0030748: Visualization - Marker displayed in immediate layer ruins QT Quick view...
[occt.git] / src / OpenGl / OpenGl_Workspace.hxx
index 519ec7d..9b330cf 100644 (file)
 
 #include <Graphic3d_BufferType.hxx>
 
-#include <OpenGl_AspectFace.hxx>
+#include <OpenGl_Aspects.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>
 #include <OpenGl_TextParam.hxx>
 #include <OpenGl_TextureBufferArb.hxx>
+#include <OpenGl_RenderFilter.hxx>
 #include <OpenGl_Vec.hxx>
 #include <OpenGl_Window.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)
-
-//! Graphical ray-tracing filter.
-//! Filters out all raytracable structures.
-class OpenGl_RaytraceFilter : public OpenGl_RenderFilter
-{
-public:
-
-  //! Default constructor.
-  OpenGl_RaytraceFilter() {}
-
-  //! Returns the previously set filter.
-  const Handle(OpenGl_RenderFilter)& PrevRenderFilter()
-  {
-    return myPrevRenderFilter;
-  }
-
-  //! Remembers the previously set filter.
-  void SetPrevRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter)
-  {
-    myPrevRenderFilter = theFilter;
-  }
-
-  //! 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;
-
-private:
-
-  Handle(OpenGl_RenderFilter) myPrevRenderFilter;
-
-public:
-
-  DEFINE_STANDARD_RTTIEXT(OpenGl_RaytraceFilter,OpenGl_RenderFilter)
-};
-
 class OpenGl_Workspace;
 DEFINE_STANDARD_HANDLE(OpenGl_Workspace,Standard_Transient)
 
@@ -121,7 +47,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,154 +77,105 @@ 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 antialiasing is enabled.
-  Standard_EXPORT Standard_Integer AntiAliasingMode() const;
-
-  //! @return true if clipping algorithm enabled
-  Standard_EXPORT Standard_Boolean IsCullingEnabled() const;
-
-  Standard_Integer NamedStatus;
+  //! Configure default polygon offset parameters.
+  //! Return previous settings.
+  Standard_EXPORT Graphic3d_PolygonOffset SetDefaultPolygonOffset (const Graphic3d_PolygonOffset& theOffset);
 
   //// 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; }
 
   //! Allow or disallow face culling.
   //! This call does NOT affect current state of back face culling;
   //! ApplyAspectFace() should be called to update state.
-  void SetAllowFaceCulling (bool theToAllow) { myToAllowFaceCulling = theToAllow; }
+  bool SetAllowFaceCulling (bool theToAllow)
+  {
+    const bool wasAllowed = myToAllowFaceCulling;
+    myToAllowFaceCulling = theToAllow;
+    return wasAllowed;
+  }
 
   //! Return true if following structures should apply highlight color.
-  bool ToHighlight() const { return myToHighlight; }
+  bool ToHighlight() const { return !myHighlightStyle.IsNull(); }
 
-  //! Set highlight.
-  void SetHighlight (bool theToHighlight) { myToHighlight = theToHighlight; }
+  //! Return highlight style.
+  const Handle(Graphic3d_PresentationAttributes)& HighlightStyle() const { return myHighlightStyle; }
 
-  //! Return line color taking into account highlight flag.
-  const OpenGl_Vec4& LineColor() const
-  {
-    return myToHighlight
-         ? *HighlightColor
-         : myAspectLineSet->Aspect()->ColorRGBA();
-  }
+  //! Set highlight style.
+  void SetHighlightStyle (const Handle(Graphic3d_PresentationAttributes)& theStyle) {  myHighlightStyle = theStyle; }
 
   //! Return edge color taking into account highlight flag.
   const OpenGl_Vec4& EdgeColor() const
   {
-    return myToHighlight
-         ? *HighlightColor
-         : 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()
+         :  myAspectsSet->Aspect()->EdgeColorRGBA();
   }
 
   //! Return Interior color taking into account highlight flag.
   const OpenGl_Vec4& InteriorColor() const
   {
-    return myToHighlight
-         ? *HighlightColor
-         : myAspectFaceSet->Aspect()->InteriorColorRGBA();
+    return !myHighlightStyle.IsNull()
+         ?  myHighlightStyle->ColorRGBA()
+         :  myAspectsSet->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()
+         :  myAspectsSet->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()
+         :  myAspectsSet->Aspect()->ColorSubTitleRGBA();
   }
 
-  //! Currently set line aspect (can differ from applied).
-  const OpenGl_AspectLine*   AspectLine()   const { return myAspectLineSet; }
-
-  //! Currently set face aspect (can differ from applied).
-  const OpenGl_AspectFace*   AspectFace()   const { return myAspectFaceSet; }
-
-  //! Currently set marker aspect (can differ from applied).
-  const OpenGl_AspectMarker* AspectMarker() const { return myAspectMarkerSet; }
-
-  //! Currently set text aspect (can differ from applied).
-  const OpenGl_AspectText*   AspectText()   const { return myAspectTextSet; }
-
-  //! Assign new line aspect (will be applied within ApplyAspectLine()).
-  Standard_EXPORT const OpenGl_AspectLine*   SetAspectLine   (const OpenGl_AspectLine*   theAspect);
-
-  //! Assign new face aspect (will be applied within ApplyAspectFace()).
-  Standard_EXPORT const OpenGl_AspectFace*   SetAspectFace   (const OpenGl_AspectFace*   theAspect);
-
-  //! Assign new marker aspect (will be applied within ApplyAspectMarker()).
-  Standard_EXPORT const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect);
-
-  //! Assign new text aspect (will be applied within ApplyAspectText()).
-  Standard_EXPORT const OpenGl_AspectText*   SetAspectText   (const OpenGl_AspectText*   theAspect);
-
-  //! Apply line aspect.
-  //! @return aspect set by SetAspectLine()
-  const OpenGl_AspectLine* ApplyAspectLine() { return myAspectLineSet; }
+  //! Currently set aspects (can differ from applied).
+  const OpenGl_Aspects* Aspects() const { return myAspectsSet; }
 
-  //! Apply face aspect.
-  //! @return aspect set by SetAspectFace()
-  Standard_EXPORT const OpenGl_AspectFace*   ApplyAspectFace();
+  //! Assign new aspects (will be applied within ApplyAspects()).
+  Standard_EXPORT const OpenGl_Aspects* SetAspects (const OpenGl_Aspects* theAspect);
 
-  //! Apply marker aspect.
-  //! @return aspect set by SetAspectMarker()
-  Standard_EXPORT const OpenGl_AspectMarker* ApplyAspectMarker();
-
-  //! Apply text aspect.
-  //! @return aspect set by SetAspectText()
-  const OpenGl_AspectText* ApplyAspectText() { return myAspectTextSet; }
+  //! Apply aspects.
+  //! @return aspect set by SetAspects()
+  Standard_EXPORT const OpenGl_Aspects* ApplyAspects();
 
   //! Clear the applied aspect state to default values.
   void ResetAppliedAspect();
 
-  Standard_EXPORT Handle(OpenGl_Texture) DisableTexture();
-  Standard_EXPORT Handle(OpenGl_Texture) EnableTexture (const Handle(OpenGl_Texture)&          theTexture,
-                                                        const Handle(Graphic3d_TextureParams)& theParams = NULL);
-  const Handle(OpenGl_Texture)& ActiveTexture() const { return myTextureBound; }
+  //! Get rendering filter.
+  //! @sa ShouldRender()
+  Standard_Integer RenderFilter() const { return myRenderFilter; }
 
   //! Set filter for restricting rendering of particular elements.
-  //! Filter can be applied for rendering passes used by recursive
-  //! rendering algorithms for rendering elements of groups.
-  //! @param theFilter [in] the filter instance.
-  inline void SetRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter)
-  {
-    myRenderFilter = theFilter;
-  }
+  //! @sa ShouldRender()
+  void SetRenderFilter (Standard_Integer theFilter) { myRenderFilter = theFilter; }
 
-  //! Get rendering filter.
-  //! @return filter instance.
-  inline const Handle(OpenGl_RenderFilter)& GetRenderFilter() const
-  {
-    return myRenderFilter;
-  }
+  //! Checks whether the element can be rendered or not.
+  //! @param theElement [in] the element to check
+  //! @return True if element can be rendered
+  bool ShouldRender (const OpenGl_Element* theElement);
+
+  //! Return the number of skipped transparent elements within active OpenGl_RenderFilter_OpaqueOnly filter.
+  //! @sa OpenGl_LayerList::Render()
+  Standard_Integer NbSkippedTransparentElements() { return myNbSkippedTranspElems; }
+
+  //! Reset skipped transparent elements counter.
+  //! @sa OpenGl_LayerList::Render()
+  void ResetSkippedCounter() { myNbSkippedTranspElems = 0; }
 
   //! @return applied view matrix.
   inline const OpenGl_Matrix* ViewMatrix() const { return ViewMatrix_applied; }
@@ -306,98 +183,50 @@ public:
   //! @return applied model structure matrix.
   inline const OpenGl_Matrix* ModelMatrix() const { return StructureMatrix_applied; }
 
-  //! Sets and applies current polygon offset.
-  void SetPolygonOffset (const Graphic3d_PolygonOffset& theParams);
-
-  //! Returns currently applied polygon offset params.
-  const Graphic3d_PolygonOffset& AppliedPolygonOffset() { return myPolygonOffsetApplied; }
-
-  //! 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;
-  }
+  const OpenGl_Aspects& NoneCulling() const { return myNoneCulling; }
 
   //! Returns face aspect for front face culling mode.
-  const OpenGl_AspectFace& FrontCulling() const
-  {
-    return myFrontCulling;
-  }
+  const OpenGl_Aspects& FrontCulling() const { return myFrontCulling; }
 
   //! Sets a new environment texture.
-  void SetEnvironmentTexture (const Handle(OpenGl_Texture)& theTexture)
-  {
-    myEnvironmentTexture = theTexture;
-  }
+  void SetEnvironmentTexture (const Handle(OpenGl_TextureSet)& theTexture) { myEnvironmentTexture = theTexture; }
 
   //! Returns environment texture.
-  const Handle(OpenGl_Texture)& EnvironmentTexture() const
-  {
-    return myEnvironmentTexture;
-  }
-
-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);
+  const Handle(OpenGl_TextureSet)& EnvironmentTexture() const { return myEnvironmentTexture; }
 
 protected: //! @name protected fields
 
-  OpenGl_View*                     myView;
-  Handle(OpenGl_Window)            myWindow;
-  Handle(OpenGl_Context)           myGlContext;
-  Handle(OpenGl_PrinterContext)    myPrintContext;
-  Handle(OpenGl_LineAttributes)    myLineAttribs;
-  Standard_Integer                 myAntiAliasingMode;
-  Standard_Boolean                 myUseZBuffer;
-  Standard_Boolean                 myUseDepthWrite;
-  Standard_Boolean                 myUseGLLight;
-  Handle(OpenGl_CappingAlgoFilter) myDefaultCappingAlgoFilter;
-  OpenGl_AspectFace                myNoneCulling;
-  OpenGl_AspectFace                myFrontCulling;
+  OpenGl_View*           myView;
+  Handle(OpenGl_Window)  myWindow;
+  Handle(OpenGl_Context) myGlContext;
+  Standard_Boolean       myUseZBuffer;
+  Standard_Boolean       myUseDepthWrite;
+  OpenGl_Aspects         myNoneCulling;
+  OpenGl_Aspects         myFrontCulling;
 
 protected: //! @name fields related to status
 
-  Handle(OpenGl_RenderFilter) myRenderFilter;
-  Handle(OpenGl_Texture) myTextureBound;    //!< currently bound texture (managed by OpenGl_AspectFace and OpenGl_View environment texture)
-  const OpenGl_AspectLine*   myAspectLineSet;
-  const OpenGl_AspectFace*   myAspectFaceSet;
-  Handle(Graphic3d_AspectFillArea3d) myAspectFaceApplied;
-  const OpenGl_AspectMarker* myAspectMarkerSet;
-  Handle(Graphic3d_AspectMarker3d) myAspectMarkerApplied;
-  const OpenGl_AspectText*   myAspectTextSet;
-  bool                       myAspectFaceAppliedWithHL;
+  Standard_Integer myNbSkippedTranspElems; //!< counter of skipped transparent elements for OpenGl_LayerList two rendering passes method
+  Standard_Integer myRenderFilter;         //!< active filter for skipping rendering of elements by some criteria (multiple render passes)
+
+  OpenGl_Aspects   myDefaultAspects;
+  const OpenGl_Aspects*      myAspectsSet;
+  Handle(Graphic3d_Aspects)  myAspectsApplied;
+
+  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
 
-  Graphic3d_PolygonOffset myPolygonOffsetApplied; //!< currently applied polygon offset
-
-  OpenGl_AspectFace myAspectFaceHl; //!< Hiddenline aspect
+  OpenGl_Aspects myAspectFaceHl; //!< Hiddenline aspect
 
-  Handle(OpenGl_Texture) myEnvironmentTexture;
+  Handle(OpenGl_TextureSet) myEnvironmentTexture;
 
 public: //! @name type definition