0024437: Visualization - silhouette edges based on OpenGL
[occt.git] / src / OpenGl / OpenGl_SetOfShaderPrograms.hxx
index f04c547..e82b785 100644 (file)
 //! Standard GLSL program combination bits.
 enum OpenGl_ProgramOptions
 {
-  OpenGl_PO_Point       = 0x001, //!< point marker
-  OpenGl_PO_VertColor   = 0x002, //!< per-vertex color
-  OpenGl_PO_TextureRGB  = 0x004, //!< handle RGB   texturing
-  OpenGl_PO_TextureA    = 0x008, //!< handle Alpha texturing
-  OpenGl_PO_TextureEnv  = 0x010, //!< handle environment map
-  OpenGl_PO_StippleLine = 0x020, //!< stipple line
-  OpenGl_PO_ClipPlanes1 = 0x040, //!< handle 1 clipping plane
-  OpenGl_PO_ClipPlanes2 = 0x080, //!< handle 2 clipping planes
-  OpenGl_PO_ClipPlanesN = 0x100, //!< handle N clipping planes
-  OpenGl_PO_AlphaTest   = 0x200, //!< discard fragment by alpha test (defined by cutoff value)
-  OpenGl_PO_WriteOit    = 0x400, //!< write coverage buffer for Blended Order-Independent Transparency
-  OpenGl_PO_NB          = 0x800  //!< overall number of combinations
+  OpenGl_PO_Point           = 0x0001, //!< point marker
+  OpenGl_PO_VertColor       = 0x0002, //!< per-vertex color
+  OpenGl_PO_TextureRGB      = 0x0004, //!< handle RGB   texturing
+  OpenGl_PO_TextureA        = 0x0008, //!< handle Alpha texturing (point sprites only)
+  OpenGl_PO_TextureEnv      = 0x0010, //!< handle environment map
+  OpenGl_PO_StippleLine     = 0x0020, //!< stipple line
+  OpenGl_PO_ClipPlanes1     = 0x0040, //!< handle 1 clipping plane
+  OpenGl_PO_ClipPlanes2     = 0x0080, //!< handle 2 clipping planes
+  OpenGl_PO_ClipPlanesN     = OpenGl_PO_ClipPlanes1|OpenGl_PO_ClipPlanes2, //!< handle N clipping planes
+  OpenGl_PO_ClipChains      = 0x0100, //!< handle chains of clipping planes
+  OpenGl_PO_MeshEdges       = 0x0200, //!< draw mesh edges (wireframe)
+  OpenGl_PO_AlphaTest       = 0x0400, //!< discard fragment by alpha test (defined by cutoff value)
+  OpenGl_PO_WriteOit        = 0x0800, //!< write coverage buffer for Blended Order-Independent Transparency
+  //
+  OpenGl_PO_NB              = 0x1000, //!< overall number of combinations
+  OpenGl_PO_HasTextures     = OpenGl_PO_TextureRGB|OpenGl_PO_TextureA,
+  OpenGl_PO_NeedsGeomShader = OpenGl_PO_MeshEdges,
 };
 
 //! Alias to programs array of predefined length
+class OpenGl_SetOfPrograms : public Standard_Transient
+{
+  DEFINE_STANDARD_RTTI_INLINE(OpenGl_SetOfPrograms, Standard_Transient)
+public:
+
+  //! Empty constructor
+  OpenGl_SetOfPrograms() {}
+
+  //! Access program by index
+  Handle(OpenGl_ShaderProgram)& ChangeValue (Standard_Integer theProgramBits) { return myPrograms[theProgramBits]; }
+
+protected:
+  Handle(OpenGl_ShaderProgram) myPrograms[OpenGl_PO_NB]; //!< programs array
+};
+
+//! Alias to 2D programs array of predefined length
 class OpenGl_SetOfShaderPrograms : public Standard_Transient
 {
   DEFINE_STANDARD_RTTI_INLINE(OpenGl_SetOfShaderPrograms, Standard_Transient)
@@ -46,19 +67,31 @@ public:
   //! Empty constructor
   OpenGl_SetOfShaderPrograms() {}
 
+  //! Constructor
+  OpenGl_SetOfShaderPrograms (const Handle(OpenGl_SetOfPrograms)& thePrograms)
+  {
+    for (Standard_Integer aSetIter = 0; aSetIter < Graphic3d_TypeOfShadingModel_NB - 1; ++aSetIter)
+    {
+      myPrograms[aSetIter] = thePrograms;
+    }
+  }
+
   //! Access program by index
   Handle(OpenGl_ShaderProgram)& ChangeValue (Graphic3d_TypeOfShadingModel theShadingModel,
                                              Standard_Integer theProgramBits)
   {
-    return myPrograms[theShadingModel][theProgramBits];
+    Handle(OpenGl_SetOfPrograms)& aSet = myPrograms[theShadingModel - 1];
+    if (aSet.IsNull())
+    {
+      aSet = new OpenGl_SetOfPrograms();
+    }
+    return aSet->ChangeValue (theProgramBits);
   }
 
 protected:
-  Handle(OpenGl_ShaderProgram) myPrograms[Graphic3d_TypeOfShadingModel_NB][OpenGl_PO_NB]; //!< programs array
+  Handle(OpenGl_SetOfPrograms) myPrograms[Graphic3d_TypeOfShadingModel_NB - 1]; //!< programs array, excluding Graphic3d_TOSM_UNLIT
 };
 
-DEFINE_STANDARD_HANDLE(OpenGl_SetOfShaderPrograms, Standard_Transient)
-
 typedef NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_SetOfShaderPrograms)> OpenGl_MapOfShaderPrograms;
 
 #endif // _OpenGl_SetOfShaderPrograms_HeaderFile