diff options
Diffstat (limited to 'src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp')
-rw-r--r-- | src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 89 |
1 files changed, 23 insertions, 66 deletions
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 0ad454f..c87941b 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtOpenGL module of the Qt Toolkit. @@ -20,10 +21,9 @@ ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this -** package. +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** If you have questions regarding the use of this file, please contact ** Nokia at qt-info@nokia.com. @@ -711,7 +711,7 @@ void QGL2PaintEngineEx::beginNativePainting() { mtx.dx(), mtx.dy(), 0, mtx.m33() } }; - const QSize sz = d->drawable.size(); + const QSize sz = d->device->size(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -1309,21 +1309,20 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) Q_D(QGL2PaintEngineEx); // qDebug("QGL2PaintEngineEx::begin()"); - d->drawable.setDevice(pdev); - 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.data()); - p->transferMode(BrushDrawingMode); - p->drawable.doneCurrent(); - } + if (pdev->devType() == QInternal::OpenGL) + d->device = static_cast<QGLPaintDevice*>(pdev); + else + d->device = QGLPaintDevice::getDevice(pdev); + + if (!d->device) + return false; + + d->ctx = d->device->context(); d->ctx->d_ptr->active_engine = this; d->last_created_state = 0; - d->drawable.makeCurrent(); - QSize sz = d->drawable.size(); + QSize sz = d->device->size(); d->width = sz.width(); d->height = sz.height(); d->mode = BrushDrawingMode; @@ -1334,8 +1333,6 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) d->shaderManager = new QGLEngineShaderManager(d->ctx); - glViewport(0, 0, d->width, d->height); - d->brushTextureDirty = true; d->brushUniformsDirty = true; d->matrixDirty = true; @@ -1344,10 +1341,12 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) d->simpleShaderDepthUniformDirty = true; d->depthUniformDirty = true; d->opacityUniformDirty = true; - d->needsSync = false; - + d->needsSync = true; d->use_system_clip = !systemClip().isEmpty(); + + d->device->beginPaint(); + if (!d->inRenderText) { glDisable(GL_DEPTH_TEST); glDisable(GL_SCISSOR_TEST); @@ -1359,30 +1358,6 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) glDisable(GL_MULTISAMPLE); #endif - QGLPixmapData *source = d->drawable.copyOnBegin(); - if (d->drawable.context()->d_func()->clear_on_painter_begin && d->drawable.autoFillBackground()) { - if (d->drawable.hasTransparentBackground()) - glClearColor(0.0, 0.0, 0.0, 0.0); - else { - const QColor &c = d->drawable.backgroundColor(); - float alpha = c.alphaF(); - glClearColor(c.redF() * alpha, c.greenF() * alpha, c.blueF() * alpha, alpha); - } - glClear(GL_COLOR_BUFFER_BIT); - } else if (source) { - QGLContext *ctx = d->ctx; - - d->transferMode(ImageDrawingMode); - - glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT); - source->bind(false); - - QRect rect(0, 0, source->width(), source->height()); - d->updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, false); - d->drawTexture(QRectF(rect), QRectF(rect), rect.size(), true); - } - - d->systemStateChanged(); return true; } @@ -1390,19 +1365,11 @@ bool QGL2PaintEngineEx::end() { Q_D(QGL2PaintEngineEx); QGLContext *ctx = d->ctx; - if (ctx->d_ptr->active_engine != this) { - QGL2PaintEngineEx *engine = static_cast<QGL2PaintEngineEx *>(ctx->d_ptr->active_engine); - if (engine && engine->isActive()) { - QGL2PaintEngineExPrivate *p = static_cast<QGL2PaintEngineExPrivate *>(engine->d_ptr.data()); - p->transferMode(BrushDrawingMode); - p->drawable.doneCurrent(); - } - d->drawable.makeCurrent(); - } glUseProgram(0); d->transferMode(BrushDrawingMode); - d->drawable.swapBuffers(); + d->device->endPaint(); + #if defined(Q_WS_X11) // On some (probably all) drivers, deleting an X pixmap which has been bound to a texture // before calling glFinish/swapBuffers renders garbage. Presumably this is because X deletes @@ -1411,7 +1378,6 @@ bool QGL2PaintEngineEx::end() // them here, after swapBuffers, where they can be safely deleted. ctx->d_func()->boundPixmaps.clear(); #endif - d->drawable.doneCurrent(); d->ctx->d_ptr->active_engine = 0; d->resetGLState(); @@ -1428,21 +1394,12 @@ void QGL2PaintEngineEx::ensureActive() QGLContext *ctx = d->ctx; if (isActive() && ctx->d_ptr->active_engine != this) { - QGL2PaintEngineEx *engine = static_cast<QGL2PaintEngineEx *>(ctx->d_ptr->active_engine); - if (engine && engine->isActive()) { - QGL2PaintEngineExPrivate *p = static_cast<QGL2PaintEngineExPrivate *>(engine->d_ptr.data()); - p->transferMode(BrushDrawingMode); - p->drawable.doneCurrent(); - } - d->drawable.context()->makeCurrent(); - d->drawable.makeCurrent(); - ctx->d_ptr->active_engine = this; d->needsSync = true; - } else { - d->drawable.context()->makeCurrent(); } + d->device->ensureActiveTarget(); + if (d->needsSync) { glViewport(0, 0, d->width, d->height); glDepthMask(false); |