src/opengl/qglframebufferobject.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
child 7 f7bc934e204c
--- a/src/opengl/qglframebufferobject.cpp	Tue Jan 26 12:42:25 2010 +0200
+++ b/src/opengl/qglframebufferobject.cpp	Tue Feb 02 00:43:10 2010 +0200
@@ -342,39 +342,6 @@
         return fboContext;
 }
 
-void QGLFBOGLPaintDevice::ensureActiveTarget()
-{
-    if (QGLContext::currentContext() != context())
-        context()->makeCurrent();
-
-    QGLContext* ctx = const_cast<QGLContext*>(QGLContext::currentContext());
-    Q_ASSERT(ctx);
-    const GLuint fboId = fbo->d_func()->fbo();
-    if (ctx->d_func()->current_fbo != fboId) {
-        ctx->d_func()->current_fbo = fboId;
-        glBindFramebuffer(GL_FRAMEBUFFER_EXT, fboId);
-    }
-}
-
-void QGLFBOGLPaintDevice::beginPaint()
-{
-    if (QGLContext::currentContext() != context())
-        context()->makeCurrent();
-
-    // We let QFBO track the previously bound FBO rather than doing it
-    // ourselves here. This has the advantage that begin/release & bind/end
-    // work as expected.
-    wasBound = fbo->isBound();
-    if (!wasBound)
-        fbo->bind();
-}
-
-void QGLFBOGLPaintDevice::endPaint()
-{
-    if (!wasBound)
-        fbo->release();
-}
-
 bool QGLFramebufferObjectPrivate::checkFramebufferStatus() const
 {
     QGL_FUNCP_CONTEXT;
@@ -630,6 +597,12 @@
     the constructors that take a QGLFramebufferObject parameter, and set the
     QGLFramebufferObject::samples() property to a non-zero value.
 
+    When painting to a QGLFramebufferObject using QPainter, the state of
+    the current GL context will be altered by the paint engine to reflect
+    its needs.  Applications should not rely upon the GL state being reset
+    to its original conditions, particularly the current shader program,
+    GL viewport, texture units, and drawing modes.
+
     For multisample framebuffer objects a color render buffer is created,
     otherwise a texture with the specified texture target is created.
     The color render buffer or texture will have the specified internal
@@ -879,13 +852,6 @@
     framebuffer to this framebuffer object.
     Returns true upon success, false otherwise.
 
-    Since 4.6: if another QGLFramebufferObject instance was already bound
-    to the current context, then its handle() will be remembered and
-    automatically restored when release() is called.  This allows multiple
-    framebuffer rendering targets to be stacked up.  It is important that
-    release() is called on the stacked framebuffer objects in the reverse
-    order of the calls to bind().
-
     \sa release()
 */
 bool QGLFramebufferObject::bind()
@@ -896,17 +862,18 @@
     QGL_FUNC_CONTEXT;
     if (!ctx)
         return false;   // Context no longer exists.
+    const QGLContext *current = QGLContext::currentContext();
+#ifdef QT_DEBUG
+    if (!current ||
+        QGLContextPrivate::contextGroup(current) != QGLContextPrivate::contextGroup(ctx))
+    {
+        qWarning("QGLFramebufferObject::bind() called from incompatible context");
+    }
+#endif
     glBindFramebuffer(GL_FRAMEBUFFER_EXT, d->fbo());
     d->valid = d->checkFramebufferStatus();
-    const QGLContext *context = QGLContext::currentContext();
-    if (d->valid && context) {
-        Q_ASSERT(QGLContextPrivate::contextGroup(context) == QGLContextPrivate::contextGroup(ctx));
-        // Save the previous setting to automatically restore in release().
-        if (context->d_ptr->current_fbo != d->fbo()) {
-            d->previous_fbo = context->d_ptr->current_fbo;
-            context->d_ptr->current_fbo = d->fbo();
-        }
-    }
+    if (d->valid && current)
+        current->d_ptr->current_fbo = d->fbo();
     return d->valid;
 }
 
@@ -917,30 +884,29 @@
     framebuffer.
     Returns true upon success, false otherwise.
 
-    Since 4.6: if another QGLFramebufferObject instance was already bound
-    to the current context when bind() was called, then this function will
-    automatically re-bind it to the current context.
-
     \sa bind()
 */
 bool QGLFramebufferObject::release()
 {
     if (!isValid())
 	return false;
-    Q_D(QGLFramebufferObject);
     QGL_FUNC_CONTEXT;
     if (!ctx)
         return false;   // Context no longer exists.
 
-    const QGLContext *context = QGLContext::currentContext();
-    if (context) {
-        Q_ASSERT(QGLContextPrivate::contextGroup(context) == QGLContextPrivate::contextGroup(ctx));
-        // Restore the previous setting for stacked framebuffer objects.
-        if (d->previous_fbo != context->d_ptr->current_fbo) {
-            context->d_ptr->current_fbo = d->previous_fbo;
-            glBindFramebuffer(GL_FRAMEBUFFER_EXT, d->previous_fbo);
-        }
-        d->previous_fbo = 0;
+    const QGLContext *current = QGLContext::currentContext();
+
+#ifdef QT_DEBUG
+    if (!current ||
+        QGLContextPrivate::contextGroup(current) != QGLContextPrivate::contextGroup(ctx))
+    {
+        qWarning("QGLFramebufferObject::release() called from incompatible context");
+    }
+#endif
+
+    if (current) {
+        current->d_ptr->current_fbo = current->d_ptr->default_fbo;
+        glBindFramebuffer(GL_FRAMEBUFFER_EXT, current->d_ptr->default_fbo);
     }
 
     return true;