From 9cdff4781fea29842177065a0cd4db4fb4f83dcc Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 24 Mar 2024 20:47:37 +1000 Subject: [PATCH] OpenGLDevice: Fix depth clears not going through --- src/util/opengl_texture.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/util/opengl_texture.cpp b/src/util/opengl_texture.cpp index 96795a38a..9bc99ffd8 100644 --- a/src/util/opengl_texture.cpp +++ b/src/util/opengl_texture.cpp @@ -484,17 +484,25 @@ void OpenGLDevice::CommitClear(OpenGLTexture* tex) { const float depth = tex->GetClearDepth(); glDisable(GL_SCISSOR_TEST); + if (!m_last_depth_state.depth_write) + glDepthMask(GL_TRUE); glClearBufferfv(GL_DEPTH, 0, &depth); + if (!m_last_depth_state.depth_write) + glDepthMask(GL_FALSE); glEnable(GL_SCISSOR_TEST); } else { const auto color = tex->GetUNormClearColor(); glDisable(GL_SCISSOR_TEST); - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + if (m_last_blend_state.write_mask != 0xf) + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glClearBufferfv(GL_COLOR, 0, color.data()); - glColorMask(m_last_blend_state.write_r, m_last_blend_state.write_g, m_last_blend_state.write_b, - m_last_blend_state.write_a); + if (m_last_blend_state.write_mask != 0xf) + { + glColorMask(m_last_blend_state.write_r, m_last_blend_state.write_g, m_last_blend_state.write_b, + m_last_blend_state.write_a); + } glEnable(GL_SCISSOR_TEST); } @@ -529,10 +537,14 @@ void OpenGLDevice::CommitRTClearInFB(OpenGLTexture* tex, u32 idx) { const auto color = tex->GetUNormClearColor(); glDisable(GL_SCISSOR_TEST); - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + if (m_last_blend_state.write_mask != 0xf) + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glClearBufferfv(GL_COLOR, static_cast(idx), color.data()); - glColorMask(m_last_blend_state.write_r, m_last_blend_state.write_g, m_last_blend_state.write_b, - m_last_blend_state.write_a); + if (m_last_blend_state.write_mask != 0xf) + { + glColorMask(m_last_blend_state.write_r, m_last_blend_state.write_g, m_last_blend_state.write_b, + m_last_blend_state.write_a); + } glEnable(GL_SCISSOR_TEST); tex->SetState(GPUTexture::State::Dirty); } @@ -562,7 +574,11 @@ void OpenGLDevice::CommitDSClearInFB(OpenGLTexture* tex) { const float depth = tex->GetClearDepth(); glDisable(GL_SCISSOR_TEST); + if (!m_last_depth_state.depth_write) + glDepthMask(GL_TRUE); glClearBufferfv(GL_DEPTH, 0, &depth); + if (!m_last_depth_state.depth_write) + glDepthMask(GL_FALSE); glEnable(GL_SCISSOR_TEST); tex->SetState(GPUTexture::State::Dirty); }