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 4 of 4

Thread: Multithreading, Single Context (Win32)

  1. #1
    Guest

    Multithreading, Single Context (Win32)

    According to the documentation for [bold]wglMakeCurrent[/bold], only one thread may hold a given context as active at any time.

    Does this mean that if one thread calls wglMakeCurrent() with a given context, it invalidates that context for another thread that may already hold it, or just that two threads should not expect to concurrently hold the context?

    That being said, will it be safe if I use two threads, one context, but enforce mutual exclusion, ensuring that there is no opportunity for both threads to make OpenGL calls at the same time at any given time?

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2004
    Posts
    990

    Re: Multithreading, Single Context (Win32)

    This is what I got from msdn:

    Before switching to the new rendering context, OpenGL flushes any previous rendering context that was current to the calling thread.

    A thread can have one current rendering context. A process can have multiple rendering contexts by means of multithreading. A thread must set a current rendering context before calling any OpenGL functions. Otherwise, all OpenGL calls are ignored.

    A rendering context can be current to only one thread at a time. You cannot make a rendering context current to multiple threads.

    An application can perform multithread drawing by making different rendering contexts current to different threads, supplying each thread with its own rendering context and device context.

    If an error occurs, the wglMakeCurrent function makes the thread's current rendering context not current before returning.
    Greetz,
    Nico

  3. #3
    Guest

    Re: Multithreading, Single Context (Win32)

    I know, that's exactly what I read, but I need to have one rendering context, because one thread will be responsible for doing recurring tasks and updates while the other is the main program thread will be doing the main rendering.

    It doesn't make clear though whether it is impossible to get two threads to use one rendering context, or whether you just cannot allow two to use one at the same time.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Feb 2002
    Location
    Bonn, Germany
    Posts
    1,633

    Re: Multithreading, Single Context (Win32)

    I've posted a similar question a month ago. Even though I would have wished for more responses, just to be sure, the general consensus seems to be that it's not possible.

    Maybe this is what MSDN means with "You cannot make a rendering context current to multiple threads". I'd today interpret that sentence as "wglMakeCurrent will fail".

Posting Permissions

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