DyingSoul
DyingSoul

Reputation: 231

QGLWidget's paintGL() method called from which Qt thread?

suppose I use the QGLWidget's paintGL() method to draw into the widget using OpenGL. After the Qt called the paintGL() method, it automatically triggers a buffer swap. In OpenGL, this buffer swap usually blocks the calling thread until the frame rendering to the background buffer is completed, right? I wonder which Qt thread calls the paintGL as well as the buffer swap. Is it the main Qt UI thread? If it is, wouldn't that mean that the block during the buffer swap also blocks the whole UI? I could not find any information about this process in general..

Thanks

Upvotes: 2

Views: 3330

Answers (2)

Luca Carlon
Luca Carlon

Reputation: 9996

I don't use the QGLWidget very often, but consider that yes, if swapBuffers() is synchronous the Qt GUI thread is stuck. This means that during that operation you'll be unable to process events.

Anyway, if you're experiencing difficulties while doing this, consider reading this article which manage to allow multithreaded OpenGL to overcome this difficulty.

Even better, this article explains well the situation and introduces the new multithreading OpenGL capabilities in Qt 4.8, which is now in release candidate.

Upvotes: 2

Nicol Bolas
Nicol Bolas

Reputation: 474436

In OpenGL, this buffer swap usually blocks the calling thread until the frame rendering to the background buffer is completed, right?

It depends on how it is implemented. Which means that it varies from hardware to hardware and driver to driver.

If it is, wouldn't that mean that the block during the buffer swap also blocks the whole UI?

Even if it does block, it will only do so for 1/60th of a second. Maybe 1/30th if your game is slowing down. If you're really slow, 1/15th. The at most one keypress or mouse action that the user gives will still be in the message queue.

The issue with blocking isn't about the UI. It will be responsive enough for the user to not notice. But if you have strict timings (such as you might for a game), I would suggest avoiding paintGL at all. You should be rendering when you want to, not when Qt tells you to.

Upvotes: 0

Related Questions