0027925: Visualization - implement order-independent transparency algorithm within...
[occt.git] / src / OpenGl / OpenGl_Workspace.hxx
index 7e40713..9086b01 100644 (file)
 #include <OpenGl_AspectFace.hxx>
 #include <OpenGl_CappingAlgo.hxx>
 #include <OpenGl_FrameBuffer.hxx>
-#include <OpenGl_LineAttributes.hxx>
+#include <OpenGl_Material.hxx>
 #include <OpenGl_Matrix.hxx>
-#include <OpenGl_NamedStatus.hxx>
-#include <OpenGl_PrinterContext.hxx>
 #include <OpenGl_RenderFilter.hxx>
 #include <OpenGl_ShaderObject.hxx>
 #include <OpenGl_ShaderProgram.hxx>
 class OpenGl_View;
 class Image_PixMap;
 
-//! OpenGL material definition
-struct OpenGl_Material
-{
-
-  OpenGl_Vec4 Ambient;  //!< ambient reflection coefficient
-  OpenGl_Vec4 Diffuse;  //!< diffuse reflection coefficient
-  OpenGl_Vec4 Specular; //!< glossy  reflection coefficient
-  OpenGl_Vec4 Emission; //!< material emission
-  OpenGl_Vec4 Params;   //!< extra packed parameters
-
-  Standard_ShortReal  Shine()              const { return Params.x(); }
-  Standard_ShortReal& ChangeShine()              { return Params.x(); }
-
-  Standard_ShortReal  Transparency()       const { return Params.y(); }
-  Standard_ShortReal& ChangeTransparency()       { return Params.y(); }
-
-  //! Set material color.
-  void SetColor (const OpenGl_Vec4& theColor)
-  {
-    // apply the same formula as in Graphic3d_MaterialAspect::SetColor()
-    Ambient.xyz() = theColor.rgb() * 0.25f;
-    Diffuse.xyz() = theColor.rgb();
-  }
-
-  //! Initialize material
-  void Init (const Graphic3d_MaterialAspect& theProp,
-             const Quantity_Color&           theInteriorColor);
-
-  //! Returns packed (serialized) representation of material properties
-  const OpenGl_Vec4* Packed() const { return reinterpret_cast<const OpenGl_Vec4*> (this); }
-  static Standard_Integer NbOfVec4() { return 5; }
-
-};
-
 class OpenGl_RaytraceFilter;
 DEFINE_STANDARD_HANDLE (OpenGl_RaytraceFilter, OpenGl_RenderFilter)
 
@@ -97,7 +61,8 @@ public:
   //! Checks whether the element can be rendered or not.
   //! @param theElement [in] the element to check.
   //! @return True if element can be rendered.
-  virtual Standard_Boolean CanRender (const OpenGl_Element* theElement) Standard_OVERRIDE;
+  virtual Standard_Boolean ShouldRender (const Handle(OpenGl_Workspace)& theWorkspace,
+                                         const OpenGl_Element*           theElement) Standard_OVERRIDE;
 
 private:
 
@@ -121,7 +86,7 @@ public:
   Standard_EXPORT OpenGl_Workspace (OpenGl_View* theView, const Handle(OpenGl_Window)& theWindow);
 
   //! Destructor
-  Standard_EXPORT virtual ~OpenGl_Workspace();
+  virtual ~OpenGl_Workspace() {}
 
   //! Activate rendering context.
   Standard_EXPORT Standard_Boolean Activate();
@@ -151,26 +116,17 @@ public:
     return wasUsed;
   }
 
-  Handle(OpenGl_PrinterContext)& PrinterContext() { return myPrintContext; }
-
   //! @return true if usage of Z buffer is enabled.
   Standard_Boolean& UseZBuffer() { return myUseZBuffer; }
 
   //! @return true if depth writing is enabled.
   Standard_Boolean& UseDepthWrite() { return myUseDepthWrite; }
 
-  //! @return true if usage of GL light is enabled.
-  Standard_EXPORT Standard_Boolean  UseGLLight() const;
-
   //! @return true if clipping algorithm enabled
   Standard_EXPORT Standard_Boolean IsCullingEnabled() const;
 
-  Standard_Integer NamedStatus;
-
   //// RELATED TO STATUS ////
 
-  const OpenGl_Vec4* HighlightColor;
-
   //! Return true if active group might activate face culling (e.g. primitives are closed).
   bool ToAllowFaceCulling() const { return myToAllowFaceCulling; }
 
@@ -180,57 +136,60 @@ public:
   void SetAllowFaceCulling (bool theToAllow) { myToAllowFaceCulling = theToAllow; }
 
   //! Return true if following structures should apply highlight color.
-  bool ToHighlight() const { return myToHighlight; }
+  bool ToHighlight() const { return !myHighlightStyle.IsNull(); }
+
+  //! Return highlight style.
+  const Handle(Graphic3d_PresentationAttributes)& HighlightStyle() const { return myHighlightStyle; }
 
-  //! Set highlight.
-  void SetHighlight (bool theToHighlight) { myToHighlight = theToHighlight; }
+  //! Set highlight style.
+  void SetHighlightStyle (const Handle(Graphic3d_PresentationAttributes)& theStyle) {  myHighlightStyle = theStyle; }
 
   //! Return line color taking into account highlight flag.
   const OpenGl_Vec4& LineColor() const
   {
-    return myToHighlight
-         ? *HighlightColor
-         : myAspectLineSet->Aspect()->ColorRGBA();
+    return !myHighlightStyle.IsNull()
+         ?  myHighlightStyle->ColorRGBA()
+         :  myAspectLineSet->Aspect()->ColorRGBA();
   }
 
   //! Return edge color taking into account highlight flag.
   const OpenGl_Vec4& EdgeColor() const
   {
-    return myToHighlight
-         ? *HighlightColor
-         : myAspectFaceSet->AspectEdge()->Aspect()->ColorRGBA();
+    return !myHighlightStyle.IsNull()
+         ?  myHighlightStyle->ColorRGBA()
+         :  myAspectFaceSet->AspectEdge()->Aspect()->ColorRGBA();
   }
 
   //! Return marker color taking into account highlight flag.
   const OpenGl_Vec4& MarkerColor() const
   {
-    return myToHighlight
-         ? *HighlightColor
-         : myAspectMarkerSet->Aspect()->ColorRGBA();
+    return !myHighlightStyle.IsNull()
+         ?  myHighlightStyle->ColorRGBA()
+         :  myAspectMarkerSet->Aspect()->ColorRGBA();
   }
 
   //! Return Interior color taking into account highlight flag.
   const OpenGl_Vec4& InteriorColor() const
   {
-    return myToHighlight
-         ? *HighlightColor
-         : myAspectFaceSet->Aspect()->InteriorColorRGBA();
+    return !myHighlightStyle.IsNull()
+         ?  myHighlightStyle->ColorRGBA()
+         :  myAspectFaceSet->Aspect()->InteriorColorRGBA();
   }
 
   //! Return text color taking into account highlight flag.
   const OpenGl_Vec4& TextColor() const
   {
-    return myToHighlight
-         ? *HighlightColor
-         : myAspectTextSet->Aspect()->ColorRGBA();
+    return !myHighlightStyle.IsNull()
+         ?  myHighlightStyle->ColorRGBA()
+         :  myAspectTextSet->Aspect()->ColorRGBA();
   }
 
   //! Return text Subtitle color taking into account highlight flag.
   const OpenGl_Vec4& TextSubtitleColor() const
   {
-    return myToHighlight
-         ? *HighlightColor
-         : myAspectTextSet->Aspect()->ColorSubTitleRGBA();
+    return !myHighlightStyle.IsNull()
+         ?  myHighlightStyle->ColorRGBA()
+         :  myAspectTextSet->Aspect()->ColorSubTitleRGBA();
   }
 
   //! Currently set line aspect (can differ from applied).
@@ -306,7 +265,7 @@ public:
   //! Sets and applies current polygon offset.
   void SetPolygonOffset (const Graphic3d_PolygonOffset& theParams);
 
-  //! Returns currently applied polygon offset params.
+  //! Returns currently applied polygon offset parameters.
   const Graphic3d_PolygonOffset& AppliedPolygonOffset() { return myPolygonOffsetApplied; }
 
   //! Returns capping algorithm rendering filter.
@@ -341,14 +300,6 @@ public:
 
 protected:
 
-  enum
-  {
-    TEL_FRONT_MATERIAL = 1,
-    TEL_BACK_MATERIAL  = 2
-  };
-
-  void updateMaterial (const int theFlag);
-
   void setTextureParams (Handle(OpenGl_Texture)&                theTexture,
                          const Handle(Graphic3d_TextureParams)& theParams);
 
@@ -357,11 +308,8 @@ protected: //! @name protected fields
   OpenGl_View*                     myView;
   Handle(OpenGl_Window)            myWindow;
   Handle(OpenGl_Context)           myGlContext;
-  Handle(OpenGl_PrinterContext)    myPrintContext;
-  Handle(OpenGl_LineAttributes)    myLineAttribs;
   Standard_Boolean                 myUseZBuffer;
   Standard_Boolean                 myUseDepthWrite;
-  Standard_Boolean                 myUseGLLight;
   Handle(OpenGl_CappingAlgoFilter) myDefaultCappingAlgoFilter;
   OpenGl_AspectFace                myNoneCulling;
   OpenGl_AspectFace                myFrontCulling;
@@ -376,16 +324,13 @@ protected: //! @name fields related to status
   const OpenGl_AspectMarker* myAspectMarkerSet;
   Handle(Graphic3d_AspectMarker3d) myAspectMarkerApplied;
   const OpenGl_AspectText*   myAspectTextSet;
-  bool                       myAspectFaceAppliedWithHL;
+  Handle(Graphic3d_PresentationAttributes) myAspectFaceAppliedWithHL;
 
   const OpenGl_Matrix* ViewMatrix_applied;
   const OpenGl_Matrix* StructureMatrix_applied;
 
-  OpenGl_Material myMatFront;    //!< current front material state (cached to reduce GL context updates)
-  OpenGl_Material myMatBack;     //!< current back  material state
-  OpenGl_Material myMatTmp;      //!< temporary variable
   bool            myToAllowFaceCulling; //!< allow back face culling
-  bool            myToHighlight; //!< flag indicating highlighting mode
+  Handle(Graphic3d_PresentationAttributes) myHighlightStyle; //!< active highlight style
 
   OpenGl_Matrix myModelViewMatrix; //!< Model matrix with applied structure transformations