The application I'm working on has several animating objects (rotating in a circle) and I'm looking to lower the CPU consumed. I'm using the graphicsview framework and most objects on the screen, including the animating objects are derived from QGraphicsWidget.
I do set the viewport to QGLWidget so I get some OpenGL acceleration but that isn't lowering the CPU enough.
I see setting the viewport to QGLWidget changes the paint engine to QOpenGLPaintEngine and translates a lot of the painter calls to OpenGL calls. Looking through the source and stepping through in debug, I come across this function of particular interest:
{
...
if (pdev->devType() == QInternal::Widget)
widget = static_cast<QGLWidget *>(pdev);
else if (pdev->devType() == QInternal::Pbuffer)
buffer = static_cast<QGLPixelBuffer *>(pdev);
else if (pdev->devType() == QInternal::FramebufferObject)
fbo = static_cast<QGLFramebufferObject *>(pdev);
else if (pdev->devType() == QInternal::UnknownDevice)
...
}
void QGLDrawable::setDevice(QPaintDevice *pdev)
{
...
if (pdev->devType() == QInternal::Widget)
widget = static_cast<QGLWidget *>(pdev);
else if (pdev->devType() == QInternal::Pbuffer)
buffer = static_cast<QGLPixelBuffer *>(pdev);
else if (pdev->devType() == QInternal::FramebufferObject)
fbo = static_cast<QGLFramebufferObject *>(pdev);
else if (pdev->devType() == QInternal::UnknownDevice)
...
}
To copy to clipboard, switch view to plain text mode
It looks like this paint engine has the ability to render into a framebuffer object and this would probably give me a nice gain in performance (platform does support framebuffer objects).
The only problem is I don't see how to change an object's PaintDevice. For all my objects the PaintDevice is of type Widget, which is expected.
Does anyone know how I can change the PaintDevice to FramebufferObject?
I've thought of changing this file to always use frame buffers but it seems there should be a way to set this.
Bookmarks