From e453484bca5add5973602044ff0fbc224f819a07 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 20 Jun 2014 11:58:34 +0200 Subject: Make QOpenGLWidget public QOpenGLWidget is now public. In addition Qt::WA_AlwaysStackOnTop is introduced to support the special case of semi-transparent QOpenGLWidget or QQuickWidget on top of regular widgets. hellogl_es2 becomes the qopenglwidget example. This example performs painting both via QPainter and native GL commands and has the OpenGL widget combined with other, normal widgets. The widget stack receives some changes when it comes to renderToTexture widgets like QQuickWidget and QOpenGLWidget. Calling update() will now result in a paint event, which is essential for QOpenGLWidget since we want it to behave like a regular widget. The dirty region handling is extended specially for such widgets due to performance reasons. (an OpenGL content update must not result in any backingstore painting, and is thus handled as a different kind of dirtiness) [ChangeLog] Added QOpenGLWidget. This widget serves as a replacement for QGLWidget. Task-number: QTBUG-36899 Task-number: QTBUG-40086 Change-Id: Ibf7f82fea99b39edfffd2fc088e7e0eadbca25cf Reviewed-by: Paul Olav Tvete --- src/gui/painting/qplatformbackingstore.cpp | 48 ++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 15 deletions(-) (limited to 'src/gui/painting/qplatformbackingstore.cpp') diff --git a/src/gui/painting/qplatformbackingstore.cpp b/src/gui/painting/qplatformbackingstore.cpp index 3728b0bddd..e5b06f499c 100644 --- a/src/gui/painting/qplatformbackingstore.cpp +++ b/src/gui/painting/qplatformbackingstore.cpp @@ -90,6 +90,7 @@ struct QBackingstoreTextureInfo { GLuint textureId; QRect rect; + bool stacksOnTop; }; Q_DECLARE_TYPEINFO(QBackingstoreTextureInfo, Q_MOVABLE_TYPE); @@ -127,6 +128,12 @@ GLuint QPlatformTextureList::textureId(int index) const return d->textures.at(index).textureId; } +bool QPlatformTextureList::stacksOnTop(int index) const +{ + Q_D(const QPlatformTextureList); + return d->textures.at(index).stacksOnTop; +} + QRect QPlatformTextureList::geometry(int index) const { Q_D(const QPlatformTextureList); @@ -148,12 +155,13 @@ bool QPlatformTextureList::isLocked() const return d->locked; } -void QPlatformTextureList::appendTexture(GLuint textureId, const QRect &geometry) +void QPlatformTextureList::appendTexture(GLuint textureId, const QRect &geometry, bool stacksOnTop) { Q_D(QPlatformTextureList); QBackingstoreTextureInfo bi; bi.textureId = textureId; bi.rect = geometry; + bi.stacksOnTop = stacksOnTop; d->textures.append(bi); } @@ -238,29 +246,39 @@ void QPlatformBackingStore::composeAndFlush(QWindow *window, const QRegion ®i QRect windowRect(QPoint(), window->size() * window->devicePixelRatio()); + // Textures for renderToTexture widgets. for (int i = 0; i < textures->count(); ++i) { - GLuint textureId = textures->textureId(i); - funcs->glBindTexture(GL_TEXTURE_2D, textureId); - - QRect targetRect = deviceRect(textures->geometry(i), window); - QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(targetRect, windowRect); - d_ptr->blitter->blit(textureId, target, QOpenGLTextureBlitter::OriginBottomLeft); + if (!textures->stacksOnTop(i)) { + QRect targetRect = deviceRect(textures->geometry(i), window); + QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(targetRect, windowRect); + d_ptr->blitter->blit(textures->textureId(i), target, QOpenGLTextureBlitter::OriginBottomLeft); + } } - GLuint textureId = toTexture(deviceRegion(region, window), &d_ptr->textureSize); - if (!textureId) - return; - funcs->glEnable(GL_BLEND); funcs->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(QRect(QPoint(), d_ptr->textureSize), windowRect); - d_ptr->blitter->setSwizzleRB(true); - d_ptr->blitter->blit(textureId, target, QOpenGLTextureBlitter::OriginTopLeft); - d_ptr->blitter->setSwizzleRB(false); + // Backingstore texture with the normal widgets. + GLuint textureId = toTexture(deviceRegion(region, window), &d_ptr->textureSize); + if (textureId) { + QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(QRect(QPoint(), d_ptr->textureSize), windowRect); + d_ptr->blitter->setSwizzleRB(true); + d_ptr->blitter->blit(textureId, target, QOpenGLTextureBlitter::OriginTopLeft); + d_ptr->blitter->setSwizzleRB(false); + } + + // Textures for renderToTexture widgets that have WA_AlwaysStackOnTop set. + for (int i = 0; i < textures->count(); ++i) { + if (textures->stacksOnTop(i)) { + QRect targetRect = deviceRect(textures->geometry(i), window); + QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(targetRect, windowRect); + d_ptr->blitter->blit(textures->textureId(i), target, QOpenGLTextureBlitter::OriginBottomLeft); + } + } funcs->glDisable(GL_BLEND); d_ptr->blitter->release(); + context->swapBuffers(window); } -- cgit v1.2.3