Qt 4.8.0 Released with Multithreaded OpenGL support

Qt 4.8.0, Multithreaded OpenGL support

Qt, the cross-platform (Windows, Linux, Mac OS X) application and UI (user interface) framework, is available in version 4.8.0. You can download Qt 4.8.0 from this page.

Among the new features, there is the threaded OpenGL support. Here are some interesting details about how OpenGL is used in Qt 4.8.0:

Depending on your driver and GPU, the call to swapBuffers() can sometimes be an expensive function call (especially on embedded processors). In many cases, this is the function that tells the GPU to take all of your render commands and execute them to render the current frame. If this operation is synchronous then your main thread is blocked while the GPU is doing its thing. That’s unfortunate because your current thread has much better things to do than wait for the GPU. For example, it could return to the event loop and process some user input, network traffic or advance the next scene of an animation. The solution to this in 4.8 is to have a separate thread whose sole purpose in life is to wait for the GPU by calling swapBuffers. In practice you would render everything as normal in your main thread, but instead of calling swapBuffers(), you would call doneCurrent() on the current GL context. You would then notify the swapping thread that you have finished rendering and it would call makeCurrent() to make the context active and then call swapBuffers(). The swapping thread should then call doneCurrent() and notify the main thread that it has finished.

Uploading many (or large) textures is typically an expensive operation because of the amount of data being pushed to the GPU. Again, this is one of those operations that can unnecessarily block your main thread. In 4.8 you can solve this problem by creating a pair of shared QGLWidgets. One of the widgets is made current in a separate thread, but is never made visible on screen. The main thread informs the uploading thread which images to upload and the uploading thread simply calls bindTexture() on each of these images and then notifies the main thread when each one has finished so it can be drawn to screen.


3 thoughts on “Qt 4.8.0 Released with Multithreaded OpenGL support”

  1. Leith Bade

    It would be nice if they introduced the asynchronous job queue API from OpenCL into OpenGL.

    Would save the need for manual threading.

  2. DrBalthar

    Oh you mean something that Direct3D 11 has introduced more than two years ago?

Comments are closed.