0025885: Visualization, ray tracing - Improve layer processing
[occt.git] / src / OpenGl / OpenGl_View.cxx
index 1e409ed..9694079 100644 (file)
@@ -35,8 +35,6 @@ IMPLEMENT_STANDARD_RTTIEXT(OpenGl_View,MMgt_TShared)
 
 /*----------------------------------------------------------------------*/
 
-static const OPENGL_BG_TEXTURE myDefaultBgTexture = { 0, 0, 0, Aspect_FM_CENTERED };
-static const OPENGL_BG_GRADIENT myDefaultBgGradient = { {{ 0.F, 0.F, 0.F, 1.F }}, {{ 0.F, 0.F, 0.F, 1.F }}, Aspect_GFM_NONE };
 static const Tmatrix3 myDefaultMatrix = { { 1.F, 0.F, 0.F, 0.F }, { 0.F, 1.F, 0.F, 0.F }, { 0.F, 0.F, 1.F, 0.F }, { 0.F, 0.F, 0.F, 1.F } };
 static const OPENGL_ZCLIP myDefaultZClip = { { Standard_True, 0.F }, { Standard_True, 1.F } };
 
@@ -54,10 +52,8 @@ static const GLdouble THE_IDENTITY_MATRIX[4][4] =
 
 OpenGl_View::OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext,
                           OpenGl_StateCounter*       theCounter)
-: mySurfaceDetail(Visual3d_TOD_NONE),
+: mySurfaceDetail(Visual3d_TOD_ALL),
   myBackfacing(0),
-  myBgTexture(myDefaultBgTexture),
-  myBgGradient(myDefaultBgGradient),
   //shield_indicator = TOn,
   //shield_colour = { { 0.F, 0.F, 0.F, 1.F } },
   //border_indicator = TOff,
@@ -66,8 +62,8 @@ OpenGl_View::OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext,
   myZClip(myDefaultZClip),
   myCamera(AContext.Camera),
   myFog(myDefaultFog),
-  myTrihedron(NULL),
-  myGraduatedTrihedron(NULL),
+  myToShowTrihedron (false),
+  myToShowGradTrihedron (false),
   myVisualization(AContext.Visualization),
   myShadingModel ((Visual3d_TypeOfModel )AContext.Model),
   myAntiAliasing(Standard_False),
@@ -76,42 +72,55 @@ OpenGl_View::OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext,
   myProjectionState (0),
   myModelViewState (0),
   myStateCounter (theCounter),
-  myLastLightSourceState (0, 0)
+  myLastLightSourceState (0, 0),
+  myTextureParams   (new OpenGl_AspectFace()),
+  myBgGradientArray (new OpenGl_BackgroundArray (Graphic3d_TOB_GRADIENT)),
+  myBgTextureArray  (new OpenGl_BackgroundArray (Graphic3d_TOB_TEXTURE)),
+  // ray-tracing fields initialization
+  myRaytraceInitStatus (OpenGl_RT_NONE),
+  myIsRaytraceDataValid (Standard_False),
+  myIsRaytraceWarnTextures (Standard_False),
+  myToUpdateEnvironmentMap (Standard_False),
+  myLayersModificationStatus (0)
 {
   myCurrLightSourceState = myStateCounter->Increment();
-  myModificationState = 1; // initial state
 }
 
 /*----------------------------------------------------------------------*/
 
-OpenGl_View::~OpenGl_View ()
+OpenGl_View::~OpenGl_View()
 {
   ReleaseGlResources (NULL); // ensure ReleaseGlResources() was called within valid context
-  OpenGl_Element::Destroy (NULL, myTrihedron);
-  OpenGl_Element::Destroy (NULL, myGraduatedTrihedron);
+  OpenGl_Element::Destroy (NULL, myBgGradientArray);
+  OpenGl_Element::Destroy (NULL, myBgTextureArray);
+  OpenGl_Element::Destroy (NULL, myTextureParams);
 }
 
 void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx)
 {
-  if (myTrihedron != NULL)
-  {
-    myTrihedron->Release (theCtx.operator->());
-  }
-  if (myGraduatedTrihedron != NULL)
-  {
-    myGraduatedTrihedron->Release (theCtx.operator->());
-  }
+  myTrihedron         .Release (theCtx.operator->());
+  myGraduatedTrihedron.Release (theCtx.operator->());
 
   if (!myTextureEnv.IsNull())
   {
     theCtx->DelayedRelease (myTextureEnv);
     myTextureEnv.Nullify();
   }
-  if (myBgTexture.TexId != 0)
+
+  if (myTextureParams != NULL)
+  {
+    myTextureParams->Release (theCtx.operator->());
+  }
+  if (myBgGradientArray != NULL)
   {
-    glDeleteTextures (1, (GLuint*)&(myBgTexture.TexId));
-    myBgTexture.TexId = 0;
+    myBgGradientArray->Release (theCtx.operator->());
   }
+  if (myBgTextureArray != NULL)
+  {
+    myBgTextureArray->Release (theCtx.operator->());
+  }
+
+  releaseRaytraceResources (theCtx);
 }
 
 void OpenGl_View::SetTextureEnv (const Handle(OpenGl_Context)&       theCtx,
@@ -133,14 +142,14 @@ void OpenGl_View::SetTextureEnv (const Handle(OpenGl_Context)&       theCtx,
   if (!anImage.IsNull())
     myTextureEnv->Init (theCtx, *anImage.operator->(), theTexture->Type());
 
-  myModificationState++;
+  myToUpdateEnvironmentMap = Standard_True;
 }
 
 void OpenGl_View::SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail theMode)
 {
   mySurfaceDetail = theMode;
 
-  myModificationState++;
+  myToUpdateEnvironmentMap = Standard_True;
 }
 
 // =======================================================================
@@ -212,37 +221,41 @@ void OpenGl_View::SetFog (const Graphic3d_CView& theCView,
 
 /*----------------------------------------------------------------------*/
 
-void OpenGl_View::TriedronDisplay (const Handle(OpenGl_Context)&       theCtx,
-                                   const Aspect_TypeOfTriedronPosition thePosition,
+void OpenGl_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition,
                                    const Quantity_NameOfColor          theColor,
                                    const Standard_Real                 theScale,
                                    const Standard_Boolean              theAsWireframe)
 {
-  OpenGl_Element::Destroy (theCtx.operator->(), myTrihedron);
-  myTrihedron = new OpenGl_Trihedron (thePosition, theColor, theScale, theAsWireframe);
+  myToShowTrihedron = true;
+  myTrihedron.SetWireframe   (theAsWireframe);
+  myTrihedron.SetPosition    (thePosition);
+  myTrihedron.SetScale       (theScale);
+  myTrihedron.SetLabelsColor (theColor);
 }
 
 /*----------------------------------------------------------------------*/
 
 void OpenGl_View::TriedronErase (const Handle(OpenGl_Context)& theCtx)
 {
-  OpenGl_Element::Destroy (theCtx.operator->(), myTrihedron);
+  myToShowTrihedron = false;
+  myTrihedron.Release (theCtx.operator->());
 }
 
 /*----------------------------------------------------------------------*/
 
-void OpenGl_View::GraduatedTrihedronDisplay (const Handle(OpenGl_Context)&        theCtx,
-                                             const Graphic3d_CGraduatedTrihedron& theData)
+void OpenGl_View::GraduatedTrihedronDisplay (const Handle(OpenGl_Context)&       theCtx,
+                                             const Graphic3d_GraduatedTrihedron& theData)
 {
-  OpenGl_Element::Destroy (theCtx.operator->(), myGraduatedTrihedron);
-  myGraduatedTrihedron = new OpenGl_GraduatedTrihedron (theData);
+  myToShowGradTrihedron = true;
+  myGraduatedTrihedron.SetValues (theCtx, theData);
 }
 
 /*----------------------------------------------------------------------*/
 
 void OpenGl_View::GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx)
 {
-  OpenGl_Element::Destroy (theCtx.operator->(), myGraduatedTrihedron);
+  myToShowGradTrihedron = false;
+  myGraduatedTrihedron.Release (theCtx.operator->());
 }
 
 /*----------------------------------------------------------------------*/
@@ -308,7 +321,7 @@ const TEL_TRANSFORM_PERSISTENCE* OpenGl_View::BeginTransformPersistence (const H
                                           aModelMatrix,
                                           aProjMatrix,
                                           aViewport,
-                                          aWinZ,
+                                          aWinX,
                                           aWinY,
                                           aWinZ);
   }