From f973f7b5e34c4e77f994ee225078e0f238e265aa Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Mon, 12 Jun 2017 21:25:27 -0700 Subject: [PATCH] Fix the background not rendering on the second frame, this was imply due to a bug in the GLBackend --- interface/src/Application.cpp | 2 +- libraries/gpu-gl/src/gpu/gl/GLBackendOutput.cpp | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f116b5fd6d..cd8b42af1a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1873,8 +1873,8 @@ void Application::initializeGL() { isDeferred = false; } - _renderEngine->addJob("MainFrame", cullFunctor, isDeferred); _renderEngine->addJob("SecondaryCameraFrame", cullFunctor); + _renderEngine->addJob("MainFrame", cullFunctor, isDeferred); /* _renderEngine->addJob("RenderShadowTask", cullFunctor); diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackendOutput.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackendOutput.cpp index a89bc69948..358b90ed8b 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackendOutput.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackendOutput.cpp @@ -63,11 +63,17 @@ void GLBackend::do_clearFramebuffer(const Batch& batch, size_t paramOffset) { int useScissor = batch._params[paramOffset + 0]._int; GLuint glmask = 0; + bool restoreStencilMask = false; + uint8_t cacheStencilMask = 0xFF; if (masks & Framebuffer::BUFFER_STENCIL) { glClearStencil(stencil); glmask |= GL_STENCIL_BUFFER_BIT; - // TODO: we will probably need to also check the write mask of stencil like we do - // for depth buffer, but as would say a famous Fez owner "We'll cross that bridge when we come to it" + + cacheStencilMask = _pipeline._stateCache.stencilActivation.getWriteMaskFront(); + if (cacheStencilMask != 0xFF) { + restoreStencilMask = true; + glStencilMask( 0xFF); + } } bool restoreDepthMask = false; @@ -121,6 +127,11 @@ void GLBackend::do_clearFramebuffer(const Batch& batch, size_t paramOffset) { glDisable(GL_SCISSOR_TEST); } + // Restore Stencil write mask + if (restoreStencilMask) { + glStencilMask(cacheStencilMask); + } + // Restore write mask meaning turn back off if (restoreDepthMask) { glDepthMask(GL_FALSE);