1 // Created on: 2011-11-02
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2015 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _OpenGl_Layer_Header
17 #define _OpenGl_Layer_Header
19 #include <NCollection_Sequence.hxx>
20 #include <NCollection_Array1.hxx>
22 #include <InterfaceGraphic_telem.hxx>
24 #include <OpenGl_BVHClipPrimitiveSet.hxx>
25 #include <OpenGl_BVHClipPrimitiveTrsfPersSet.hxx>
26 #include <OpenGl_BVHTreeSelector.hxx>
28 #include <Graphic3d_ZLayerSettings.hxx>
29 #include <Graphic3d_Camera.hxx>
30 #include <OpenGl_GlCore11.hxx>
33 struct OpenGl_GlobalLayerSettings
39 //! Defines index map of OpenGL structures.
40 typedef NCollection_IndexedMap<const OpenGl_Structure*> OpenGl_IndexedMapOfStructure;
42 //! Defines array of indexed maps of OpenGL structures.
43 typedef NCollection_Array1<OpenGl_IndexedMapOfStructure> OpenGl_ArrayOfIndexedMapOfStructure;
45 //! Presentations list sorted within priorities.
50 //! Initializes associated priority list and layer properties
51 OpenGl_Layer (const Standard_Integer theNbPriorities = 11);
54 virtual ~OpenGl_Layer();
56 //! Returns settings of the layer object.
57 const Graphic3d_ZLayerSettings& LayerSettings() const { return myLayerSettings; };
59 //! Sets settings of the layer object.
60 void SetLayerSettings (const Graphic3d_ZLayerSettings& theSettings)
62 myLayerSettings = theSettings;
65 //! Returns true if theSetting is enabled for the layer.
66 Standard_Boolean IsSettingEnabled (const Graphic3d_ZLayerSetting theSetting) const
68 return myLayerSettings.IsSettingEnabled (theSetting);
71 void Add (const OpenGl_Structure* theStruct,
72 const Standard_Integer thePriority,
73 Standard_Boolean isForChangePriority = Standard_False);
75 //! Remove structure and returns its priority, if the structure is not found, method returns negative value
76 bool Remove (const OpenGl_Structure* theStruct,
77 Standard_Integer& thePriority,
78 Standard_Boolean isForChangePriority = Standard_False);
80 //! @return the number of structures
81 Standard_Integer NbStructures() const { return myNbStructures; }
83 //! Returns the number of available priority levels
84 Standard_Integer NbPriorities() const { return myArray.Length(); }
86 //! Append layer of acceptable type (with similar number of priorities or less).
87 //! Returns Standard_False if the list can not be accepted.
88 Standard_Boolean Append (const OpenGl_Layer& theOther);
90 //! Returns array of OpenGL structures.
91 const OpenGl_ArrayOfIndexedMapOfStructure& ArrayOfStructures() const { return myArray; }
93 //! Marks BVH tree for given priority list as dirty and
94 //! marks primitive set for rebuild.
95 void InvalidateBVHData();
97 // Render all structures.
98 void Render (const Handle(OpenGl_Workspace)& theWorkspace,
99 const OpenGl_GlobalLayerSettings& theDefaultSettings) const;
103 //! Traverses through BVH tree to determine which structures are in view volume.
104 void traverse (OpenGl_BVHTreeSelector& theSelector) const;
106 //! Iterates through the hierarchical list of existing structures and renders them all.
107 void renderAll (const Handle(OpenGl_Workspace)& theWorkspace) const;
109 //! Iterates through the hierarchical list of existing structures and renders only overlapping ones.
110 void renderTraverse (const Handle(OpenGl_Workspace)& theWorkspace) const;
114 //! Array of OpenGl_Structures by priority rendered in layer.
115 OpenGl_ArrayOfIndexedMapOfStructure myArray;
117 //! Overall number of structures rendered in the layer.
118 Standard_Integer myNbStructures;
120 //! Layer setting flags.
121 Graphic3d_ZLayerSettings myLayerSettings;
123 //! Set of OpenGl_Structures structures for building BVH tree.
124 mutable OpenGl_BVHClipPrimitiveSet myBVHPrimitives;
126 //! Set of transform persistent OpenGl_Structures for building BVH tree.
127 mutable OpenGl_BVHClipPrimitiveTrsfPersSet myBVHPrimitivesTrsfPers;
129 //! Is needed for implementation of stochastic order of BVH traverse.
130 mutable Standard_Boolean myBVHIsLeftChildQueuedFirst;
132 //! Defines if the primitive set for BVH is outdated.
133 mutable Standard_Boolean myIsBVHPrimitivesNeedsReset;
137 DEFINE_STANDARD_ALLOC
141 #endif //_OpenGl_Layer_Header