diff options
author | Andy Nichols <andy.nichols@qt.io> | 2018-04-12 10:14:07 +0200 |
---|---|---|
committer | Andy Nichols <andy.nichols@qt.io> | 2018-04-12 15:03:31 +0000 |
commit | 8beae9a0944b30f0008f81cbc0376af03bb4c90f (patch) | |
tree | adcef2d90924b639c320ab2a050b8c9d747012a2 | |
parent | 81cbbc022bb67a14b1cb5e855c8d4754a4538e70 (diff) |
ES2: Enable Renderbuffer usage with either Depth or Stencil
Current we require a combined DepthStencil RenderBuffer, however this is
an extension in ES2 so it's not a given that it will be available. It
is still possible to setup separate Depth and Stencil buffers for those
devices that only support that (similar to what Scenegraph does).
Change-Id: Ia112b30e229bfc553cd0cdc0f8dd8b57290c7081
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
3 files changed, 24 insertions, 6 deletions
diff --git a/src/render/renderers/opengl/graphicshelpers/graphicshelperes2.cpp b/src/render/renderers/opengl/graphicshelpers/graphicshelperes2.cpp index 966528ad8..798457edb 100644 --- a/src/render/renderers/opengl/graphicshelpers/graphicshelperes2.cpp +++ b/src/render/renderers/opengl/graphicshelpers/graphicshelperes2.cpp @@ -399,9 +399,13 @@ bool GraphicsHelperES2::checkFrameBufferComplete() bool GraphicsHelperES2::frameBufferNeedsRenderBuffer(const Attachment &attachment) { - // Use a renderbuffer for combined depth+stencil attachments since this is + // Use a renderbuffer for depth or stencil attachments since this is // problematic before GLES 3.2. Keep using textures for everything else. - return attachment.m_point == QRenderTargetOutput::DepthStencil; + // For ES2 individual Depth and Stencil buffers need to be an option because + // DepthStencil is an extension. + return attachment.m_point == QRenderTargetOutput::DepthStencil || + attachment.m_point == QRenderTargetOutput::Depth || + attachment.m_point == QRenderTargetOutput::Stencil; } void GraphicsHelperES2::bindFrameBufferAttachment(QOpenGLTexture *texture, const Attachment &attachment) @@ -436,15 +440,21 @@ void GraphicsHelperES2::bindFrameBufferAttachment(QOpenGLTexture *texture, const void GraphicsHelperES2::bindFrameBufferAttachment(RenderBuffer *renderBuffer, const Attachment &attachment) { - if (attachment.m_point != QRenderTargetOutput::DepthStencil) { - qCritical() << "Renderbuffers only supported for combined depth-stencil, but got attachment point" + if (attachment.m_point != QRenderTargetOutput::DepthStencil && + attachment.m_point != QRenderTargetOutput::Depth && + attachment.m_point != QRenderTargetOutput::Stencil) { + qCritical() << "Renderbuffers only supported for combined depth-stencil, depth, or stencil, but got attachment point" << attachment.m_point; return; } renderBuffer->bind(); - m_funcs->glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderBuffer->renderBufferId()); - m_funcs->glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderBuffer->renderBufferId()); + if (attachment.m_point == QRenderTargetOutput::DepthStencil || + attachment.m_point == QRenderTargetOutput::Depth) + m_funcs->glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderBuffer->renderBufferId()); + if (attachment.m_point == QRenderTargetOutput::DepthStencil || + attachment.m_point == QRenderTargetOutput::Stencil) + m_funcs->glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderBuffer->renderBufferId()); renderBuffer->release(); } diff --git a/src/render/renderers/opengl/graphicshelpers/graphicshelperes3.cpp b/src/render/renderers/opengl/graphicshelpers/graphicshelperes3.cpp index 813c627b8..d324baf1f 100644 --- a/src/render/renderers/opengl/graphicshelpers/graphicshelperes3.cpp +++ b/src/render/renderers/opengl/graphicshelpers/graphicshelperes3.cpp @@ -314,6 +314,13 @@ void GraphicsHelperES3::bindBufferBase(GLenum target, GLuint index, GLuint buffe m_extraFuncs->glBindBufferBase(target, index, buffer); } +bool GraphicsHelperES3::frameBufferNeedsRenderBuffer(const Attachment &attachment) +{ + // Use a renderbuffer for combined depth+stencil attachments since this is + // problematic before GLES 3.2. Keep using textures for everything else. + return attachment.m_point == QRenderTargetOutput::DepthStencil; +} + void GraphicsHelperES3::bindUniformBlock(GLuint programId, GLuint uniformBlockIndex, GLuint uniformBlockBinding) { m_extraFuncs->glUniformBlockBinding(programId, uniformBlockIndex, uniformBlockBinding); diff --git a/src/render/renderers/opengl/graphicshelpers/graphicshelperes3_p.h b/src/render/renderers/opengl/graphicshelpers/graphicshelperes3_p.h index 9bca2d48d..518226116 100644 --- a/src/render/renderers/opengl/graphicshelpers/graphicshelperes3_p.h +++ b/src/render/renderers/opengl/graphicshelpers/graphicshelperes3_p.h @@ -67,6 +67,7 @@ public: // QGraphicHelperInterface interface void bindBufferBase(GLenum target, GLuint index, GLuint buffer) override; + bool frameBufferNeedsRenderBuffer(const Attachment &attachment) override; void bindFrameBufferAttachment(QOpenGLTexture *texture, const Attachment &attachment) override; void bindUniformBlock(GLuint programId, GLuint uniformBlockIndex, GLuint uniformBlockBinding) override; void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) override; |