Multithreading OpenGL in Qt 5

It always was a good prSpeedometer - Going Too Fastogramming practice that UI thread separated from working thread. Users doesn’t like when UI just freezes. These days, multithreading programming is not a rocket science and, fortunately, Qt have all that you need to create multuthreded applications. But what about OpenGL rendering in separate thread? What if you want OpenGL to do some off screen job for you while you interacting with user?

Here is some tips how to do this in Qt 5:

The main rule here is to create QOpenGLContext in the run() method of the OpenGL thread, otherwise any QOpenGL functions will not work. Unfortunately, playing with moveToThread() doesnt works (yet?)threadrip

If you planning to create several OpenGL threads within your application, don’t forget to call doneCurrent() method of QOpenGLContext. Then it makes sense to destroy context and recreate it in different thread. At least, this works pretty solid for me (Qt 5.1 for Linux)

Leave a Reply

Your email address will not be published. Required fields are marked *