From 7307bd270b11c947c5e474598d52f319a2c185d1 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Wed, 5 Jul 2023 18:54:09 +0300 Subject: [PATCH] [OpenGL] Same for depth mask --- include/gl_state.hpp | 12 ++++++++++-- include/opengl.hpp | 2 ++ src/core/renderer_gl/renderer_gl.cpp | 4 ++-- src/gl_state.cpp | 5 ++++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/include/gl_state.hpp b/include/gl_state.hpp index fe0eba60..793d2922 100644 --- a/include/gl_state.hpp +++ b/include/gl_state.hpp @@ -22,8 +22,9 @@ struct GLStateManager { bool depthEnabled; bool scissorEnabled; - // Colour mask + // Colour/depth masks bool redMask, greenMask, blueMask, alphaMask; + bool depthMask; GLuint boundVAO; GLuint boundVBO; @@ -108,7 +109,14 @@ struct GLStateManager { b = blueMask; a = alphaMask; - glColorMask(r, g, b, a); + OpenGL::setColourMask(r, g, b, a); + } + } + + void setDepthMask(bool mask) { + if (depthMask != mask) { + depthMask = mask; + OpenGL::setDepthMask(mask); } } diff --git a/include/opengl.hpp b/include/opengl.hpp index b85347bf..f8328799 100644 --- a/include/opengl.hpp +++ b/include/opengl.hpp @@ -528,6 +528,8 @@ namespace OpenGL { static void disableClipPlane(GLuint index) { glDisable(GL_CLIP_DISTANCE0 + index); } static void setDepthFunc(DepthFunc func) { glDepthFunc(static_cast(func)); } + static void setColourMask(GLboolean r, GLboolean g, GLboolean b, GLboolean a) { glColorMask(r, g, b, a); } + static void setDepthMask(GLboolean mask) { glDepthMask(mask); } enum Primitives { Triangle = GL_TRIANGLES, diff --git a/src/core/renderer_gl/renderer_gl.cpp b/src/core/renderer_gl/renderer_gl.cpp index 9ca9f2d1..0dd5d58e 100644 --- a/src/core/renderer_gl/renderer_gl.cpp +++ b/src/core/renderer_gl/renderer_gl.cpp @@ -896,14 +896,14 @@ void Renderer::drawVertices(PICA::PrimType primType, std::span ver // Because it attaches a depth texture to the aforementioned colour buffer if (depthEnable) { gl.enableDepth(); + gl.setDepthMask(depthWriteEnable ? GL_TRUE : GL_FALSE); glDepthFunc(depthModes[depthFunc]); - glDepthMask(depthWriteEnable ? GL_TRUE : GL_FALSE); bindDepthBuffer(); } else { if (depthWriteEnable) { gl.enableDepth(); + gl.setDepthMask(GL_TRUE); glDepthFunc(GL_ALWAYS); - glDepthMask(GL_TRUE); bindDepthBuffer(); } else { gl.disableDepth(); diff --git a/src/gl_state.cpp b/src/gl_state.cpp index 2f286f70..472c16d6 100644 --- a/src/gl_state.cpp +++ b/src/gl_state.cpp @@ -7,12 +7,15 @@ void GLStateManager::resetBlend() { void GLStateManager::resetColourMask() { redMask = greenMask = blueMask = alphaMask = true; - glColorMask(redMask, greenMask, blueMask, alphaMask); + OpenGL::setColourMask(redMask, greenMask, blueMask, alphaMask); } void GLStateManager::resetDepth() { depthEnabled = false; + depthMask = true; + OpenGL::disableDepth(); + OpenGL::setDepthMask(true); } void GLStateManager::resetScissor() {