From d047a37e2b97ecc8158680b6ca192c6175b270fb Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 1 Apr 2016 14:03:36 -1000 Subject: [PATCH] OpenGL depth-buffer resize fix --- lib/graphicsdev/GL.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/graphicsdev/GL.cpp b/lib/graphicsdev/GL.cpp index 8211aab..40b1a28 100644 --- a/lib/graphicsdev/GL.cpp +++ b/lib/graphicsdev/GL.cpp @@ -228,12 +228,14 @@ public: void bind(size_t idx, int b); }; +static std::vector DepthInitializer; + class GLTextureR : public ITextureR { friend class GLDataFactory; friend struct GLCommandQueue; struct GLCommandQueue* m_q; - GLuint m_texs[2]; + GLuint m_texs[2] = {}; GLuint m_bindTexs[2] = {}; GLuint m_fbo = 0; size_t m_width = 0; @@ -279,7 +281,10 @@ public: glBindTexture(GL_TEXTURE_2D, m_texs[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glBindTexture(GL_TEXTURE_2D, m_texs[1]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr); + + if (DepthInitializer.size() < width * height) + DepthInitializer.resize(width * height, ~0); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, DepthInitializer.data()); if (m_bindTexs[0]) { @@ -398,6 +403,7 @@ public: else glDisable(GL_DEPTH_TEST); glDepthMask(m_depthWrite); + glDepthFunc(GL_LEQUAL); if (m_backfaceCulling) glEnable(GL_CULL_FACE); @@ -907,6 +913,13 @@ struct GLCommandQueue : IGraphicsCommandQueue break; self->m_drawBuf = self->m_completeBuf; + if (self->m_pendingFboAdds.size()) + { + for (GLTextureR* tex : self->m_pendingFboAdds) + ConfigureFBO(tex); + self->m_pendingFboAdds.clear(); + } + if (self->m_pendingResizes.size()) { for (const RenderTextureResize& resize : self->m_pendingResizes) @@ -928,13 +941,6 @@ struct GLCommandQueue : IGraphicsCommandQueue self->m_pendingFmtDels.clear(); } - if (self->m_pendingFboAdds.size()) - { - for (GLTextureR* tex : self->m_pendingFboAdds) - ConfigureFBO(tex); - self->m_pendingFboAdds.clear(); - } - if (self->m_pendingFboDels.size()) { for (GLuint fbo : self->m_pendingFboDels)