0026940: Visualization, TKOpenGl - capping plane should be applied to connected struc...
[occt.git] / src / OpenGl / OpenGl_CappingAlgo.cxx
index cb94604..33d6df3 100755 (executable)
 #include <OpenGl_CappingPlaneResource.hxx>
 #include <OpenGl_Vec.hxx>
 #include <OpenGl_Structure.hxx>
-
-IMPLEMENT_STANDARD_HANDLE(OpenGl_CappingAlgoFilter, OpenGl_RenderFilter)
-IMPLEMENT_STANDARD_RTTIEXT(OpenGl_CappingAlgoFilter, OpenGl_RenderFilter)
-
-Handle(OpenGl_RenderFilter) OpenGl_CappingAlgo::myRenderFilter;
-OpenGl_AspectFace OpenGl_CappingAlgo::myFrontCulling;
-OpenGl_AspectFace OpenGl_CappingAlgo::myNoneCulling;
-Standard_Boolean OpenGl_CappingAlgo::myIsInit = Standard_False;
+#include <Graphic3d_GraphicDriver.hxx>
 
 namespace
 {
-
 #if !defined(GL_ES_VERSION_2_0)
   static const GLint THE_FILLPRIM_FROM = GL_TRIANGLES;
   static const GLint THE_FILLPRIM_TO   = GL_POLYGON;
@@ -45,8 +37,8 @@ namespace
 // function : RenderCapping
 // purpose  :
 // =======================================================================
-void OpenGl_CappingAlgo::RenderCapping (const Handle(OpenGl_Workspace)&  theWorkspace,
-                                        const Graphic3d_SequenceOfGroup& theGroups)
+void OpenGl_CappingAlgo::RenderCapping (const Handle(OpenGl_Workspace)& theWorkspace,
+                                        const OpenGl_Structure&         theStructure)
 {
   const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
 
@@ -70,16 +62,12 @@ void OpenGl_CappingAlgo::RenderCapping (const Handle(OpenGl_Workspace)&  theWork
     return;
   }
 
-  // init internal data
-  Init();
-
   // remember current aspect face defined in workspace
   const OpenGl_AspectFace* aFaceAsp = theWorkspace->AspectFace (Standard_False);
 
   // replace primitive groups rendering filter
-  static Handle(OpenGl_CappingAlgoFilter) aCappingFilter = new OpenGl_CappingAlgoFilter();
   Handle(OpenGl_RenderFilter) aRenderFilter = theWorkspace->GetRenderFilter();
-  theWorkspace->SetRenderFilter (aCappingFilter);
+  theWorkspace->SetRenderFilter (theWorkspace->DefaultCappingAlgoFilter());
 
   // prepare for rendering the clip planes
   glEnable (GL_STENCIL_TEST);
@@ -106,14 +94,14 @@ void OpenGl_CappingAlgo::RenderCapping (const Handle(OpenGl_Workspace)&  theWork
     {
       const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
       const Standard_Boolean isOn = (aPlane == aRenderPlane);
-      aContext->ChangeClipping().SetEnabled (aPlane, isOn);
+      aContext->ChangeClipping().SetEnabled (aContext, aPlane, isOn);
     }
 
     glClear (GL_STENCIL_BUFFER_BIT);
     glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
 
     // override aspects, disable culling
-    theWorkspace->SetAspectFace (NoneCulling());
+    theWorkspace->SetAspectFace (&theWorkspace->NoneCulling());
     theWorkspace->AspectFace (Standard_True);
 
     // evaluate number of pair faces
@@ -122,16 +110,11 @@ void OpenGl_CappingAlgo::RenderCapping (const Handle(OpenGl_Workspace)&  theWork
     glStencilFunc (GL_ALWAYS, 1, 0x01);
     glStencilOp (GL_KEEP, GL_INVERT, GL_INVERT);
 
-    for (OpenGl_Structure::GroupIterator aGroupIt (theGroups); aGroupIt.More(); aGroupIt.Next())
-    {
-      if (aGroupIt.Value()->IsClosed())
-      {
-        aGroupIt.Value()->Render (theWorkspace);
-      }
-    }
+    // render closed primitives
+    theStructure.renderClosedGeometry (theWorkspace);
 
     // override material, cull back faces
-    theWorkspace->SetAspectFace (FrontCulling());
+    theWorkspace->SetAspectFace (&theWorkspace->FrontCulling());
     theWorkspace->AspectFace (Standard_True);
 
     // enable all clip plane except the rendered one
@@ -139,7 +122,7 @@ void OpenGl_CappingAlgo::RenderCapping (const Handle(OpenGl_Workspace)&  theWork
     {
       const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
       const Standard_Boolean isOn = (aPlane != aRenderPlane);
-      aContext->ChangeClipping().SetEnabled (aPlane, isOn);
+      aContext->ChangeClipping().SetEnabled (aContext, aPlane, isOn);
     }
 
     // render capping plane using the generated stencil mask
@@ -161,7 +144,7 @@ void OpenGl_CappingAlgo::RenderCapping (const Handle(OpenGl_Workspace)&  theWork
   // enable clipping
   for (aCappingIt.Init (aContextPlanes); aCappingIt.More(); aCappingIt.Next())
   {
-    aContext->ChangeClipping().SetEnabled (aCappingIt.Value(), Standard_True);
+    aContext->ChangeClipping().SetEnabled (aContext, aCappingIt.Value(), Standard_True);
   }
 
   // restore rendering aspects
@@ -215,25 +198,6 @@ void OpenGl_CappingAlgo::RenderPlane (const Handle(OpenGl_Workspace)& theWorkspa
   aContext->ReleaseResource (aResId, Standard_True);
 }
 
-// =======================================================================
-// function : Init
-// purpose  :
-// =======================================================================
-void OpenGl_CappingAlgo::Init()
-{
-  if (myIsInit)
-    return;
-
-  myRenderFilter = new OpenGl_CappingAlgoFilter();
-  myNoneCulling.ChangeCullingMode() = TelCullNone;
-  myNoneCulling.ChangeEdge() = 0;
-
-  myFrontCulling.ChangeCullingMode() = TelCullBack;
-  myFrontCulling.ChangeEdge() = 0;
-
-  myIsInit = Standard_True;
-}
-
 // =======================================================================
 // function : CanRender
 // purpose  :