From e5954bba5bb1f88a847570d4790d0cef64f92209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Mon, 12 Oct 2009 15:48:50 +0200 Subject: Fixed bug when using QGLWidgets in -graphicssystem opengl We need to make sure that the FBO is bound in a valid context. Reviewed-by: Tom --- src/opengl/qglframebufferobject.cpp | 17 +++++++++++++++++ src/opengl/qglframebufferobject_p.h | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/opengl/qglframebufferobject.cpp b/src/opengl/qglframebufferobject.cpp index 5585208..9674cfb 100644 --- a/src/opengl/qglframebufferobject.cpp +++ b/src/opengl/qglframebufferobject.cpp @@ -331,8 +331,22 @@ void QGLFBOGLPaintDevice::setFBO(QGLFramebufferObject* f, } } +QGLContext *QGLFBOGLPaintDevice::context() const +{ + QGLContext *fboContext = const_cast(fbo->d_ptr->fbo_guard.context()); + QGLContext *currentContext = const_cast(QGLContext::currentContext()); + + if (QGLContextPrivate::contextGroup(fboContext) == QGLContextPrivate::contextGroup(currentContext)) + return currentContext; + else + return fboContext; +} + void QGLFBOGLPaintDevice::ensureActiveTarget() { + if (QGLContext::currentContext() != context()) + context()->makeCurrent(); + QGLContext* ctx = const_cast(QGLContext::currentContext()); Q_ASSERT(ctx); const GLuint fboId = fbo->d_func()->fbo(); @@ -344,6 +358,9 @@ void QGLFBOGLPaintDevice::ensureActiveTarget() 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. diff --git a/src/opengl/qglframebufferobject_p.h b/src/opengl/qglframebufferobject_p.h index 055a752..43d4a41 100644 --- a/src/opengl/qglframebufferobject_p.h +++ b/src/opengl/qglframebufferobject_p.h @@ -109,7 +109,7 @@ class QGLFBOGLPaintDevice : public QGLPaintDevice public: virtual QPaintEngine* paintEngine() const {return fbo->paintEngine();} virtual QSize size() const {return fbo->size();} - virtual QGLContext* context() const {return const_cast(QGLContext::currentContext());} + virtual QGLContext* context() const; virtual QGLFormat format() const {return fboFormat;} virtual void ensureActiveTarget(); virtual void beginPaint(); -- cgit v0.12