Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 10

Thread: Threads rendering to different contexts

  1. #1
    Intern Newbie
    Join Date
    Jul 2002
    Posts
    40

    Threads rendering to different contexts

    I'm sure I've seen this before but I didn't turn up anything with 'search'.

    This question is in regards to all OS's. ( Linux/Win/OSX)

    IIRC you can make OGL calls from separate threads so long as each thread is rendering to a different context. Correct?

    Is there the additional requirement that each thread must create the context that it is rendering to?

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: Threads rendering to different contexts

    The 2 cases I've tried is single context (single window), many threads. Just make cxt current with wglMakeCurrent

    2nd case : multiple windows, each in a different thread, each with it's own context.

    I don't know about Linux and Mac.
    On Windows, MSDN explains more or less but it's quite ****ty.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  3. #3
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,979

    Re: Threads rendering to different contexts

    If I am not mistaken, the threads have to create their own contexts...

  4. #4
    Senior Member OpenGL Pro
    Join Date
    May 2000
    Location
    Naarn, Austria
    Posts
    1,142

    Re: Threads rendering to different contexts

    The spec only says that a context can only be current in one thread at any time. This implies it can be current in multiple threads, as long as it's not at the same time

    I've so far only tested the case where each thread creates it's own context, but I see no reason why it should not work otherwise.

  5. #5
    Advanced Member Frequent Contributor yooyo's Avatar
    Join Date
    Apr 2003
    Location
    Belgrade, Serbia
    Posts
    883

    Re: Threads rendering to different contexts

    Before making any gl calls in some thread, context MUST be current in that thread and NOT current in any other thread. Context can be created in any thread and pass it to another thread for usage.

    Now.. I have question. I have app that create 3 GL context. I would like to share objects between contexts. Im using wglShareLists call to do that.
    Now.. im confused.. should I call wglShareLists for each pair of contexts (1-2, 1-3, 2-3) or just 1-2, 1-3?
    Im getting strange GL errors (on first gl call) when I use 3 GL contexts with dualview setup on NV8600GT+C2D+XPSP2. If I use clone, span or single view mode everything works fine. Im not sure is it driver bug or Im mis-using wglShareLists.

  6. #6
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: Threads rendering to different contexts

    For three contexts it's enough to share(1, 2) and share(1, 3). In that case the objects of context 1 are the only ones left.
    Note that the second hglrc parameter must not be current while calling sharelists and the first needs to be current, I think.
    You should not have any objects in the second hglrc (the one which loses its object namespace) or the sharelists call could fail.

  7. #7
    Junior Member Regular Contributor
    Join Date
    Aug 2004
    Location
    Palo Alto, CA
    Posts
    111

    Re: Threads rendering to different contexts

    MSDN doesn't put any restriction where the rendering contexts should be created, it just says a single rendering context cannot be current in two different threads.

    This is what I have tried:-
    1) Create RC0 & RC1 in the main thread
    2) Create Thread0 & Thread1
    3) Make RC0 current in Thread0
    4) Make RC1 current in Thread1
    5) Render to both threads simultaneously

    Note: I've had problems with wglShareLists in the above situation. If you dont share the rendering contexts you should be fine.

  8. #8
    Intern Contributor macarter's Avatar
    Join Date
    Mar 2004
    Location
    Saint Louis, Missouri, USA
    Posts
    66

    Re: Threads rendering to different contexts

    Windows OpenGL context documentation

    A thread using an OpenGL context is not required to be the creator of the context. The creating thread must release the context before it can be attached by another thread.

    We also have had problems with dualview mode failing to share textures created with automatic mip-mapping using the GeForce card/driver but working on a Quadro card/driver.

  9. #9
    Junior Member Newbie
    Join Date
    Jul 2007
    Posts
    1

    Re: Threads rendering to different contexts

    Hi,
    take a look at the following poster from SIGGRAPH 2006. Although it is about multi-core rendering it is exactly what you are looking for having a context per thread and render in parallel.

    Parallel Multi-View Rendering on Multi-Core Processor Systems.

    Poster

  10. #10
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    3,032

    Re: Threads rendering to different contexts

    I don't get what's new in that 'paper', it just seems to be stating the obvious and doesn't sound optimal. On hardware where you have multiple cores, but a single rendering pipe (1 gpu), isn't this going to cause many unnecessary context switches (thread context switches)? Isn't it more efficient in this scenario to render in series rather than parallel (ie. have a single thread responsible for rendering all views in series)?
    Knackered

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •