0027961: Visualization - remove unused and no more working OpenGl_AVIWriter
[occt.git] / src / OpenGl / OpenGl_LineAttributes.cxx
index 3ac75e4..1d58616 100644 (file)
 #include <OpenGl_LineAttributes.hxx>
 #include <OpenGl_Context.hxx>
 
+IMPLEMENT_STANDARD_RTTIEXT(OpenGl_LineAttributes,OpenGl_Resource)
+
 static const unsigned int myInteriors[TEL_HS_USER_DEF_START][32] =
 {
-  //TEL_HS_SOLID
+  // Aspect_HS_SOLID
   {
     0xFFFFFFFF,
     0xFFFFFFFF,
@@ -55,7 +57,7 @@ static const unsigned int myInteriors[TEL_HS_USER_DEF_START][32] =
     0xFFFFFFFF,
     0xFFFFFFFF
   },
-  //TEL_HS_CROSS
+  // Aspect_HS_GRID_DIAGONAL
   {
     0xFFFFFFFF,
     0xBBBBBBBB,
@@ -90,7 +92,7 @@ static const unsigned int myInteriors[TEL_HS_USER_DEF_START][32] =
     0xEEEEEEEE,
     0xBBBBBBBB
   },
-  //TEL_HS_CROSS_SPARSE
+  // Aspect_HS_GRID_DIAGONAL_WIDE
   {
     0x81818181,
     0x24242424,
@@ -125,7 +127,7 @@ static const unsigned int myInteriors[TEL_HS_USER_DEF_START][32] =
     0x18181818,
     0x42424242
   },
-  //TEL_HS_GRID
+  // Aspect_HS_GRID
   {
     0xFFFFFFFF,
     0x88888888,
@@ -160,7 +162,7 @@ static const unsigned int myInteriors[TEL_HS_USER_DEF_START][32] =
     0xFFFFFFFF,
     0x88888888
   },
-  //TEL_HS_GRID_SPARSE
+  // Aspect_HS_GRID_WIDE
   {
     0xFFFFFFFF,
     0x80808080,
@@ -195,7 +197,7 @@ static const unsigned int myInteriors[TEL_HS_USER_DEF_START][32] =
     0x80808080,
     0x80808080
   },
-  //TEL_HS_DIAG_45
+  // Aspect_HS_DIAGONAL_45
   {
     0x88888888,
     0x22222222,
@@ -230,7 +232,7 @@ static const unsigned int myInteriors[TEL_HS_USER_DEF_START][32] =
     0x88888888,
     0x22222222
   },
-  //TEL_HS_DIAG_135
+  // Aspect_HS_DIAGONAL_135
   {
     0x11111111,
     0x44444444,
@@ -265,7 +267,7 @@ static const unsigned int myInteriors[TEL_HS_USER_DEF_START][32] =
     0x11111111,
     0x44444444
   },
-  //TEL_HS_HORIZONTAL
+  // Aspect_HS_HORIZONTAL
   {
     0xFFFFFFFF,
     0x00000000,
@@ -300,7 +302,7 @@ static const unsigned int myInteriors[TEL_HS_USER_DEF_START][32] =
     0xFFFFFFFF,
     0x00000000
   },
-  //TEL_HS_VERTICAL
+  // Aspect_HS_VERTICAL
   {
     0x11111111,
     0x11111111,
@@ -335,7 +337,7 @@ static const unsigned int myInteriors[TEL_HS_USER_DEF_START][32] =
     0x11111111,
     0x11111111
   },
-  //TEL_HS_DIAG_45_SPARSE
+  // Aspect_HS_DIAGONAL_45_WIDE
   {
     0x80808080,
     0x20202020,
@@ -370,7 +372,7 @@ static const unsigned int myInteriors[TEL_HS_USER_DEF_START][32] =
     0x08080808,
     0x02020202
   },
-  //TEL_HS_DIAG_135_SPARSE
+  // Aspect_HS_DIAGONAL_135_WIDE
   {
     0x01010101,
     0x04040404,
@@ -405,7 +407,7 @@ static const unsigned int myInteriors[TEL_HS_USER_DEF_START][32] =
     0x10101010,
     0x40404040
   },
-  //TEL_HS_HORIZONTAL_SPARSE
+  // Aspect_HS_HORIZONTAL_WIDE
   {
     0xFFFFFFFF,
     0x00000000,
@@ -440,7 +442,7 @@ static const unsigned int myInteriors[TEL_HS_USER_DEF_START][32] =
     0x00000000,
     0x00000000
   },
-  //TEL_HS_VERTICAL_SPARSE
+  // Aspect_HS_VERTICAL_WIDE
   {
     0x10101010,
     0x10101010,
@@ -477,13 +479,14 @@ static const unsigned int myInteriors[TEL_HS_USER_DEF_START][32] =
   }
 };
 
-
 // =======================================================================
 // function : OpenGl_LineAttributes
 // purpose  :
 // =======================================================================
 OpenGl_LineAttributes::OpenGl_LineAttributes()
-: myPatternBase(0)
+: myPatternBase (0),
+  myTypeOfHatch (0),
+  myIsEnabled (true)
 {
   //
 }
@@ -506,12 +509,14 @@ void OpenGl_LineAttributes::Release (OpenGl_Context* theGlCtx)
   // Delete surface patterns
   if (myPatternBase != 0)
   {
+#if !defined(GL_ES_VERSION_2_0)
     if (theGlCtx->IsValid())
     {
-    #if !defined(GL_ES_VERSION_2_0)
-      glDeleteLists ((GLuint )myPatternBase, TEL_HS_USER_DEF_START);
-    #endif
+      theGlCtx->core11->glDeleteLists ((GLuint )myPatternBase, TEL_HS_USER_DEF_START);
     }
+#else
+    (void )theGlCtx;
+#endif
     myPatternBase = 0;
   }
 }
@@ -520,7 +525,7 @@ void OpenGl_LineAttributes::Release (OpenGl_Context* theGlCtx)
 // function : Init
 // purpose  :
 // =======================================================================
-void OpenGl_LineAttributes::Init (const Handle(OpenGl_Context)& theGlCtx)
+void OpenGl_LineAttributes::Init (const OpenGl_Context* theGlCtx)
 {
   // Return if already initialized
   if (myPatternBase != 0)
@@ -539,10 +544,12 @@ void OpenGl_LineAttributes::Init (const Handle(OpenGl_Context)& theGlCtx)
   myPatternBase = glGenLists(TEL_HS_USER_DEF_START);
   for (int i = 1; i < TEL_HS_USER_DEF_START; i++)
   {
-    glNewList ((GLuint )myPatternBase + i, GL_COMPILE);
-    glPolygonStipple ((const GLubyte* )myInteriors[i < nbi ? i : 0]);
-    glEndList();
+    theGlCtx->core11->glNewList ((GLuint )myPatternBase + i, GL_COMPILE);
+    theGlCtx->core11->glPolygonStipple ((const GLubyte* )myInteriors[i < nbi ? i : 0]);
+    theGlCtx->core11->glEndList();
   }
+#else
+  (void )theGlCtx;
 #endif
 }
 
@@ -550,20 +557,69 @@ void OpenGl_LineAttributes::Init (const Handle(OpenGl_Context)& theGlCtx)
 // function : SetTypeOfHatch
 // purpose  :
 // =======================================================================
-void OpenGl_LineAttributes::SetTypeOfHatch (const int theType) const
+int OpenGl_LineAttributes::SetTypeOfHatch (const OpenGl_Context* theGlCtx, const int theType)
 {
-#if !defined(GL_ES_VERSION_2_0)
+  // Return if not initialized
   if (myPatternBase == 0)
   {
-    return;
+    return 0;
   }
 
+  const int anOldType = myTypeOfHatch;
+
+#if !defined(GL_ES_VERSION_2_0)
   if (theType != 0)
   {
-    glCallList ((GLuint )myPatternBase + (GLuint )theType);
-    glEnable (GL_POLYGON_STIPPLE);
+    theGlCtx->core11->glCallList ((GLuint )myPatternBase + (GLuint )theType);
+
+    if (myIsEnabled)
+    {
+      theGlCtx->core11fwd->glEnable (GL_POLYGON_STIPPLE);
+    }
   }
   else
-    glDisable (GL_POLYGON_STIPPLE);
+  {
+    theGlCtx->core11fwd->glDisable (GL_POLYGON_STIPPLE);
+  }
+#else
+  (void )theGlCtx;
 #endif
+  myTypeOfHatch = theType;
+
+  return anOldType;
+}
+
+// =======================================================================
+// function : SetEnabled
+// purpose  :
+// =======================================================================
+bool OpenGl_LineAttributes::SetEnabled (const OpenGl_Context* theGlCtx,
+                                        const bool theToEnable)
+{
+  // Return if not initialized
+  if (myPatternBase == 0)
+  {
+    return false;
+  }
+
+  const bool anOldIsEnabled = myIsEnabled;
+
+#if !defined(GL_ES_VERSION_2_0)
+  if (theToEnable)
+  {
+    if (myTypeOfHatch != 0)
+    {
+      theGlCtx->core11fwd->glEnable (GL_POLYGON_STIPPLE);
+    }
+  }
+  else
+  {
+    theGlCtx->core11fwd->glDisable (GL_POLYGON_STIPPLE);
+  }
+#else
+  (void )theGlCtx;
+#endif
+  myIsEnabled = theToEnable;
+
+  return anOldIsEnabled;
 }