From 52c7783ae1b8051aa34c1b0faf907ac69c84af09 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Wed, 5 Jul 2023 19:08:13 +0300 Subject: [PATCH] [OpenGL] Same for depth func --- include/gl_state.hpp | 17 ++++++++++++++--- src/core/renderer_gl/renderer_gl.cpp | 4 ++-- src/gl_state.cpp | 2 ++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/include/gl_state.hpp b/include/gl_state.hpp index 793d2922..82531c7a 100644 --- a/include/gl_state.hpp +++ b/include/gl_state.hpp @@ -30,6 +30,8 @@ struct GLStateManager { GLuint boundVBO; GLuint currentProgram; + GLenum depthFunc; + void reset(); void resetBlend(); void resetColourMask(); @@ -102,6 +104,10 @@ struct GLStateManager { } } + void bindVAO(const OpenGL::VertexArray& vao) { bindVAO(vao.handle()); } + void bindVBO(const OpenGL::VertexBuffer& vbo) { bindVBO(vbo.handle()); } + void useProgram(const OpenGL::Program& program) { useProgram(program.handle()); } + void setColourMask(bool r, bool g, bool b, bool a) { if (r != redMask || g != greenMask || b != blueMask || a != alphaMask) { r = redMask; @@ -120,9 +126,14 @@ struct GLStateManager { } } - void bindVAO(const OpenGL::VertexArray& vao) { bindVAO(vao.handle()); } - void bindVBO(const OpenGL::VertexBuffer& vbo) { bindVBO(vbo.handle()); } - void useProgram(const OpenGL::Program& program) { useProgram(program.handle()); } + void setDepthFunc(GLenum func) { + if (depthFunc != func) { + depthFunc = func; + glDepthFunc(func); + } + } + + void setDepthFunc(OpenGL::DepthFunc func) { setDepthFunc(static_cast(func)); } }; static_assert(std::is_trivially_constructible(), "OpenGL State Manager class is not trivially constructible!"); diff --git a/src/core/renderer_gl/renderer_gl.cpp b/src/core/renderer_gl/renderer_gl.cpp index 0dd5d58e..acc31936 100644 --- a/src/core/renderer_gl/renderer_gl.cpp +++ b/src/core/renderer_gl/renderer_gl.cpp @@ -897,13 +897,13 @@ void Renderer::drawVertices(PICA::PrimType primType, std::span ver if (depthEnable) { gl.enableDepth(); gl.setDepthMask(depthWriteEnable ? GL_TRUE : GL_FALSE); - glDepthFunc(depthModes[depthFunc]); + gl.setDepthFunc(depthModes[depthFunc]); bindDepthBuffer(); } else { if (depthWriteEnable) { gl.enableDepth(); gl.setDepthMask(GL_TRUE); - glDepthFunc(GL_ALWAYS); + gl.setDepthFunc(GL_ALWAYS); bindDepthBuffer(); } else { gl.disableDepth(); diff --git a/src/gl_state.cpp b/src/gl_state.cpp index 472c16d6..612ae44d 100644 --- a/src/gl_state.cpp +++ b/src/gl_state.cpp @@ -13,9 +13,11 @@ void GLStateManager::resetColourMask() { void GLStateManager::resetDepth() { depthEnabled = false; depthMask = true; + depthFunc = GL_LESS; OpenGL::disableDepth(); OpenGL::setDepthMask(true); + OpenGL::setDepthFunc(OpenGL::DepthFunc::Less); } void GLStateManager::resetScissor() {