diff options
author | Antti Määttä <antti.maatta@qt.io> | 2017-02-03 12:20:36 +0200 |
---|---|---|
committer | Antti Määttä <antti.maatta@qt.io> | 2017-02-08 11:24:16 +0000 |
commit | e29f8cf68e2f1ed22244f84099589e9444eaf5ba (patch) | |
tree | 5f8a7848d315cf4e1e4040c7b2f79dd87b2e2356 | |
parent | 8f2e0c0948a2afcf94536e2b78a40f380422a322 (diff) |
Enable blitFramebuffer with ES2 when it is supported
Task-number: QTBUG-57573
Change-Id: Ie1be0282fbab6e4346a81f37eff7597b932da07e
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r-- | src/render/graphicshelpers/graphicscontext.cpp | 17 | ||||
-rw-r--r-- | src/render/graphicshelpers/graphicshelperes2.cpp | 25 | ||||
-rw-r--r-- | src/render/graphicshelpers/graphicshelperes2_p.h | 4 |
3 files changed, 24 insertions, 22 deletions
diff --git a/src/render/graphicshelpers/graphicscontext.cpp b/src/render/graphicshelpers/graphicscontext.cpp index aba74c8d9..cee1a568a 100644 --- a/src/render/graphicshelpers/graphicscontext.cpp +++ b/src/render/graphicshelpers/graphicscontext.cpp @@ -81,6 +81,14 @@ QT_BEGIN_NAMESPACE +#ifndef GL_READ_FRAMEBUFFER +#define GL_READ_FRAMEBUFFER 0x8CA8 +#endif + +#ifndef GL_DRAW_FRAMEBUFFER +#define GL_DRAW_FRAMEBUFFER 0x8CA9 +#endif + namespace { QOpenGLShader::ShaderType shaderType(Qt3DRender::QShaderProgram::ShaderType type) @@ -1630,10 +1638,8 @@ QImage GraphicsContext::readFramebuffer(QSize size) QImage::Format imageFormat; uint stride; -#ifndef QT_OPENGL_ES_2 /* format value should match GL internalFormat */ GLenum internalFormat = m_renderTargetFormat; -#endif switch (m_renderTargetFormat) { case QAbstractTexture::RGBAFormat: @@ -1709,18 +1715,15 @@ QImage GraphicsContext::readFramebuffer(QSize size) return img; } -#ifndef QT_OPENGL_ES_2 GLint samples = 0; m_gl->functions()->glGetIntegerv(GL_SAMPLES, &samples); if (samples > 0 && !m_glHelper->supportsFeature(GraphicsHelperInterface::BlitFramebuffer)) return img; -#endif img = QImage(size.width(), size.height(), imageFormat); QScopedArrayPointer<uchar> data(new uchar [bytes]); -#ifndef QT_OPENGL_ES_2 if (samples > 0) { // resolve multisample-framebuffer to renderbuffer and read pixels from it GLuint fbo, rb; @@ -1752,14 +1755,10 @@ QImage GraphicsContext::readFramebuffer(QSize size) gl->glBindFramebuffer(GL_FRAMEBUFFER, m_activeFBO); gl->glDeleteFramebuffers(1, &fbo); } else { -#endif // read pixels directly from framebuffer m_gl->functions()->glReadPixels(0,0,size.width(), size.height(), format, type, data.data()); copyGLFramebufferDataToImage(img, data.data(), stride, size.width(), size.height(), m_renderTargetFormat); - -#ifndef QT_OPENGL_ES_2 } -#endif return img; } diff --git a/src/render/graphicshelpers/graphicshelperes2.cpp b/src/render/graphicshelpers/graphicshelperes2.cpp index 1335b250f..b409cf5af 100644 --- a/src/render/graphicshelpers/graphicshelperes2.cpp +++ b/src/render/graphicshelpers/graphicshelperes2.cpp @@ -65,8 +65,9 @@ QT_BEGIN_NAMESPACE namespace Qt3DRender { namespace Render { -GraphicsHelperES2::GraphicsHelperES2() : - m_funcs(0) +GraphicsHelperES2::GraphicsHelperES2() + : m_funcs(0) + , m_supportFramebufferBlit(false) { } @@ -80,6 +81,9 @@ void GraphicsHelperES2::initializeHelper(QOpenGLContext *context, Q_ASSERT(context); m_funcs = context->functions(); Q_ASSERT(m_funcs); + m_ext.reset(new QOpenGLExtensions(context)); + if (m_ext->hasOpenGLExtension(QOpenGLExtensions::FramebufferBlit)) + m_supportFramebufferBlit = true; } void GraphicsHelperES2::drawElementsInstancedBaseVertexBaseInstance(GLenum primitiveType, @@ -356,6 +360,8 @@ bool GraphicsHelperES2::supportsFeature(GraphicsHelperInterface::Feature feature switch (feature) { case RenderBufferDimensionRetrieval: return true; + case BlitFramebuffer: + return m_supportFramebufferBlit; default: return false; } @@ -709,17 +715,10 @@ UniformType GraphicsHelperES2::uniformTypeFromGLType(GLenum type) void GraphicsHelperES2::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) { - Q_UNUSED(srcX0); - Q_UNUSED(srcX1); - Q_UNUSED(srcY0); - Q_UNUSED(srcY1); - Q_UNUSED(dstX0); - Q_UNUSED(dstX1); - Q_UNUSED(dstY0); - Q_UNUSED(dstY1); - Q_UNUSED(mask); - Q_UNUSED(filter); - qWarning() << "Framebuffer blits are not supported by ES 2.0 (since ES 3.1)"; + if (!m_supportFramebufferBlit) + qWarning() << "Framebuffer blits are not supported by ES 2.0 (since ES 3.1)"; + else + m_ext->glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); } } // namespace Render diff --git a/src/render/graphicshelpers/graphicshelperes2_p.h b/src/render/graphicshelpers/graphicshelperes2_p.h index 17249ef23..ddcd28ca5 100644 --- a/src/render/graphicshelpers/graphicshelperes2_p.h +++ b/src/render/graphicshelpers/graphicshelperes2_p.h @@ -57,6 +57,8 @@ QT_BEGIN_NAMESPACE +class QOpenGLExtensions; + namespace Qt3DRender { namespace Render { @@ -148,6 +150,8 @@ public: protected: QOpenGLFunctions *m_funcs; + bool m_supportFramebufferBlit; + QScopedPointer<QOpenGLExtensions> m_ext; }; } // namespace Render |