diff options
author | Samuel Rødal <sroedal@trolltech.com> | 2009-05-25 12:56:27 (GMT) |
---|---|---|
committer | Samuel Rødal <sroedal@trolltech.com> | 2009-05-27 10:43:11 (GMT) |
commit | 15c8f565973592c9929cdd6fc83d61641aa63afa (patch) | |
tree | b0a2e1754164b715572c6d088651d9d3859e26f7 /src/opengl | |
parent | cfdfdf079c4a2095c588dd8af8403c74d2cfa37a (diff) | |
download | Qt-15c8f565973592c9929cdd6fc83d61641aa63afa.zip Qt-15c8f565973592c9929cdd6fc83d61641aa63afa.tar.gz Qt-15c8f565973592c9929cdd6fc83d61641aa63afa.tar.bz2 |
Fixed bugs in GL2 paint engine when several engines are active.
Make sure makeCurrent() on a window surface unbinds any active FBO, and
simplify ensureActive() code in GL2 paint engine a bit. We don't need
the last_engine pointer as ensureActive() will take care of ensuring the
correct engine is active anway.
Diffstat (limited to 'src/opengl')
-rw-r--r-- | src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 46 | ||||
-rw-r--r-- | src/opengl/qgl.cpp | 15 | ||||
-rw-r--r-- | src/opengl/qgl_p.h | 1 | ||||
-rw-r--r-- | src/opengl/qglframebufferobject.cpp | 12 |
4 files changed, 41 insertions, 33 deletions
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index f174306..a7c7426 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -175,8 +175,6 @@ public: void updateDepthClip(); void systemStateChanged(); uint use_system_clip : 1; - - QPaintEngine *last_engine; }; @@ -830,10 +828,11 @@ void QGL2PaintEngineEx::stroke(const QVectorPath &path, const QPen &pen) { Q_D(QGL2PaintEngineEx); - ensureActive(); if (pen.style() == Qt::NoPen) return; + ensureActive(); + if ( (pen.isCosmetic() && (pen.style() == Qt::SolidLine)) && (pen.widthF() < 2.5f) ) { // We only handle solid, cosmetic pens with a width of 1 pixel @@ -1051,10 +1050,19 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) Q_D(QGL2PaintEngineEx); // qDebug("QGL2PaintEngineEx::begin()"); - d->drawable.setDevice(pdev); - d->drawable.makeCurrent(); d->ctx = d->drawable.context(); + + if (d->ctx->d_ptr->active_engine) { + QGL2PaintEngineEx *engine = static_cast<QGL2PaintEngineEx *>(d->ctx->d_ptr->active_engine); + QGL2PaintEngineExPrivate *p = static_cast<QGL2PaintEngineExPrivate *>(engine->d_ptr); + p->transferMode(BrushDrawingMode); + p->drawable.doneCurrent(); + } + + d->ctx->d_ptr->active_engine = this; + + d->drawable.makeCurrent(); QSize sz = d->drawable.size(); d->width = sz.width(); d->height = sz.height(); @@ -1064,14 +1072,6 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) qt_resolve_version_2_0_functions(d->ctx); #endif - d->last_engine = d->ctx->d_ptr->active_engine; - d->ctx->d_ptr->active_engine = this; - - if (d->last_engine) { - QGL2PaintEngineEx *engine = static_cast<QGL2PaintEngineEx *>(d->last_engine); - static_cast<QGL2PaintEngineExPrivate *>(engine->d_ptr)->transferMode(BrushDrawingMode); - } - if (!d->shaderManager) d->shaderManager = new QGLEngineShaderManager(d->ctx); @@ -1115,8 +1115,8 @@ bool QGL2PaintEngineEx::end() Q_D(QGL2PaintEngineEx); QGLContext *ctx = d->ctx; if (ctx->d_ptr->active_engine != this) { - QGL2PaintEngineEx *engine = static_cast<QGL2PaintEngineEx *>(d->last_engine); - if (engine) { + QGL2PaintEngineEx *engine = static_cast<QGL2PaintEngineEx *>(ctx->d_ptr->active_engine); + if (engine && engine->isActive()) { QGL2PaintEngineExPrivate *p = static_cast<QGL2PaintEngineExPrivate *>(engine->d_ptr); p->transferMode(BrushDrawingMode); p->drawable.doneCurrent(); @@ -1128,19 +1128,7 @@ bool QGL2PaintEngineEx::end() d->transferMode(BrushDrawingMode); d->drawable.swapBuffers(); d->drawable.doneCurrent(); - d->ctx->d_ptr->active_engine = d->last_engine; - - if (d->last_engine) { - QGL2PaintEngineEx *engine = static_cast<QGL2PaintEngineEx *>(d->last_engine); - QGL2PaintEngineExPrivate *p = static_cast<QGL2PaintEngineExPrivate *>(engine->d_ptr); - - glDisable(GL_DEPTH_TEST); - glDisable(GL_SCISSOR_TEST); - - glViewport(0, 0, p->width, p->height); - engine->setState(engine->state()); - p->updateDepthClip(); - } + d->ctx->d_ptr->active_engine = 0; return false; } @@ -1152,7 +1140,7 @@ void QGL2PaintEngineEx::ensureActive() if (isActive() && ctx->d_ptr->active_engine != this) { QGL2PaintEngineEx *engine = static_cast<QGL2PaintEngineEx *>(ctx->d_ptr->active_engine); - if (engine) { + if (engine && engine->isActive()) { QGL2PaintEngineExPrivate *p = static_cast<QGL2PaintEngineExPrivate *>(engine->d_ptr); p->transferMode(BrushDrawingMode); p->drawable.doneCurrent(); diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 0a2a196..62a592a 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -4391,6 +4391,15 @@ void QGLDrawable::swapBuffers() void QGLDrawable::makeCurrent() { + previous_fbo = 0; + if (!pixmapData && !fbo) { + QGLContext *ctx = context(); + previous_fbo = ctx->d_ptr->current_fbo; + ctx->d_ptr->current_fbo = 0; + if (previous_fbo) + glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); + } + if (widget) widget->makeCurrent(); #if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) @@ -4428,6 +4437,12 @@ void QGLDrawable::doneCurrent() } #endif + if (previous_fbo) { + QGLContext *ctx = context(); + ctx->d_ptr->current_fbo = previous_fbo; + glBindFramebuffer(GL_FRAMEBUFFER_EXT, previous_fbo); + } + if (fbo && !wasBound) fbo->release(); } diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index b421eee..9657416 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -333,6 +333,7 @@ private: #if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) QGLPixmapData *pixmapData; #endif + int previous_fbo; }; // GL extension definitions diff --git a/src/opengl/qglframebufferobject.cpp b/src/opengl/qglframebufferobject.cpp index 338ce1f..3e7ca0a 100644 --- a/src/opengl/qglframebufferobject.cpp +++ b/src/opengl/qglframebufferobject.cpp @@ -804,8 +804,10 @@ bool QGLFramebufferObject::bind() const QGLContext *context = QGLContext::currentContext(); if (d->valid && context) { // Save the previous setting to automatically restore in release(). - d->previous_fbo = context->d_ptr->current_fbo; - context->d_ptr->current_fbo = d->fbo; + if (context->d_ptr->current_fbo != d->fbo) { + d->previous_fbo = context->d_ptr->current_fbo; + context->d_ptr->current_fbo = d->fbo; + } } return d->valid; } @@ -834,8 +836,10 @@ bool QGLFramebufferObject::release() const QGLContext *context = QGLContext::currentContext(); if (context) { // Restore the previous setting for stacked framebuffer objects. - context->d_ptr->current_fbo = d->previous_fbo; - glBindFramebuffer(GL_FRAMEBUFFER_EXT, d->previous_fbo); + 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; } |