View Full Version : Multithreading, Single Context (Win32)
According to the documentation for wglMakeCurrent, 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?
06-04-2004, 03:50 PM
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,
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.
06-04-2004, 06:24 PM
I've posted a similar question (http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=9;t=000185) 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".
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.