diff --git a/src/gui/opengl/qopenglframebufferobject.cpp b/src/gui/opengl/qopenglframebufferobject.cpp index 56e04c09d8..b1b580f85b 100644 --- a/src/gui/opengl/qopenglframebufferobject.cpp +++ b/src/gui/opengl/qopenglframebufferobject.cpp @@ -1490,6 +1490,7 @@ bool QOpenGLFramebufferObject::bindDefault() if (ctx) { ctx->functions()->glBindFramebuffer(GL_FRAMEBUFFER, ctx->defaultFramebufferObject()); QOpenGLContextPrivate::get(ctx)->qgl_current_fbo_invalid = true; + QOpenGLContextPrivate::get(ctx)->qgl_current_fbo = Q_NULLPTR; } #ifdef QT_DEBUG else diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index e2ad502a52..00b5da92a8 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -114,6 +114,7 @@ private slots: void vaoCreate(); void bufferCreate(); void bufferMapRange(); + void defaultQGLCurrentBuffer(); }; struct SharedResourceTracker @@ -1525,6 +1526,33 @@ void tst_QOpenGL::bufferMapRange() ctx->doneCurrent(); } +void tst_QOpenGL::defaultQGLCurrentBuffer() +{ + QScopedPointer surface(createSurface(QSurface::Window)); + QScopedPointer ctx(new QOpenGLContext); + ctx->create(); + ctx->makeCurrent(surface.data()); + + // Bind default FBO on the current context, and record what's the current QGL FBO. It should + // be Q_NULLPTR because the default platform OpenGL FBO is not backed by a + // QOpenGLFramebufferObject. + QOpenGLFramebufferObject::bindDefault(); + QOpenGLFramebufferObject *defaultQFBO = QOpenGLContextPrivate::get(ctx.data())->qgl_current_fbo; + + // Create new FBO, bind it, and see that the QGL FBO points to the newly created FBO. + QScopedPointer obj(new QOpenGLFramebufferObject(128, 128)); + obj->bind(); + QOpenGLFramebufferObject *customQFBO = QOpenGLContextPrivate::get(ctx.data())->qgl_current_fbo; + QVERIFY(defaultQFBO != customQFBO); + + // Bind the default FBO, and check that the QGL FBO points to the original FBO object. + QOpenGLFramebufferObject::bindDefault(); + QOpenGLFramebufferObject *finalQFBO = QOpenGLContextPrivate::get(ctx.data())->qgl_current_fbo; + QCOMPARE(defaultQFBO, finalQFBO); + + ctx->doneCurrent(); +} + void tst_QOpenGL::nullTextureInitializtion() { QScopedPointer surface(createSurface(QSurface::Window));