0027750: Visualization, V3d_View - remove unused functionality ZClipping and ZCueing
[occt.git] / src / OpenGl / OpenGl_Clipping.cxx
index f19232b..25398dc 100755 (executable)
 // commercial license or contractual agreement.
 
 #include <OpenGl_Clipping.hxx>
+
 #include <OpenGl_GlCore11.hxx>
 #include <OpenGl_Workspace.hxx>
+#include <OpenGl_Context.hxx>
+
+#if defined(GL_ES_VERSION_2_0)
+  // id does not matter for GLSL-based clipping, just for consistency
+  #define GL_CLIP_PLANE0 0x3000
+#endif
 
 // =======================================================================
 // function : OpenGl_ClippingState
 // purpose  :
 // =======================================================================
 OpenGl_Clipping::OpenGl_Clipping ()
-: myEmptyPlaneIds (new Aspect_GenId (GL_CLIP_PLANE0, GL_CLIP_PLANE5)),
+: myEmptyPlaneIds (new Aspect_GenId (GL_CLIP_PLANE0, GL_CLIP_PLANE0 + 5)),
   myNbClipping (0),
   myNbCapping  (0)
 {}
@@ -43,50 +50,45 @@ void OpenGl_Clipping::Init (const Standard_Integer theMaxPlanes)
 }
 
 // =======================================================================
-// function : Add
+// function : add
 // purpose  :
 // =======================================================================
-void OpenGl_Clipping::Add (Graphic3d_SequenceOfHClipPlane& thePlanes,
-                           const EquationCoords& theCoordSpace,
-                           const Handle(OpenGl_Workspace)& theWS)
+void OpenGl_Clipping::add (const Handle(OpenGl_Context)&   theGlCtx,
+                           Graphic3d_SequenceOfHClipPlane& thePlanes)
 {
-  GLint aMatrixMode;
-  glGetIntegerv (GL_MATRIX_MODE, &aMatrixMode);
-
-  OpenGl_Matrix aCurrentMx;
-  glGetFloatv (GL_MODELVIEW_MATRIX, (GLfloat*) &aCurrentMx);
-
-  if (aMatrixMode != GL_MODELVIEW)
-  {
-    glMatrixMode (GL_MODELVIEW);
-  }
-
-  switch (theCoordSpace)
+  const bool toUseFfp = theGlCtx->core11 != NULL
+                     && theGlCtx->caps->ffpEnable;
+  if (!toUseFfp)
   {
-    case EquationCoords_View:  glLoadMatrixf ((const GLfloat*) &OpenGl_IdentityMatrix); break;
-    case EquationCoords_World: glLoadMatrixf ((const GLfloat*) theWS->ViewMatrix());    break;
+    addLazy (theGlCtx, thePlanes);
+    return;
   }
 
-  Add (thePlanes, theCoordSpace);
+  // Set either identity or pure view matrix.
+  theGlCtx->ApplyWorldViewMatrix();
 
-  // restore model-view matrix
-  glLoadMatrixf ((GLfloat*) &aCurrentMx);
+  addLazy (theGlCtx, thePlanes);
 
-  // restore context matrix state
-  if (aMatrixMode != GL_MODELVIEW)
-  {
-    glMatrixMode (aMatrixMode);
-  }
+  // Restore combined model-view matrix.
+  theGlCtx->ApplyModelViewMatrix();
 }
 
 // =======================================================================
-// function : Add
+// function : addLazy
 // purpose  :
 // =======================================================================
-void OpenGl_Clipping::Add (Graphic3d_SequenceOfHClipPlane& thePlanes, const EquationCoords& theCoordSpace)
+void OpenGl_Clipping::addLazy (const Handle(OpenGl_Context)&   theGlCtx,
+                               Graphic3d_SequenceOfHClipPlane& thePlanes)
 {
+#if !defined(GL_ES_VERSION_2_0)
+  const bool toUseFfp = theGlCtx->core11 != NULL
+                     && theGlCtx->caps->ffpEnable;
+#else
+  (void )theGlCtx;
+#endif
+
   Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (thePlanes);
-  while (aPlaneIt.More() && myEmptyPlaneIds->Available() > 0)
+  while (aPlaneIt.More() && myEmptyPlaneIds->HasFree())
   {
     const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
     if (Contains (aPlane))
@@ -97,10 +99,15 @@ void OpenGl_Clipping::Add (Graphic3d_SequenceOfHClipPlane& thePlanes, const Equa
 
     Standard_Integer anID = myEmptyPlaneIds->Next();
     myPlanes.Append (aPlane);
-    myPlaneStates.Bind (aPlane, PlaneProps (theCoordSpace, anID, Standard_True));
+    myPlaneStates.Bind (aPlane, PlaneProps (anID, Standard_True));
 
-    glEnable ((GLenum)anID);
-    glClipPlane ((GLenum)anID, aPlane->GetEquation());
+  #if !defined(GL_ES_VERSION_2_0)
+    if (toUseFfp)
+    {
+      ::glEnable ((GLenum)anID);
+      theGlCtx->core11->glClipPlane ((GLenum)anID, aPlane->GetEquation());
+    }
+  #endif
     if (aPlane->IsCapping())
     {
       ++myNbCapping;
@@ -113,9 +120,12 @@ void OpenGl_Clipping::Add (Graphic3d_SequenceOfHClipPlane& thePlanes, const Equa
     aPlaneIt.Next();
   }
 
-  while (aPlaneIt.More() && myEmptyPlaneIds->Available() == 0)
+  if (!myEmptyPlaneIds->HasFree())
   {
-    thePlanes.Remove (aPlaneIt);
+    while (aPlaneIt.More())
+    {
+      thePlanes.Remove (aPlaneIt);
+    }
   }
 }
 
@@ -123,8 +133,16 @@ void OpenGl_Clipping::Add (Graphic3d_SequenceOfHClipPlane& thePlanes, const Equa
 // function : Remove
 // purpose  :
 // =======================================================================
-void OpenGl_Clipping::Remove (const Graphic3d_SequenceOfHClipPlane& thePlanes)
+void OpenGl_Clipping::Remove (const Handle(OpenGl_Context)&         theGlCtx,
+                              const Graphic3d_SequenceOfHClipPlane& thePlanes)
 {
+#if !defined(GL_ES_VERSION_2_0)
+  const bool toUseFfp = theGlCtx->core11 != NULL
+                     && theGlCtx->caps->ffpEnable;
+#else
+  (void )theGlCtx;
+#endif
+
   Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (thePlanes);
   for (; aPlaneIt.More(); aPlaneIt.Next())
   {
@@ -138,7 +156,12 @@ void OpenGl_Clipping::Remove (const Graphic3d_SequenceOfHClipPlane& thePlanes)
     PlaneProps& aProps = myPlaneStates.ChangeFind (aPlane);
     if (aProps.IsEnabled)
     {
-      glDisable ((GLenum)anID);
+    #if !defined(GL_ES_VERSION_2_0)
+      if (toUseFfp)
+      {
+        ::glDisable ((GLenum)anID);
+      }
+    #endif
       if (aPlane->IsCapping())
       {
         --myNbCapping;
@@ -173,8 +196,9 @@ void OpenGl_Clipping::Remove (const Graphic3d_SequenceOfHClipPlane& thePlanes)
 // function : SetEnabled
 // purpose  :
 // =======================================================================
-void OpenGl_Clipping::SetEnabled (const Handle(Graphic3d_ClipPlane)& thePlane,
-                                  const Standard_Boolean theIsEnabled)
+void OpenGl_Clipping::SetEnabled (const Handle(OpenGl_Context)&      theGlCtx,
+                                  const Handle(Graphic3d_ClipPlane)& thePlane,
+                                  const Standard_Boolean             theIsEnabled)
 {
   if (!Contains (thePlane))
   {
@@ -187,10 +211,21 @@ void OpenGl_Clipping::SetEnabled (const Handle(Graphic3d_ClipPlane)& thePlane,
     return;
   }
 
+#if !defined(GL_ES_VERSION_2_0)
   GLenum anID = (GLenum)aProps.ContextID;
+  const bool toUseFfp = theGlCtx->core11 != NULL
+                     && theGlCtx->caps->ffpEnable;
+#else
+  (void )theGlCtx;
+#endif
   if (theIsEnabled)
   {
-    glEnable (anID);
+  #if !defined(GL_ES_VERSION_2_0)
+    if (toUseFfp)
+    {
+      ::glEnable (anID);
+    }
+  #endif
     if (thePlane->IsCapping())
     {
       ++myNbCapping;
@@ -202,7 +237,12 @@ void OpenGl_Clipping::SetEnabled (const Handle(Graphic3d_ClipPlane)& thePlane,
   }
   else
   {
-    glDisable (anID);
+  #if !defined(GL_ES_VERSION_2_0)
+    if (toUseFfp)
+    {
+      ::glDisable (anID);
+    }
+  #endif
     if (thePlane->IsCapping())
     {
       --myNbCapping;