From a21b661384c31e6c9154a99690b2d134a12b9187 Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Thu, 10 Sep 2009 15:56:11 +0200 Subject: Re-order begin() so everything needing a current context has one It should be up to QGLPaintDevice::beginPaint() to make the correct context current, so everything needing a current context needs to be moved after that call. This patch also modifies QGLPixmapData to use QGLContext::drawTexture rather than the GL2 PE's drawTexture, which shouldn't be called inside beginPaint as the paint engine hasn't been fully initialised yet. Reviewed-by: Eskil --- .../gl2paintengineex/qpaintengineex_opengl2.cpp | 24 +++++++++++----------- src/opengl/qpixmapdata_gl.cpp | 8 ++------ 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 2eacef0..4427ee9 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -1318,23 +1318,13 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) return false; d->ctx = d->device->context(); - d->ctx->d_ptr->active_engine = this; - d->last_created_state = 0; - QSize sz = d->device->size(); + const QSize sz = d->device->size(); d->width = sz.width(); d->height = sz.height(); + d->last_created_state = 0; d->mode = BrushDrawingMode; - -#if !defined(QT_OPENGL_ES_2) - d->ctx->makeCurrent(); - bool success = qt_resolve_version_2_0_functions(d->ctx); - Q_ASSERT(success); -#endif - - d->shaderManager = new QGLEngineShaderManager(d->ctx); - d->brushTextureDirty = true; d->brushUniformsDirty = true; d->matrixDirty = true; @@ -1346,8 +1336,18 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) d->needsSync = true; d->use_system_clip = !systemClip().isEmpty(); + // Calling begin paint should make the correct context current. So, any + // code which calls into GL or otherwise needs a current context *must* + // go after beginPaint: d->device->beginPaint(); +#if !defined(QT_OPENGL_ES_2) + bool success = qt_resolve_version_2_0_functions(d->ctx); + Q_ASSERT(success); +#endif + + d->shaderManager = new QGLEngineShaderManager(d->ctx); + if (!d->inRenderText) { glDisable(GL_DEPTH_TEST); glDisable(GL_SCISSOR_TEST); diff --git a/src/opengl/qpixmapdata_gl.cpp b/src/opengl/qpixmapdata_gl.cpp index fa1b815..0bc46e1 100644 --- a/src/opengl/qpixmapdata_gl.cpp +++ b/src/opengl/qpixmapdata_gl.cpp @@ -157,12 +157,8 @@ void QGLPixmapGLPaintDevice::beginPaint() // uploaded from an image or rendered into before), we need to // copy it from the texture to the render FBO. - // Pass false to tell bind to _not_ copy the FBO into the texture! - GLuint texId = data->bind(false); - - QGL2PaintEngineEx* pe = static_cast(data->paintEngine()); - QRect rect(0, 0, data->width(), data->height()); - pe->drawTexture(QRectF(rect), texId, rect.size(), QRectF(rect)); + // Pass false to bind so it doesn't copy the FBO into the texture! + context()->drawTexture(QPointF(0.0, 0.0), data->bind(false)); } } -- cgit v0.12