diff options
author | Jesse Barnes <jbarnes@virtuousgeek.org> | 2010-10-28 18:13:13 (GMT) |
---|---|---|
committer | Jørgen Lind <jorgen.lind@nokia.com> | 2011-01-25 18:01:50 (GMT) |
commit | adbcd0f749e7ce8d7a95ed919e0a37fa5b219f06 (patch) | |
tree | a8d6180436778dab49afb9206fda82592f7437af | |
parent | 4a3d4dcdcf2782530c76a6aff4775ec5f8ebd157 (diff) | |
download | Qt-adbcd0f749e7ce8d7a95ed919e0a37fa5b219f06.zip Qt-adbcd0f749e7ce8d7a95ed919e0a37fa5b219f06.tar.gz Qt-adbcd0f749e7ce8d7a95ed919e0a37fa5b219f06.tar.bz2 |
Wayland: clean up swapBuffers code
Pull the swap fbo and rbo into the context and make sure to destroy them
when the context goes away. Add unfortunate lazy allocation of the fbo
and rbo because we need them to be part of the right context.
-rw-r--r-- | src/plugins/platforms/wayland/qwaylandintegration.cpp | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/plugins/platforms/wayland/qwaylandintegration.cpp b/src/plugins/platforms/wayland/qwaylandintegration.cpp index a3237fb..879fd73 100644 --- a/src/plugins/platforms/wayland/qwaylandintegration.cpp +++ b/src/plugins/platforms/wayland/qwaylandintegration.cpp @@ -513,6 +513,7 @@ private: QPlatformWindowFormat mFormat; QWaylandDisplay *mDisplay; QWaylandWindow *mWindow; + GLuint parentFbo, parentRbo; }; QWaylandGLContext::QWaylandGLContext(QWaylandDisplay *wd, QWaylandWindow *window, const QPlatformWindowFormat &format) @@ -520,11 +521,15 @@ QWaylandGLContext::QWaylandGLContext(QWaylandDisplay *wd, QWaylandWindow *window , mFormat(format) , mDisplay(wd) , mWindow(window) + , parentFbo(0) + , parentRbo(0) { } QWaylandGLContext::~QWaylandGLContext() { + glDeleteRenderbuffers(1, &parentRbo); + glDeleteFramebuffers(1, &parentFbo); } void QWaylandGLContext::makeCurrent() @@ -594,7 +599,10 @@ void QWaylandGLContext::swapBuffers() QWaylandWindow *mParentWindow = mWindow->getParentWindow(); QWaylandDrmBuffer *mBuffer, *mParentBuffer; QRect geometry = mWindow->geometry(), parentGeometry; - GLuint parentFbo, parentRbo; + QGLShaderProgram *blitProgram; + QRectF r; + qreal w; + qreal h; if (!mParentWindow) { qDebug("swap without parent widget?\n"); @@ -610,31 +618,33 @@ void QWaylandGLContext::swapBuffers() mBuffer = (QWaylandDrmBuffer *)mWindow->getBuffer(); mParentBuffer = (QWaylandDrmBuffer *)mParentWindow->getBuffer(); - qDebug("copying from texture image %d, texture %d to image %d, texture %d\n", - mBuffer->mImage, mBuffer->mTexture, mParentBuffer->mImage, mParentBuffer->mTexture); - glDisable(GL_DEPTH_TEST); - glGenFramebuffers(1, &parentFbo); - glGenRenderbuffers(1, &parentRbo); + w = geometry.width() ? geometry.width() : 1.0f; + h = geometry.height() ? geometry.height() : 1.0f; + + /* These need to be generated against the src context */ + if (!parentFbo) + glGenFramebuffers(1, &parentFbo); + if (!parentRbo) + glGenRenderbuffers(1, &parentRbo); + glBindFramebuffer(GL_FRAMEBUFFER, parentFbo); glBindRenderbuffer(GL_RENDERBUFFER, parentRbo); - glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER, mParentBuffer->mImage); + glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER, + mParentBuffer->mImage); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, parentRbo); glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, mBuffer->mImage); glViewport(0, 0, geometry.width(), geometry.height()); - QGLShaderProgram *blitProgram = - QGLEngineSharedShaders::shadersForContext(QGLContext::currentContext())->blitProgram(); + blitProgram = QGLEngineSharedShaders::shadersForContext(QGLContext::currentContext())->blitProgram(); blitProgram->bind(); - blitProgram->setUniformValue("imageTexture", 0 /*QT_IMAGE_TEXTURE_UNIT*/); + blitProgram->setUniformValue("imageTexture", 0); + // The shader manager's blit program does not multiply the // vertices by the pmv matrix, so we need to do the effect // of the orthographic projection here ourselves. - QRectF r; - qreal w = geometry.width() ? geometry.width() : 1.0f; - qreal h = geometry.height() ? geometry.height() : 1.0f; r.setLeft((geometry.left() / w) * 2.0f - 1.0f); if (geometry.right() == (geometry.width() - 1)) r.setRight(1.0f); @@ -649,6 +659,8 @@ void QWaylandGLContext::swapBuffers() wl_surface_damage(mParentWindow->surface(), 0, 0, geometry.width(), geometry.height()); + /* restore things to the last valid GL state */ + makeCurrent(); } void *QWaylandGLContext::getProcAddress(const QString &string) |