Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-26 09:04:22

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