From 2c99a81b2cb7428c2d03eca98617aa34279ea166 Mon Sep 17 00:00:00 2001 From: Cory Quammen <cory.quammen@kitware.com> Date: Fri, 7 Feb 2025 17:02:52 -0500 Subject: [PATCH] vtkValuePass: save and restores GL state to fix rendering issues When initializing the FBOs, blending, scissor testing, and depth testing are disabled for the first render, which leads to junk results on the first render. Fix by saving and restoring that OpenGL state. --- Rendering/OpenGL2/vtkValuePass.cxx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Rendering/OpenGL2/vtkValuePass.cxx b/Rendering/OpenGL2/vtkValuePass.cxx index 3af34b82355..9e596080680 100644 --- a/Rendering/OpenGL2/vtkValuePass.cxx +++ b/Rendering/OpenGL2/vtkValuePass.cxx @@ -621,6 +621,13 @@ bool vtkValuePass::InitializeFBO(vtkRenderer* ren) this->ImplFloat->ValueFBO = vtkOpenGLFramebufferObject::New(); this->ImplFloat->ValueFBO->SetContext(renWin); renWin->GetState()->PushFramebufferBindings(); + + // vtkOpenGLFramebufferObject::InitializeViewport disables blending, scissor test and + // depth test. Save and restore them in scoped variables. + vtkOpenGLState* glstate = renWin->GetState(); + vtkOpenGLState::ScopedglEnableDisable blendState(glstate, GL_BLEND); + vtkOpenGLState::ScopedglEnableDisable depthTestState(glstate, GL_DEPTH_TEST); + vtkOpenGLState::ScopedglEnableDisable scissorTestState(glstate, GL_SCISSOR_TEST); this->ImplFloat->ValueFBO->Bind(); this->ImplFloat->ValueFBO->InitializeViewport(size[0], size[1]); /* GL_COLOR_ATTACHMENT0 */ @@ -635,7 +642,7 @@ bool vtkValuePass::InitializeFBO(vtkRenderer* ren) return false; } - renWin->GetState()->PopFramebufferBindings(); + glstate->PopFramebufferBindings(); this->ImplFloat->FBOAllocated = true; return true; -- GitLab