From 221ad14f3d3120ed8a3ca8377bc7cbb76759cbc3 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Sat, 10 Sep 2011 09:57:39 +0200 Subject: Made FBO blit behave properly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Iad9b9823bbcdf1068455f743e5fbc554939f8592 Reviewed-on: http://codereview.qt-project.org/4630 Reviewed-by: Samuel Rødal --- src/gui/opengl/qopenglframebufferobject.cpp | 34 ++++++++++++++++++----------- src/gui/opengl/qopenglframebufferobject.h | 4 ++++ 2 files changed, 25 insertions(+), 13 deletions(-) (limited to 'src/gui/opengl') diff --git a/src/gui/opengl/qopenglframebufferobject.cpp b/src/gui/opengl/qopenglframebufferobject.cpp index 4512904a15..8c5eb0d877 100644 --- a/src/gui/opengl/qopenglframebufferobject.cpp +++ b/src/gui/opengl/qopenglframebufferobject.cpp @@ -1148,6 +1148,21 @@ bool QOpenGLFramebufferObject::hasOpenGLFramebufferBlit() return QOpenGLExtensions(QOpenGLContext::currentContext()).hasOpenGLExtension(QOpenGLExtensions::FramebufferBlit); } + +/*! + \overload + \sa blitFramebuffer +*/ + +void QOpenGLFramebufferObject::blitFramebuffer(QOpenGLFramebufferObject *target, + QOpenGLFramebufferObject *source, + GLbitfield buffers, GLenum filter) +{ + blitFramebuffer(target, QRect(QPoint(0, 0), target->size()), + source, QRect(QPoint(0, 0), source->size()), + buffers, filter); +} + /*! Blits from the \a sourceRect rectangle in the \a source framebuffer object to the \a targetRect rectangle in the \a target framebuffer object. @@ -1191,29 +1206,22 @@ void QOpenGLFramebufferObject::blitFramebuffer(QOpenGLFramebufferObject *target, if (!extensions.hasOpenGLExtension(QOpenGLExtensions::FramebufferBlit)) return; - QSurface *surface = ctx->surface(); - - const int height = static_cast(surface)->height(); - - const int sh = source ? source->height() : height; - const int th = target ? target->height() : height; - const int sx0 = sourceRect.left(); const int sx1 = sourceRect.left() + sourceRect.width(); - const int sy0 = sh - (sourceRect.top() + sourceRect.height()); - const int sy1 = sh - sourceRect.top(); + const int sy0 = sourceRect.top(); + const int sy1 = sourceRect.top() + sourceRect.height(); const int tx0 = targetRect.left(); const int tx1 = targetRect.left() + targetRect.width(); - const int ty0 = th - (targetRect.top() + targetRect.height()); - const int ty1 = th - targetRect.top(); + const int ty0 = targetRect.top(); + const int ty1 = targetRect.top() + targetRect.height(); extensions.glBindFramebuffer(GL_READ_FRAMEBUFFER, source ? source->handle() : 0); extensions.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, target ? target->handle() : 0); extensions.glBlitFramebuffer(sx0, sy0, sx1, sy1, - tx0, ty0, tx1, ty1, - buffers, filter); + tx0, ty0, tx1, ty1, + buffers, filter); extensions.glBindFramebuffer(GL_FRAMEBUFFER, ctx->d_func()->current_fbo); } diff --git a/src/gui/opengl/qopenglframebufferobject.h b/src/gui/opengl/qopenglframebufferobject.h index 8c3895b293..e25ec6b15c 100644 --- a/src/gui/opengl/qopenglframebufferobject.h +++ b/src/gui/opengl/qopenglframebufferobject.h @@ -112,6 +112,10 @@ public: QOpenGLFramebufferObject *source, const QRect &sourceRect, GLbitfield buffers = GL_COLOR_BUFFER_BIT, GLenum filter = GL_NEAREST); + static void blitFramebuffer(QOpenGLFramebufferObject *target, + QOpenGLFramebufferObject *source, + GLbitfield buffers = GL_COLOR_BUFFER_BIT, + GLenum filter = GL_NEAREST); private: Q_DISABLE_COPY(QOpenGLFramebufferObject) -- cgit v1.2.3