0032036: Visualization, TKOpenGl - broken Cubemap background on GeForce 320M
[occt.git] / src / OpenGl / OpenGl_View.cxx
index 5d1aa16..5f8e602 100644 (file)
@@ -902,12 +902,21 @@ void OpenGl_View::drawBackground (const Handle(OpenGl_Workspace)& theWorkspace,
                                   Graphic3d_Camera::Projection theProjection)
 {
   const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
-  const Standard_Boolean wasUsedZBuffer = theWorkspace->SetUseZBuffer (Standard_False);
+  const bool wasUsedZBuffer = theWorkspace->SetUseZBuffer (false);
   if (wasUsedZBuffer)
   {
     aCtx->core11fwd->glDisable (GL_DEPTH_TEST);
   }
 
+#ifdef GL_DEPTH_CLAMP
+  const bool wasDepthClamped = aCtx->arbDepthClamp && glIsEnabled (GL_DEPTH_CLAMP);
+  if (aCtx->arbDepthClamp && !wasDepthClamped)
+  {
+    // make sure background is always drawn (workaround skybox rendering on some hardware)
+    aCtx->core11fwd->glEnable (GL_DEPTH_CLAMP);
+  }
+#endif
+
   if (myBackgroundType == Graphic3d_TOB_CUBEMAP)
   {
     myCubeMapParams->Aspect()->ShaderProgram()->PushVariableInt ("uZCoeff", myBackgroundCubeMap->ZIsInverted() ? -1 : 1);
@@ -950,6 +959,12 @@ void OpenGl_View::drawBackground (const Handle(OpenGl_Workspace)& theWorkspace,
     theWorkspace->SetUseZBuffer (Standard_True);
     aCtx->core11fwd->glEnable (GL_DEPTH_TEST);
   }
+#ifdef GL_DEPTH_CLAMP
+  if (aCtx->arbDepthClamp && !wasDepthClamped)
+  {
+    aCtx->core11fwd->glDisable (GL_DEPTH_CLAMP);
+  }
+#endif
 }
 
 //=======================================================================