Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Created on: 2012-02-02
0002 // Created by: Anton POLETAEV
0003 // Copyright (c) 2012-2014 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_LayerList_HeaderFile
0017 #define OpenGl_LayerList_HeaderFile
0018 
0019 #include <OpenGl_Layer.hxx>
0020 #include <OpenGl_LayerFilter.hxx>
0021 
0022 #include <Graphic3d_ZLayerId.hxx>
0023 #include <NCollection_Array1.hxx>
0024 #include <NCollection_Handle.hxx>
0025 #include <NCollection_DataMap.hxx>
0026 
0027 class OpenGl_FrameBuffer;
0028 class OpenGl_Structure;
0029 class OpenGl_Workspace;
0030 struct OpenGl_GlobalLayerSettings;
0031 
0032 //! Class defining the list of layers.
0033 class OpenGl_LayerList
0034 {
0035 public:
0036 
0037   //! Constructor
0038   Standard_EXPORT OpenGl_LayerList();
0039 
0040   //! Destructor
0041   Standard_EXPORT virtual ~OpenGl_LayerList();
0042 
0043   //! Method returns the number of available priorities
0044   Standard_Integer NbPriorities() const { return Graphic3d_DisplayPriority_NB; }
0045 
0046   //! Number of displayed structures
0047   Standard_Integer NbStructures() const { return myNbStructures; }
0048 
0049   //! Return number of structures within immediate layers
0050   Standard_Integer NbImmediateStructures() const { return myImmediateNbStructures; }
0051 
0052   //! Insert a new layer with id.
0053   Standard_EXPORT void InsertLayerBefore (const Graphic3d_ZLayerId theNewLayerId,
0054                                           const Graphic3d_ZLayerSettings& theSettings,
0055                                           const Graphic3d_ZLayerId theLayerAfter);
0056 
0057   //! Insert a new layer with id.
0058   Standard_EXPORT void InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
0059                                          const Graphic3d_ZLayerSettings& theSettings,
0060                                          const Graphic3d_ZLayerId theLayerBefore);
0061 
0062   //! Remove layer by its id.
0063   Standard_EXPORT void RemoveLayer (const Graphic3d_ZLayerId theLayerId);
0064 
0065   //! Add structure to list with given priority. The structure will be inserted
0066   //! to specified layer. If the layer isn't found, the structure will be put
0067   //! to default bottom-level layer.
0068   Standard_EXPORT void AddStructure (const OpenGl_Structure*  theStruct,
0069                                      const Graphic3d_ZLayerId theLayerId,
0070                                      const Graphic3d_DisplayPriority thePriority,
0071                                      Standard_Boolean        isForChangePriority = Standard_False);
0072 
0073   //! Remove structure from structure list and return its previous priority
0074   Standard_EXPORT void RemoveStructure (const OpenGl_Structure* theStructure);
0075 
0076   //! Change structure z layer
0077   //! If the new layer is not presented, the structure will be displayed
0078   //! in default z layer
0079   Standard_EXPORT void ChangeLayer (const OpenGl_Structure*  theStructure,
0080                                     const Graphic3d_ZLayerId theOldLayerId,
0081                                     const Graphic3d_ZLayerId theNewLayerId);
0082 
0083   //! Changes structure priority within its ZLayer
0084   Standard_EXPORT void ChangePriority (const OpenGl_Structure*  theStructure,
0085                                        const Graphic3d_ZLayerId theLayerId,
0086                                        const Graphic3d_DisplayPriority theNewPriority);
0087 
0088   //! Returns reference to the layer with given ID.
0089   OpenGl_Layer& Layer (const Graphic3d_ZLayerId theLayerId) { return *myLayerIds.Find (theLayerId); }
0090 
0091   //! Returns reference to the layer with given ID.
0092   const OpenGl_Layer& Layer (const Graphic3d_ZLayerId theLayerId) const { return *myLayerIds.Find (theLayerId); }
0093 
0094   //! Assign new settings to the layer.
0095   Standard_EXPORT void SetLayerSettings (const Graphic3d_ZLayerId        theLayerId,
0096                                          const Graphic3d_ZLayerSettings& theSettings);
0097 
0098   //! Update culling state - should be called before rendering.
0099   Standard_EXPORT void UpdateCulling (const Handle(OpenGl_Workspace)& theWorkspace,
0100                                       const Standard_Boolean theToDrawImmediate);
0101 
0102   //! Render this element
0103   Standard_EXPORT void Render (const Handle(OpenGl_Workspace)& theWorkspace,
0104                                const Standard_Boolean          theToDrawImmediate,
0105                                const OpenGl_LayerFilter        theLayersToProcess,
0106                                OpenGl_FrameBuffer*             theReadDrawFbo,
0107                                OpenGl_FrameBuffer*             theOitAccumFbo) const;
0108 
0109   //! Returns the set of OpenGL Z-layers.
0110   const NCollection_List<Handle(Graphic3d_Layer)>& Layers() const { return myLayers; }
0111 
0112   //! Returns the map of Z-layer IDs to indexes.
0113   const NCollection_DataMap<Graphic3d_ZLayerId, Handle(Graphic3d_Layer)>& LayerIDs() const { return myLayerIds; }
0114 
0115   //! Marks BVH tree for given priority list as dirty and
0116   //! marks primitive set for rebuild.
0117   Standard_EXPORT void InvalidateBVHData (const Graphic3d_ZLayerId theLayerId);
0118 
0119   //! Returns structure modification state (for ray-tracing).
0120   Standard_Size ModificationStateOfRaytracable() const { return myModifStateOfRaytraceable; }
0121 
0122   //! Returns BVH tree builder for frustum culling.
0123   const Handle(Select3D_BVHBuilder3d)& FrustumCullingBVHBuilder() const { return myBVHBuilder; }
0124 
0125   //! Assigns BVH tree builder for frustum culling.
0126   Standard_EXPORT void SetFrustumCullingBVHBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder);
0127 
0128   //! Dumps the content of me into the stream
0129   Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0130 
0131 protected:
0132 
0133   //! Stack of references to existing layers of predefined maximum size.
0134   class OpenGl_LayerStack
0135   {
0136   public:
0137     typedef NCollection_Array1<const Graphic3d_Layer*>::const_iterator const_iterator;
0138     typedef NCollection_Array1<const Graphic3d_Layer*>::iterator iterator;
0139 
0140     //! Reallocate internal buffer of the stack.
0141     void Allocate (Standard_Integer theSize)
0142     {
0143       if (theSize > 0)
0144       {
0145         myStackSpace.Resize (1, theSize, false);
0146         myStackSpace.Init (NULL);
0147         myBackPtr = myStackSpace.begin();
0148       }
0149       else
0150       {
0151         NCollection_Array1<const Graphic3d_Layer*> aDummy;
0152         myStackSpace.Move (std::move(aDummy));
0153         myBackPtr = iterator();
0154       }
0155     }
0156 
0157     //! Clear stack.
0158     void Clear()
0159     {
0160       myStackSpace.Init (NULL);
0161       myBackPtr = myStackSpace.begin();
0162     }
0163 
0164     //! Push a new layer reference to the stack.
0165     void Push (const OpenGl_Layer* theLayer) { (*myBackPtr++) = theLayer; }
0166 
0167     //! Returns iterator to the origin of the stack.
0168     const_iterator Origin() const { return myStackSpace.IsEmpty() ? const_iterator() : myStackSpace.begin(); }
0169 
0170     //! Returns iterator to the back of the stack (after last item added).
0171     iterator Back() const { return myBackPtr; }
0172 
0173     //! Returns iterator to the origin of the stack.
0174     iterator Origin() { return myStackSpace.IsEmpty() ? iterator() : myStackSpace.begin(); }
0175 
0176     //! Returns true if nothing has been pushed into the stack.
0177     Standard_Boolean IsEmpty() const { return Back() == Origin(); }
0178 
0179   private:
0180 
0181     NCollection_Array1<const OpenGl_Layer*> myStackSpace;
0182     iterator                                myBackPtr;
0183   };
0184 
0185   //! Render transparent objects using blending operator.
0186   //! Additional accumulation framebuffer is used for blended order-independent
0187   //! transparency algorithm. It should support floating-point color components
0188   //! and share depth with main reading/drawing framebuffer.
0189   //! @param theWorkspace [in] the currently used workspace for rendering.
0190   //! @param theLayerIter [in/out] the current iterator of transparent layers to process.
0191   //! @param theGlobalSettings [in] the set of global settings used for rendering.
0192   //! @param theReadDrawFbo [in] the framebuffer for reading depth and writing final color.
0193   //! @param theOitAccumFbo [in] the framebuffer for accumulating color and coverage for OIT process.
0194   Standard_EXPORT void renderTransparent (const Handle(OpenGl_Workspace)&   theWorkspace,
0195                                           OpenGl_LayerStack::iterator&      theLayerIter,
0196                                           const OpenGl_GlobalLayerSettings& theGlobalSettings,
0197                                           OpenGl_FrameBuffer*               theReadDrawFbo,
0198                                           OpenGl_FrameBuffer*               theOitAccumFbo) const;
0199 
0200   // Render structures within specified layer.
0201   Standard_EXPORT void renderLayer (const Handle(OpenGl_Workspace)& theWorkspace,
0202                                     const OpenGl_GlobalLayerSettings& theDefaultSettings,
0203                                     const Graphic3d_Layer& theLayer) const;
0204 
0205 protected:
0206 
0207   NCollection_List<Handle(Graphic3d_Layer)> myLayers;
0208   NCollection_DataMap<Graphic3d_ZLayerId, Handle(Graphic3d_Layer)> myLayerIds;
0209   Handle(Select3D_BVHBuilder3d) myBVHBuilder;      //!< BVH tree builder for frustum culling
0210 
0211   Standard_Integer        myNbStructures;
0212   Standard_Integer        myImmediateNbStructures; //!< number of structures within immediate layers
0213 
0214   mutable Standard_Size   myModifStateOfRaytraceable;
0215 
0216   //! Collection of references to layers with transparency gathered during rendering pass.
0217   mutable OpenGl_LayerStack myTransparentToProcess;
0218 
0219 public:
0220 
0221   DEFINE_STANDARD_ALLOC
0222 
0223 };
0224 
0225 #endif //_OpenGl_LayerList_Header