0027755: Visualization, V3d_View::ToPixMap() - fix image dump with MSAA turned on
[occt.git] / src / OpenGl / OpenGl_View_Redraw.cxx
index 78af8c7..7478fbb 100644 (file)
@@ -318,13 +318,23 @@ void OpenGl_View::Redraw()
      || myMainSceneFbos[0]->GetVPSizeY() != aSizeY
      || myMainSceneFbos[0]->NbSamples()  != aNbSamples)
     {
+      if (!myTransientDrawToFront)
+      {
+        myImmediateSceneFbos[0]->Release (aCtx.operator->());
+        myImmediateSceneFbos[1]->Release (aCtx.operator->());
+        myImmediateSceneFbos[0]->ChangeViewport (0, 0);
+        myImmediateSceneFbos[1]->ChangeViewport (0, 0);
+      }
+
       // prepare FBOs containing main scene
       // for further blitting and rendering immediate presentations on top
       if (aCtx->core20fwd != NULL)
       {
         myMainSceneFbos[0]->Init (aCtx, aSizeX, aSizeY, myFboColorFormat, myFboDepthFormat, aNbSamples);
       }
-      if (!aCtx->caps->useSystemBuffer && myMainSceneFbos[0]->IsValid())
+      if (myTransientDrawToFront
+       && !aCtx->caps->useSystemBuffer
+       && myMainSceneFbos[0]->IsValid())
       {
         myImmediateSceneFbos[0]->InitLazy (aCtx, *myMainSceneFbos[0]);
       }
@@ -434,6 +444,10 @@ void OpenGl_View::Redraw()
     {
       anImmFbo = myImmediateSceneFbos[0].operator->();
     }
+    if (!myTransientDrawToFront)
+    {
+      anImmFbo = aMainFbo;
+    }
 
   #if !defined(GL_ES_VERSION_2_0)
     if (aMainFbo     == NULL
@@ -708,7 +722,8 @@ bool OpenGl_View::redrawImmediate (const Graphic3d_Camera::Projection theProject
 {
   Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
   GLboolean toCopyBackToFront = GL_FALSE;
-  if (!myTransientDrawToFront)
+  if (theDrawFbo == theReadFbo
+   && theDrawFbo != NULL)
   {
     myBackBufferRestored = Standard_False;
   }
@@ -922,10 +937,6 @@ void OpenGl_View::render (Graphic3d_Camera::Projection theProjection,
 #endif
 
   aManager->SetShadingModel (myShadingModel);
-  if (!aManager->IsEmpty())
-  {
-    aManager->UpdateClippingState();
-  }
 
   // Redraw 3d scene
   if (theProjection == Graphic3d_Camera::Projection_MonoLeftEye)
@@ -954,17 +965,11 @@ void OpenGl_View::render (Graphic3d_Camera::Projection theProjection,
   // before drawing auxiliary stuff (trihedrons, overlayer)
   myWorkspace->ResetAppliedAspect();
 
-  aContext->ChangeClipping().RemoveAll (aContext);
-
-  if (!aManager->IsEmpty())
-  {
-    aManager->RevertClippingState();
 
-    // We need to disable (unbind) all shaders programs to ensure
-    // that all objects without specified aspect will be drawn
-    // correctly (such as background)
-    aContext->BindProgram (NULL);
-  }
+  // We need to disable (unbind) all shaders programs to ensure
+  // that all objects without specified aspect will be drawn
+  // correctly (such as background)
+  aContext->BindProgram (NULL);
 
   // Render trihedron
   if (!theToDrawImmediate)
@@ -1192,6 +1197,8 @@ void OpenGl_View::renderScene (Graphic3d_Camera::Projection theProjection,
       // add planes at loaded view matrix state
       aContext->ChangeClipping().AddView (aContext, aSlicingPlanes);
     }
+
+    aContext->ShaderManager()->UpdateClippingState();
   }
 
 #ifdef _WIN32
@@ -1221,13 +1228,10 @@ void OpenGl_View::renderScene (Graphic3d_Camera::Projection theProjection,
 
     if (!aUserPlanes.IsEmpty())
     {
-      aContext->ChangeClipping().AddWorldLazy (aContext, aUserPlanes);
+      aContext->ChangeClipping().AddWorld (aContext, aUserPlanes);
     }
 
-    if (!aContext->ShaderManager()->IsEmpty())
-    {
-      aContext->ShaderManager()->UpdateClippingState();
-    }
+    aContext->ShaderManager()->UpdateClippingState();
   }
 
 #if !defined(GL_ES_VERSION_2_0)
@@ -1314,6 +1318,16 @@ void OpenGl_View::renderScene (Graphic3d_Camera::Projection theProjection,
   // Apply restored view matrix.
   aContext->ApplyWorldViewMatrix();
 
+  aContext->ChangeClipping().RemoveAll (aContext);
+  if (!myClipPlanes.IsEmpty())
+  {
+    aContext->ShaderManager()->RevertClippingState();
+  }
+  if (myZClip.Back.IsOn || myZClip.Front.IsOn)
+  {
+    aContext->ShaderManager()->RevertClippingState();
+  }
+
 #ifdef _WIN32
   // set printing scale/tiling transformation
   if (!aPrintContext.IsNull())
@@ -1340,6 +1354,7 @@ void OpenGl_View::bindDefaultFbo (OpenGl_FrameBuffer* theCustomFbo)
   if (anFbo != NULL)
   {
     anFbo->BindBuffer (aCtx);
+    anFbo->SetupViewport (aCtx);
   }
   else
   {
@@ -1351,8 +1366,8 @@ void OpenGl_View::bindDefaultFbo (OpenGl_FrameBuffer* theCustomFbo)
       aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
     }
   #endif
+    aCtx->core11fwd->glViewport (0, 0, myWindow->Width(), myWindow->Height());
   }
-  aCtx->core11fwd->glViewport (0, 0, myWindow->Width(), myWindow->Height());
 }
 
 // =======================================================================