[Interest] Using QOpenGLFramebufferObject with QGraphicsView

Laszlo Agocs laszlo.agocs at qt.io
Mon Mar 6 11:27:40 CET 2017


Please report a bug, at first glance it looks like an oversight.

Thanks,
Laszlo


Get Outlook for iOS<https://aka.ms/o0ukef>

________________________________
From: Interest <interest-bounces+laszlo.agocs=qt.io at qt-project.org> on behalf of ole-qt-2017 at mail.plastictree.net <ole-qt-2017 at mail.plastictree.net>
Sent: Monday, March 6, 2017 11:18:24 AM
To: interest at qt-project.org
Subject: [Interest] Using QOpenGLFramebufferObject with QGraphicsView

The QOpenGLWidget has a GL framebuffer in which it expects
everything to be rendered. This framebuffer is not the system's
default framebuffer.

QOpenGLContext::defaultFramebufferObject() returns the default
framebuffer. This function is used in
QOpenGLFramebufferObject::release() to rebind the default
framebuffer after one is done with using one's own.

Now, for this to work with QOpenGLWidget it is necessary for
defaultFramebufferObject() to return not the system's default,
but the framebuffer used by the widget.

Otherwise calling QOpenGLFramebufferObject::bind() and
subsequently release() will leave you rendering into the system's
default framebuffer 0 while the widget expects you to render to,
say, framebuffer 3.

Looking at the sources shows that QOpenGLWidget, before calling a
virtual paintGL() method, sets a flag on QOpenGLContext to make
its defaultFramebufferObject() method return the correct
framebuffer. QOpenGLFramebufferObject::bind() and release()
inside the paintGL() method do therefore work as expected.

So far so good. This is also all documented like this.

We are, however, using QOpenGLWidget as viewport for
QGraphicsView. When using QOpenGLFramebufferObject inside
QGraphicsEffect::draw() the aformentioned intialization step that
modifies QOpenGLContext::defaultFramebufferObject()'s behaviour
seems to be missing. A call to
QOpenGLFramebufferObject::release() leaves you with the wrong
framebuffer bound. We have to manually save the framebuffer id
before QOpenGLFramebufferObject::bind() and restore it later.

Now my question is: Is QOpenGLFramebufferObject not supposed to
be used with QGraphicsView or is there an oversight in
QGraphicsView, failing to set the correct default framebuffer
before calling any user-overriden draw() methods? (Or, more
plainly: Should I report a bug for this?)

Best regards
Ole
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170306/20368c57/attachment.html>


More information about the Interest mailing list