Adding a QOpenGLWidget to a QWindow greatly impacts its performance
-
Hello everyone,
I have an application that uses
QGraphicsView
andQGraphicsScene
to display some fast changing jpeg images within aQGridLayout
.
Now, I have added aQOpenGLWidget
to this layout. This alone (not even rendering something) was enough to drag down the performance of that window, i.e. operations like moving, resizing, or simple button presses are notably slower.
This performance impact persists even when theQOpenGLWidget
is deleted.This is probably related to the behavior described within the "alternatives" section of the
QOpenGLWidget
documentation, since I can use the described workaround to speed my application up again.Now, I am quite curious, what exactly causes these performance implications, especially due to it persisting after the widgets's deletion.
-
Hi and welcome.
Normally widgets paint onto a pixmap and that pixmap is then painted to the window using double buffering. It happens on the CPU.
Once you insert QOpenGLWidget the entire window is rendered using OpenGL and OpenGL scene is composited with the widgets pixmap. This means that every time you draw something in the widgets the pixmap needs to be uploaded to the GPU as a texture. This takes time and is what causes the slowdown. I suspect it stays slow after you delete the QOpenGLWidget because it doesn't get back to normal rendering, but I can only guess. I haven't looked at the internal code. When you use a separate OpenGL window in a container no CPU-GPU composition is done and that's why it should run faster. You will run into trouble when you try to overlay widgets on top of that OpenGL window though, because those are now separate surfaces. So it's a tradeoff - functionality or speed. -
Thanks, so that is what "OpenGL-based composing" does under the hood!
Is there any way to synchronize/batch my
QGraphicsView
updates, so that there is less of a performance impact?
Or would it be preferable to switch theQGraphicsView
-based widgets over to render their scene via OpenGL?