0023028: Visualization, TKOpenGl - eliminate global static variables
authorisk <isk@opencascade.com>
Mon, 22 Jun 2015 12:01:37 +0000 (15:01 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 25 Jun 2015 12:06:24 +0000 (15:06 +0300)
OpenGl_CappingAlgo - move global variables to OpenGl_Workspace class fields.
OpenGl_View::ShaderSource::Source() - drop static for local variable.
OpenGl_Window - drop redundant global constant THE_DEFAULT_BG_COLOR.

12 files changed:
src/OpenGl/OpenGl_CappingAlgo.cxx
src/OpenGl/OpenGl_CappingAlgo.hxx
src/OpenGl/OpenGl_CappingPlaneResource.cxx
src/OpenGl/OpenGl_GraphicDriver_Layer.cxx
src/OpenGl/OpenGl_Matrix.cxx
src/OpenGl/OpenGl_Matrix.hxx
src/OpenGl/OpenGl_View.cxx
src/OpenGl/OpenGl_View_Raytrace.cxx
src/OpenGl/OpenGl_Window.cxx
src/OpenGl/OpenGl_Window_1.mm
src/OpenGl/OpenGl_Workspace.cxx
src/OpenGl/OpenGl_Workspace.hxx

index cb94604..3840d35 100755 (executable)
 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;
-
 namespace
 {
-
 #if !defined(GL_ES_VERSION_2_0)
   static const GLint THE_FILLPRIM_FROM = GL_TRIANGLES;
   static const GLint THE_FILLPRIM_TO   = GL_POLYGON;
@@ -70,16 +64,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);
@@ -113,7 +103,7 @@ void OpenGl_CappingAlgo::RenderCapping (const Handle(OpenGl_Workspace)&  theWork
     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
@@ -131,7 +121,7 @@ void OpenGl_CappingAlgo::RenderCapping (const Handle(OpenGl_Workspace)&  theWork
     }
 
     // override material, cull back faces
-    theWorkspace->SetAspectFace (FrontCulling());
+    theWorkspace->SetAspectFace (&theWorkspace->FrontCulling());
     theWorkspace->AspectFace (Standard_True);
 
     // enable all clip plane except the rendered one
@@ -215,25 +205,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  :
index d45e9af..1df476b 100755 (executable)
@@ -45,27 +45,6 @@ public:
   //! @param thePlane [in] the graphical plane, for which the capping surface is rendered.
   Standard_EXPORT static void RenderPlane (const Handle(OpenGl_Workspace)& theWorkspace,
                                            const Handle(Graphic3d_ClipPlane)& thePlane);
-
-private:
-
-  //! Init algorithm.
-  static void Init();
-
-  //! @return capping algorithm rendering filter.
-  static const Handle(OpenGl_RenderFilter)& CappingFilter() { return myRenderFilter; }
-
-  //! @return face aspect for front face culling mode.
-  static const OpenGl_AspectFace* FrontCulling() { return &myFrontCulling; }
-
-  //! @return face aspect for none culling mode.
-  static const OpenGl_AspectFace* NoneCulling() { return &myNoneCulling; }
-
-private:
-
-  static Handle(OpenGl_RenderFilter) myRenderFilter;
-  static OpenGl_AspectFace myFrontCulling;
-  static OpenGl_AspectFace myNoneCulling;
-  static Standard_Boolean myIsInit;
 };
 
 //! Graphical capping rendering algorithm filter.
index 3691beb..fe48301 100755 (executable)
@@ -43,6 +43,16 @@ namespace
     0.0f, 0.0f,-1.0f, 0.0f,  0.0f, 1.0f, 0.0f, 0.0f,   0.0f, 1.0f, 0.0f, 0.0f,
     1.0f, 0.0f, 0.0f, 0.0f,  0.0f, 1.0f, 0.0f, 0.0f,   1.0f, 0.0f, 0.0f, 0.0f
   };
+
+  static const OpenGl_Matrix OpenGl_IdentityMatrix =
+  {
+    // mat[4][4]
+    { { 1.0f, 0.0f, 0.0f, 0.0f },
+      { 0.0f, 1.0f, 0.0f, 0.0f },
+      { 0.0f, 0.0f, 1.0f, 0.0f },
+      { 0.0f, 0.0f, 0.0f, 1.0f } }
+  };
+
 }
 
 IMPLEMENT_STANDARD_HANDLE (OpenGl_CappingPlaneResource, OpenGl_Resource)
index be0389e..1180d47 100644 (file)
@@ -40,25 +40,28 @@ struct OpenGl_LAYER_PROP
 
 /*----------------------------------------------------------------------*/
 
-static const TEL_COLOUR myDefaultColor = {{ 1.F, 1.F, 1.F, 1.F }};
-static const CALL_DEF_CONTEXTTEXT myDefaultContextText =
+namespace
 {
-  1, //IsDef
-  1, //IsSet
-  "Courier", //Font
-  0.3F, //Space
-  1.F, //Expan
-  { 1.F, 1.F, 1.F }, //Color
-  (int)Aspect_TOST_NORMAL, //Style
-  (int)Aspect_TODT_NORMAL, //DisplayType
-  { 1.F, 1.F, 1.F }, //ColorSubTitle
-  0, //TextZoomable
-  0.F, //TextAngle
-  (int)Font_FA_Regular //TextFontAspect
-};
-
-static Standard_Boolean TheLayerIsOpen = Standard_False;
-static OpenGl_LAYER_PROP TheLayerProp;
+  static const TEL_COLOUR myDefaultColor = {{ 1.F, 1.F, 1.F, 1.F }};
+  static const CALL_DEF_CONTEXTTEXT myDefaultContextText =
+  {
+    1, //IsDef
+    1, //IsSet
+    "Courier", //Font
+    0.3F, //Space
+    1.F, //Expan
+    { 1.F, 1.F, 1.F }, //Color
+    (int)Aspect_TOST_NORMAL, //Style
+    (int)Aspect_TODT_NORMAL, //DisplayType
+    { 1.F, 1.F, 1.F }, //ColorSubTitle
+    0, //TextZoomable
+    0.F, //TextAngle
+    (int)Font_FA_Regular //TextFontAspect
+  };
+
+  static Standard_Boolean TheLayerIsOpen = Standard_False;
+  static OpenGl_LAYER_PROP TheLayerProp;
+}
 
 /*----------------------------------------------------------------------*/
 
index 945e66f..877b722 100644 (file)
 
 /*----------------------------------------------------------------------*/
 
-void OpenGl_Multiplymat3 (OpenGl_Matrix *c, const OpenGl_Matrix *a, const OpenGl_Matrix *b)
-{
-  int row, col, i;
-  for (row = 0; row < 4; row++) {
-    for (col = 0; col < 4; col++) {
-      float sum = 0.F;
-      for (i = 0; i < 4; i++)
-        sum += a->mat[row][i] * b->mat[i][col];
-      c->mat[row][col] = sum;
-    }
-  }
-}
-
-/*----------------------------------------------------------------------*/
-
 void OpenGl_Transposemat3 (OpenGl_Matrix *c, const OpenGl_Matrix *a)
 {
   Tint row, col;
index 35bd424..e92da57 100644 (file)
@@ -24,16 +24,6 @@ struct OpenGl_Matrix
   DEFINE_STANDARD_ALLOC
 };
 
-Standard_EXPORT void OpenGl_Multiplymat3 (OpenGl_Matrix *c, const OpenGl_Matrix *a, const OpenGl_Matrix *b);
 Standard_EXPORT void OpenGl_Transposemat3 (OpenGl_Matrix *c, const OpenGl_Matrix *a);
 
-static const OpenGl_Matrix OpenGl_IdentityMatrix =
-{
-  // mat[4][4]
-  { { 1.0f, 0.0f, 0.0f, 0.0f },
-    { 0.0f, 1.0f, 0.0f, 0.0f },
-    { 0.0f, 0.0f, 1.0f, 0.0f },
-    { 0.0f, 0.0f, 0.0f, 1.0f } }
-};
-
 #endif //OpenGl_Matrix_Header
index d293880..e1a5655 100644 (file)
@@ -35,18 +35,21 @@ IMPLEMENT_STANDARD_RTTIEXT(OpenGl_View,MMgt_TShared)
 
 /*----------------------------------------------------------------------*/
 
-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 } };
-
-static const OPENGL_FOG myDefaultFog = { Standard_False, 0.F, 1.F, { { 0.F, 0.F, 0.F, 1.F } } };
-static const TEL_TRANSFORM_PERSISTENCE myDefaultTransPers = { 0, 0.F, 0.F, 0.F };
-static const GLdouble THE_IDENTITY_MATRIX[4][4] =
+namespace
 {
-  {1.0, 0.0, 0.0, 0.0},
-  {0.0, 1.0, 0.0, 0.0},
-  {0.0, 0.0, 1.0, 0.0},
-  {0.0, 0.0, 0.0, 1.0}
-};
+  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 } };
+
+  static const OPENGL_FOG myDefaultFog = { Standard_False, 0.F, 1.F, { { 0.F, 0.F, 0.F, 1.F } } };
+  static const TEL_TRANSFORM_PERSISTENCE myDefaultTransPers = { 0, 0.F, 0.F, 0.F };
+  static const GLdouble THE_IDENTITY_MATRIX[4][4] =
+  {
+    {1.0, 0.0, 0.0, 0.0},
+    {0.0, 1.0, 0.0, 0.0},
+    {0.0, 0.0, 1.0, 0.0},
+    {0.0, 0.0, 0.0, 1.0}
+  };
+}
 
 /*----------------------------------------------------------------------*/
 
index 52e2a5b..d5923c5 100644 (file)
@@ -999,7 +999,7 @@ const TCollection_AsciiString OpenGl_View::ShaderSource::EMPTY_PREFIX;
 // =======================================================================
 TCollection_AsciiString OpenGl_View::ShaderSource::Source() const
 {
-  static const TCollection_AsciiString aVersion = "#version 140";
+  const TCollection_AsciiString aVersion = "#version 140";
 
   if (myPrefix.IsEmpty())
   {
@@ -2591,4 +2591,4 @@ Standard_Boolean OpenGl_View::raytrace (const Graphic3d_CView&        theCView,
   glEnable (GL_DEPTH_TEST);
 
   return Standard_True;
-}
\ No newline at end of file
+}
index 785559c..e91bce0 100644 (file)
@@ -36,7 +36,6 @@ IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Window,MMgt_TShared)
 
 namespace
 {
-  static const TEL_COLOUR THE_DEFAULT_BG_COLOR = { { 0.F, 0.F, 0.F, 1.F } };
 
 #if defined(HAVE_EGL) || defined(__ANDROID__)
   //
@@ -141,12 +140,12 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
   myOwnGContext (theGContext == 0),
   myWidth   (theCWindow.dx),
   myHeight  (theCWindow.dy),
-  myBgColor (THE_DEFAULT_BG_COLOR),
   mySwapInterval (theCaps->swapInterval)
 {
   myBgColor.rgb[0] = theCWindow.Background.r;
   myBgColor.rgb[1] = theCWindow.Background.g;
   myBgColor.rgb[2] = theCWindow.Background.b;
+  myBgColor.rgb[3] = 1.0f;
 
   Standard_Boolean isCoreProfile = Standard_False;
 
index a9386ea..41e692a 100644 (file)
   #include <OpenGL/CGLRenderers.h>
 #endif
 
-namespace
-{
-  static const TEL_COLOUR THE_DEFAULT_BG_COLOR = { { 0.F, 0.F, 0.F, 1.F } };
-}
-
 // =======================================================================
 // function : OpenGl_Window
 // purpose  :
@@ -74,12 +69,12 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
 #endif
   myWidth    (theCWindow.dx),
   myHeight   (theCWindow.dy),
-  myBgColor (THE_DEFAULT_BG_COLOR),
   mySwapInterval (theCaps->swapInterval)
 {
   myBgColor.rgb[0] = theCWindow.Background.r;
   myBgColor.rgb[1] = theCWindow.Background.g;
   myBgColor.rgb[2] = theCWindow.Background.b;
+  myBgColor.rgb[3] = 1.0f;
 
 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
   EAGLContext* aGLContext = theGContext;
index c9177ef..f5a0f25 100644 (file)
@@ -214,6 +214,12 @@ OpenGl_Workspace::OpenGl_Workspace (const Handle(OpenGl_GraphicDriver)& theDrive
     int v;
     if (sscanf (anAaEnv, "%d", &v) > 0) myAntiAliasingMode = v;
   }
+
+  myDefaultCappingAlgoFilter         = new OpenGl_CappingAlgoFilter();
+  myNoneCulling.ChangeCullingMode()  = TelCullNone;
+  myNoneCulling.ChangeEdge()         = 0;
+  myFrontCulling.ChangeCullingMode() = TelCullBack;
+  myFrontCulling.ChangeEdge()        = 0;
 }
 
 // =======================================================================
index 4a40ebc..7f7b0e4 100644 (file)
@@ -51,6 +51,7 @@
 #include <OpenGl_RenderFilter.hxx>
 #include <OpenGl_Vec.hxx>
 #include <OpenGl_LineAttributes.hxx>
+#include <OpenGl_CappingAlgo.hxx>
 
 #include <Handle_OpenGl_View.hxx>
 #include <Handle_OpenGl_Texture.hxx>
@@ -274,6 +275,24 @@ public:
   //! @return true if clipping algorithm enabled
   inline Standard_Boolean IsCullingEnabled() const { return myIsCullingEnabled; }
 
+  //! Returns capping algorithm rendering filter.
+  const Handle(OpenGl_CappingAlgoFilter)& DefaultCappingAlgoFilter() const
+  {
+    return myDefaultCappingAlgoFilter;
+  }
+
+  //! Returns face aspect for none culling mode.
+  const OpenGl_AspectFace& NoneCulling() const
+  {
+    return myNoneCulling;
+  }
+
+  //! Returns face aspect for front face culling mode.
+  const OpenGl_AspectFace& FrontCulling() const
+  {
+    return myFrontCulling;
+  }
+
 protected:
 
   //! Copy content of Back buffer to the Front buffer
@@ -346,6 +365,10 @@ protected: //! @name protected fields
 
   unsigned int           myFrameCounter;         //!< redraw counter, for debugging
 
+  Handle(OpenGl_CappingAlgoFilter) myDefaultCappingAlgoFilter;
+  OpenGl_AspectFace                myNoneCulling;
+  OpenGl_AspectFace                myFrontCulling;
+
 protected: //! @name fields related to status
 
   Handle(OpenGl_RenderFilter) myRenderFilter;