From 2f26ef087353d402b0ecf0296b3a2bde206bebed Mon Sep 17 00:00:00 2001 From: Ben Doherty Date: Wed, 31 Aug 2022 17:17:16 -0400 Subject: [PATCH] Fix OpenGL stencil buffer writes (#6023) --- RELEASE_NOTES.md | 2 ++ filament/backend/src/opengl/OpenGLDriver.cpp | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index e75bb7ab34..429beeb3b2 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -5,6 +5,8 @@ A new header is inserted each time a *tag* is created. ## main branch +- engine: Fix stencil buffer writes with OpenGL backend. + ## v1.27.0 - WebGL: reduce max instance count to work around Chrome issues [⚠️ **Recompile Materials**] diff --git a/filament/backend/src/opengl/OpenGLDriver.cpp b/filament/backend/src/opengl/OpenGLDriver.cpp index e75bd4faeb..623e90bda5 100644 --- a/filament/backend/src/opengl/OpenGLDriver.cpp +++ b/filament/backend/src/opengl/OpenGLDriver.cpp @@ -309,9 +309,16 @@ void OpenGLDriver::setStencilState(StencilState ss) noexcept { mRenderPassStencilWrite |= ss.stencilWrite; // stencil test / operation + // GL_STENCIL_TEST must be enabled if we're testing OR writing to the stencil buffer. if (UTILS_LIKELY( ss.front.stencilFunc == StencilState::StencilFunction::A && - ss.back.stencilFunc == StencilState::StencilFunction::A)) { + ss.back.stencilFunc == StencilState::StencilFunction::A && + ss.front.stencilOpDepthFail == StencilOperation::KEEP && + ss.back.stencilOpDepthFail == StencilOperation::KEEP && + ss.front.stencilOpStencilFail == StencilOperation::KEEP && + ss.back.stencilOpStencilFail == StencilOperation::KEEP && + ss.front.stencilOpDepthStencilPass == StencilOperation::KEEP && + ss.back.stencilOpDepthStencilPass == StencilOperation::KEEP)) { // that's equivalent to having the stencil test disabled gl.disable(GL_STENCIL_TEST); } else {