PDA

View Full Version : Multithreaded OpenGL



spraff
19th January 2009, 23:08
I managed to hunt down this article from the qt3 days (http://lists.trolltech.com/qt-interest/2006-11/msg00940.html) but I remain confused and unconvinced...

I need several threads which are making native OpenGL calls on independent QGLPixelBuffer objects, looping and issuing drawing commands at unpredictable times. If one thread calls makeCurrent() and issues half its drawing commands before another calls makeCurrent() and starts its own work, won't one threads drawing commands apply to another's rendering context?

I'm at a loss as to how anyone can call the library "thread safe". Can someone please enlighten me?

P.S. is that XInitThreads() call still necessary? I'm at version 4.4.

wysota
20th January 2009, 00:36
I need several threads which are making native OpenGL calls on independent QGLPixelBuffer objects, looping and issuing drawing commands at unpredictable times. If one thread calls makeCurrent() and issues half its drawing commands before another calls makeCurrent() and starts its own work, won't one threads drawing commands apply to another's rendering context?
I don't think that's safe. You'd have to do proper synchronization using wait conditions or plain mutexes.


I'm at a loss as to how anyone can call the library "thread safe". Can someone please enlighten me?
Qt4 is not thread safe. Some parts of it are thread safe, but not all.


P.S. is that XInitThreads() call still necessary? I'm at version 4.4.
I don't see a word about multithreading in the OpenGL module docs, so I'd say it's still necessary, but I doubt it will save your day.

Lodorot
5th March 2010, 17:55
If one thread calls makeCurrent() and issues half its drawing commands before another calls makeCurrent() and starts its own work, won't one threads drawing commands apply to another's rendering context?

You will need to create a different open gl context for each thread. But then the OpenGL context is thread-specific and makeCurrent on the context will only affect the thread you are calling from. So it is okay to do parallel open gl drawing from different threads.

Yes you still have to call XInitThreads() before any drawing.

Regards

Lodorot

Concurrency and OpenGL (http://developer.apple.com/mac/library/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_threading/opengl_threading.html)
Parallel OpenGL FAQ (http://www.equalizergraphics.com/documentation/parallelOpenGLFAQ.html)