Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:36

0001 // Created on: 2011-09-20
0002 // Created by: Sergey ZERCHANINOV
0003 // Copyright (c) 2011-2013 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef OpenGl_Workspace_HeaderFile
0017 #define OpenGl_Workspace_HeaderFile
0018 
0019 #include <Graphic3d_BufferType.hxx>
0020 #include <Graphic3d_PresentationAttributes.hxx>
0021 
0022 #include <OpenGl_Aspects.hxx>
0023 #include <OpenGl_Vec.hxx>
0024 
0025 class OpenGl_FrameBuffer;
0026 class OpenGl_Group;
0027 class OpenGl_View;
0028 class OpenGl_Window;
0029 class Image_PixMap;
0030 
0031 class OpenGl_Workspace;
0032 DEFINE_STANDARD_HANDLE(OpenGl_Workspace,Standard_Transient)
0033 
0034 //! Rendering workspace.
0035 //! Provides methods to render primitives and maintain GL state.
0036 class OpenGl_Workspace : public Standard_Transient
0037 {
0038 public:
0039 
0040   //! Constructor of rendering workspace.
0041   Standard_EXPORT OpenGl_Workspace (OpenGl_View* theView, const Handle(OpenGl_Window)& theWindow);
0042 
0043   //! Destructor
0044   virtual ~OpenGl_Workspace() {}
0045 
0046   //! Activate rendering context.
0047   Standard_EXPORT Standard_Boolean Activate();
0048 
0049   OpenGl_View* View() const { return myView; }
0050 
0051   const Handle(OpenGl_Context)& GetGlContext() { return myGlContext; }
0052 
0053   Standard_EXPORT Handle(OpenGl_FrameBuffer) FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight);
0054 
0055   Standard_EXPORT void FBORelease (Handle(OpenGl_FrameBuffer)& theFbo);
0056 
0057   Standard_Boolean BufferDump (const Handle(OpenGl_FrameBuffer)& theFbo,
0058                                Image_PixMap&                     theImage,
0059                                const Graphic3d_BufferType&       theBufferType);
0060 
0061   Standard_EXPORT Standard_Integer Width()  const;
0062 
0063   Standard_EXPORT Standard_Integer Height() const;
0064 
0065   //! Setup Z-buffer usage flag (without affecting GL state!).
0066   //! Returns previously set flag.
0067   Standard_Boolean SetUseZBuffer (const Standard_Boolean theToUse)
0068   {
0069     const Standard_Boolean wasUsed = myUseZBuffer;
0070     myUseZBuffer = theToUse;
0071     return wasUsed;
0072   }
0073 
0074   //! @return true if usage of Z buffer is enabled.
0075   Standard_Boolean& UseZBuffer() { return myUseZBuffer; }
0076 
0077   //! @return true if depth writing is enabled.
0078   Standard_Boolean& UseDepthWrite() { return myUseDepthWrite; }
0079 
0080   //! Configure default polygon offset parameters.
0081   //! Return previous settings.
0082   Standard_EXPORT Graphic3d_PolygonOffset SetDefaultPolygonOffset (const Graphic3d_PolygonOffset& theOffset);
0083 
0084   //// RELATED TO STATUS ////
0085 
0086   //! Return true if active group might activate face culling (e.g. primitives are closed).
0087   bool ToAllowFaceCulling() const { return myToAllowFaceCulling; }
0088 
0089   //! Allow or disallow face culling.
0090   //! This call does NOT affect current state of back face culling;
0091   //! ApplyAspectFace() should be called to update state.
0092   bool SetAllowFaceCulling (bool theToAllow)
0093   {
0094     const bool wasAllowed = myToAllowFaceCulling;
0095     myToAllowFaceCulling = theToAllow;
0096     return wasAllowed;
0097   }
0098 
0099   //! Return true if following structures should apply highlight color.
0100   bool ToHighlight() const { return !myHighlightStyle.IsNull(); }
0101 
0102   //! Return highlight style.
0103   const Handle(Graphic3d_PresentationAttributes)& HighlightStyle() const { return myHighlightStyle; }
0104 
0105   //! Set highlight style.
0106   void SetHighlightStyle (const Handle(Graphic3d_PresentationAttributes)& theStyle) {  myHighlightStyle = theStyle; }
0107 
0108   //! Return edge color taking into account highlight flag.
0109   const OpenGl_Vec4& EdgeColor() const
0110   {
0111     return !myHighlightStyle.IsNull()
0112          ?  myHighlightStyle->ColorRGBA()
0113          :  myAspectsSet->Aspect()->EdgeColorRGBA();
0114   }
0115 
0116   //! Return Interior color taking into account highlight flag.
0117   const OpenGl_Vec4& InteriorColor() const
0118   {
0119     return !myHighlightStyle.IsNull()
0120          ?  myHighlightStyle->ColorRGBA()
0121          :  myAspectsSet->Aspect()->InteriorColorRGBA();
0122   }
0123 
0124   //! Return text color taking into account highlight flag.
0125   const OpenGl_Vec4& TextColor() const
0126   {
0127     return !myHighlightStyle.IsNull()
0128          ?  myHighlightStyle->ColorRGBA()
0129          :  myAspectsSet->Aspect()->ColorRGBA();
0130   }
0131 
0132   //! Return text Subtitle color taking into account highlight flag.
0133   const OpenGl_Vec4& TextSubtitleColor() const
0134   {
0135     return !myHighlightStyle.IsNull()
0136          ?  myHighlightStyle->ColorRGBA()
0137          :  myAspectsSet->Aspect()->ColorSubTitleRGBA();
0138   }
0139 
0140   //! Currently set aspects (can differ from applied).
0141   const OpenGl_Aspects* Aspects() const { return myAspectsSet; }
0142 
0143   //! Assign new aspects (will be applied within ApplyAspects()).
0144   Standard_EXPORT const OpenGl_Aspects* SetAspects (const OpenGl_Aspects* theAspect);
0145 
0146   //! Return TextureSet from set Aspects or Environment texture.
0147   const Handle(OpenGl_TextureSet)& TextureSet() const
0148   {
0149     const Handle(OpenGl_TextureSet)& aTextureSet = myAspectsSet->TextureSet (myGlContext, ToHighlight());
0150     return !aTextureSet.IsNull()
0151           || myAspectsSet->Aspect()->ToMapTexture()
0152           ? aTextureSet
0153           : myEnvironmentTexture;
0154   }
0155 
0156   //! Apply aspects.
0157   //! @param theToBindTextures flag to bind texture set defined by applied aspect
0158   //! @return aspect set by SetAspects()
0159   Standard_EXPORT const OpenGl_Aspects* ApplyAspects (bool theToBindTextures = true);
0160 
0161   //! Clear the applied aspect state to default values.
0162   void ResetAppliedAspect();
0163 
0164   //! Get rendering filter.
0165   //! @sa ShouldRender()
0166   Standard_Integer RenderFilter() const { return myRenderFilter; }
0167 
0168   //! Set filter for restricting rendering of particular elements.
0169   //! @sa ShouldRender()
0170   void SetRenderFilter (Standard_Integer theFilter) { myRenderFilter = theFilter; }
0171 
0172   //! Checks whether the element can be rendered or not.
0173   //! @param theElement [in] the element to check
0174   //! @param theGroup   [in] the group containing the element
0175   //! @return True if element can be rendered
0176   bool ShouldRender (const OpenGl_Element* theElement, const OpenGl_Group* theGroup);
0177 
0178   //! Return the number of skipped transparent elements within active OpenGl_RenderFilter_OpaqueOnly filter.
0179   //! @sa OpenGl_LayerList::Render()
0180   Standard_Integer NbSkippedTransparentElements() { return myNbSkippedTranspElems; }
0181 
0182   //! Reset skipped transparent elements counter.
0183   //! @sa OpenGl_LayerList::Render()
0184   void ResetSkippedCounter() { myNbSkippedTranspElems = 0; }
0185 
0186   //! Returns face aspect for none culling mode.
0187   const OpenGl_Aspects& NoneCulling() const { return myNoneCulling; }
0188 
0189   //! Returns face aspect for front face culling mode.
0190   const OpenGl_Aspects& FrontCulling() const { return myFrontCulling; }
0191 
0192   //! Sets a new environment texture.
0193   void SetEnvironmentTexture (const Handle(OpenGl_TextureSet)& theTexture) { myEnvironmentTexture = theTexture; }
0194 
0195   //! Returns environment texture.
0196   const Handle(OpenGl_TextureSet)& EnvironmentTexture() const { return myEnvironmentTexture; }
0197 
0198   //! Dumps the content of me into the stream
0199   Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0200   
0201 protected: //! @name protected fields
0202 
0203   OpenGl_View*           myView;
0204   Handle(OpenGl_Window)  myWindow;
0205   Handle(OpenGl_Context) myGlContext;
0206   Standard_Boolean       myUseZBuffer;
0207   Standard_Boolean       myUseDepthWrite;
0208   OpenGl_Aspects         myNoneCulling;
0209   OpenGl_Aspects         myFrontCulling;
0210 
0211 protected: //! @name fields related to status
0212 
0213   Standard_Integer myNbSkippedTranspElems; //!< counter of skipped transparent elements for OpenGl_LayerList two rendering passes method
0214   Standard_Integer myRenderFilter;         //!< active filter for skipping rendering of elements by some criteria (multiple render passes)
0215 
0216   OpenGl_Aspects   myDefaultAspects;
0217   const OpenGl_Aspects*      myAspectsSet;
0218   Handle(Graphic3d_Aspects)  myAspectsApplied;
0219 
0220   Handle(Graphic3d_PresentationAttributes) myAspectFaceAppliedWithHL;
0221 
0222   bool            myToAllowFaceCulling; //!< allow back face culling
0223   Handle(Graphic3d_PresentationAttributes) myHighlightStyle; //!< active highlight style
0224 
0225   OpenGl_Aspects myAspectFaceHl; //!< Hiddenline aspect
0226 
0227   Handle(OpenGl_TextureSet) myEnvironmentTexture;
0228 
0229 public: //! @name type definition
0230 
0231   DEFINE_STANDARD_RTTIEXT(OpenGl_Workspace,Standard_Transient)
0232   DEFINE_STANDARD_ALLOC
0233 
0234 };
0235 
0236 #endif // _OpenGl_Workspace_Header