diff --git a/Common/GPU/OpenGL/GLQueueRunner.cpp b/Common/GPU/OpenGL/GLQueueRunner.cpp index 08af252ffd..0bd9a92e90 100644 --- a/Common/GPU/OpenGL/GLQueueRunner.cpp +++ b/Common/GPU/OpenGL/GLQueueRunner.cpp @@ -836,6 +836,13 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last bool clipDistanceEnabled[8]{}; GLuint blendEqColor = (GLuint)-1; GLuint blendEqAlpha = (GLuint)-1; + GLuint stencilWriteMask = (GLuint)-1; + GLenum stencilFunc = (GLenum)-1; + GLuint stencilRef = (GLuint)-1; + GLuint stencilCompareMask = (GLuint)-1; + GLenum stencilSFail = (GLenum)-1; + GLenum stencilZFail = (GLenum)-1; + GLenum stencilPass = (GLenum)-1; GLRTexture *curTex[MAX_GL_TEXTURE_SLOTS]{}; @@ -868,9 +875,22 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last glEnable(GL_STENCIL_TEST); stencilEnabled = true; } - glStencilFunc(c.stencil.func, c.stencil.ref, c.stencil.compareMask); - glStencilOp(c.stencil.sFail, c.stencil.zFail, c.stencil.pass); - glStencilMask(c.stencil.writeMask); + if (c.stencil.func != stencilFunc || c.stencil.ref != stencilRef || c.stencil.compareMask != stencilCompareMask) { + glStencilFunc(c.stencil.func, c.stencil.ref, c.stencil.compareMask); + stencilFunc = c.stencil.func; + stencilRef = c.stencil.ref; + stencilCompareMask = c.stencil.compareMask; + } + if (c.stencil.sFail != stencilSFail || c.stencil.zFail != stencilZFail || c.stencil.pass != stencilPass) { + glStencilOp(c.stencil.sFail, c.stencil.zFail, c.stencil.pass); + stencilSFail = c.stencil.sFail; + stencilZFail = c.stencil.zFail; + stencilPass = c.stencil.pass; + } + if (c.stencil.writeMask != stencilWriteMask) { + glStencilMask(c.stencil.writeMask); + stencilWriteMask = c.stencil.writeMask; + } } else if (/* !c.stencilFunc.enabled && */stencilEnabled) { glDisable(GL_STENCIL_TEST); stencilEnabled = false;