PDA

View Full Version : multithreading and ogl



markun
04-06-2003, 06:15 AM
Is there a way to call ogl functions in different threads in the program.
As much as i know ogl commands must be called from same thread. Is there a way to seperate this calls into different threads.
thanks

MichaelK
04-06-2003, 10:16 AM
Yes. Under Windows You can post messages to the thread owning the RC. The thread only processes messages.
This method can improve the rendering performance. In the main thread You send drawing command to the rendering thread and at the end of command stream You put, say WM_SWAP_BUFFERS. After this You do other stuff, like physics, from time to time checking if swapping have been done. Checking can be implemented using Events.

evanGLizr
04-06-2003, 11:07 AM
Originally posted by markun:
Is there a way to call ogl functions in different threads in the program.
As much as i know ogl commands must be called from same thread. Is there a way to seperate this calls into different threads.
thanks

That's an OS specific issue. In win32 it's resolved by using wgl functions. From the wglMakeCurrent (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/ntopnglr_2u0k.asp) documentation:



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.