From 09cd3b68c9aec4b1b42655679f8ae2892c3e16c2 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Tue, 2 Apr 2019 21:13:01 -0300 Subject: [PATCH] Explicitly disable color FBO attachments where possible for depth/stencil canvases. Potentially fixes issue #1470 --- src/modules/graphics/opengl/Canvas.cpp | 22 ++++++++++++++++++++++ src/modules/graphics/opengl/Graphics.cpp | 13 ++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/modules/graphics/opengl/Canvas.cpp b/src/modules/graphics/opengl/Canvas.cpp index 5424665c8..80f647937 100644 --- a/src/modules/graphics/opengl/Canvas.cpp +++ b/src/modules/graphics/opengl/Canvas.cpp @@ -41,6 +41,17 @@ static GLenum createFBO(GLuint &framebuffer, TextureType texType, PixelFormat fo if (texture != 0) { + if (isPixelFormatDepthStencil(format) && (GLAD_ES_VERSION_3_0 || !GLAD_ES_VERSION_2_0)) + { + // glDrawBuffers is an ext in GL2. glDrawBuffer doesn't exist in ES3. + GLenum none = GL_NONE; + if (GLAD_ES_VERSION_3_0) + glDrawBuffers(1, &none); + else + glDrawBuffer(GL_NONE); + glReadBuffer(GL_NONE); + } + bool unusedSRGB = false; OpenGL::TextureFormat fmt = OpenGL::convertPixelFormat(format, false, unusedSRGB); @@ -109,6 +120,17 @@ static bool createRenderbuffer(int width, int height, int &samples, PixelFormat glGenFramebuffers(1, &fbo); gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, fbo); + if (isPixelFormatDepthStencil(pixelformat) && (GLAD_ES_VERSION_3_0 || !GLAD_ES_VERSION_2_0)) + { + // glDrawBuffers is an ext in GL2. glDrawBuffer doesn't exist in ES3. + GLenum none = GL_NONE; + if (GLAD_ES_VERSION_3_0) + glDrawBuffers(1, &none); + else + glDrawBuffer(GL_NONE); + glReadBuffer(GL_NONE); + } + glGenRenderbuffers(1, &buffer); glBindRenderbuffer(GL_RENDERBUFFER, buffer); diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index af28cd551..f862c83da 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -821,6 +821,7 @@ void Graphics::bindCachedFBO(const RenderTargets &targets) else { int msaa = targets.getFirstTarget().canvas->getMSAA(); + bool hasDS = targets.depthStencil.canvas != nullptr; glGenFramebuffers(1, &fbo); gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, fbo); @@ -865,11 +866,21 @@ void Graphics::bindCachedFBO(const RenderTargets &targets) for (const auto &rt : targets.colors) attachCanvas(rt); - if (targets.depthStencil.canvas != nullptr) + if (hasDS) attachCanvas(targets.depthStencil); if (ncolortargets > 1) glDrawBuffers(ncolortargets, drawbuffers); + else if (ncolortargets == 0 && hasDS && (GLAD_ES_VERSION_3_0 || !GLAD_ES_VERSION_2_0)) + { + // glDrawBuffers is an ext in GL2. glDrawBuffer doesn't exist in ES3. + GLenum none = GL_NONE; + if (GLAD_ES_VERSION_3_0) + glDrawBuffers(1, &none); + else + glDrawBuffer(GL_NONE); + glReadBuffer(GL_NONE); + } GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);