0024023: Revamp the OCCT Handle -- automatic
[occt.git] / src / OpenGl / OpenGl_Layer.hxx
1 // Created on: 2011-11-02
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2015 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _OpenGl_Layer_Header
17 #define _OpenGl_Layer_Header
18
19 #include <NCollection_Sequence.hxx>
20 #include <NCollection_Array1.hxx>
21
22 #include <InterfaceGraphic_telem.hxx>
23
24 #include <OpenGl_BVHClipPrimitiveSet.hxx>
25 #include <OpenGl_BVHTreeSelector.hxx>
26
27 #include <Graphic3d_ZLayerSettings.hxx>
28 #include <OpenGl_GlCore11.hxx>
29
30
31 struct OpenGl_GlobalLayerSettings
32 {
33   GLint DepthFunc;
34   GLboolean DepthMask;
35 };
36
37 //! Presentations list sorted within priorities.
38 class OpenGl_Layer
39 {
40 public:
41
42   //! Initializes associated priority list and layer properties
43   OpenGl_Layer (const Standard_Integer theNbPriorities = 11);
44
45   //! Destructor.
46   virtual ~OpenGl_Layer();
47
48   //! Returns settings of the layer object.
49   const Graphic3d_ZLayerSettings& LayerSettings() const { return myLayerSettings; };
50
51   //! Sets settings of the layer object.
52   void SetLayerSettings (const Graphic3d_ZLayerSettings& theSettings)
53   {
54     myLayerSettings = theSettings;
55   }
56
57   //! Returns true if theSetting is enabled for the layer.
58   const Standard_Boolean IsSettingEnabled (const Graphic3d_ZLayerSetting theSetting) const
59   {
60     return myLayerSettings.IsSettingEnabled (theSetting);
61   }
62
63   void Add (const OpenGl_Structure* theStruct,
64             const Standard_Integer  thePriority,
65             Standard_Boolean        isForChangePriority = Standard_False);
66
67   //! Remove structure and returns its priority, if the structure is not found, method returns negative value
68   bool Remove (const OpenGl_Structure* theStruct,
69                Standard_Integer&       thePriority,
70                Standard_Boolean        isForChangePriority = Standard_False);
71
72   //! @return the number of structures
73   Standard_Integer NbStructures() const { return myNbStructures; }
74
75   //! Returns the number of available priority levels
76   Standard_Integer NbPriorities() const { return myArray.Length(); }
77
78   //! Append layer of acceptable type (with similar number of priorities or less).
79   //! Returns Standard_False if the list can not be accepted.
80   Standard_Boolean Append (const OpenGl_Layer& theOther);
81
82   //! Returns array of OpenGL structures.
83   const OpenGl_ArrayOfIndexedMapOfStructure& ArrayOfStructures() const { return myArray; }
84
85   //! Marks BVH tree for given priority list as dirty and
86   //! marks primitive set for rebuild.
87   void InvalidateBVHData();
88
89   // Render all structures.
90   void Render (const Handle(OpenGl_Workspace)&   theWorkspace,
91                const OpenGl_GlobalLayerSettings& theDefaultSettings) const;
92
93 protected:
94
95   //! Traverses through BVH tree to determine which structures are in view volume.
96   void traverse (OpenGl_BVHTreeSelector& theSelector) const;
97
98   //! Iterates through the hierarchical list of existing structures and renders them all.
99   void renderAll (const Handle(OpenGl_Workspace)& theWorkspace) const;
100
101   //! Iterates through the hierarchical list of existing structures and renders only overlapping ones.
102   void renderTraverse (const Handle(OpenGl_Workspace)& theWorkspace) const;
103
104 private:
105
106   OpenGl_ArrayOfIndexedMapOfStructure myArray;
107   Standard_Integer                    myNbStructures;
108   Graphic3d_ZLayerSettings            myLayerSettings;             //!< Layer setting flags
109   mutable OpenGl_BVHClipPrimitiveSet  myBVHPrimitives;             //!< Set of OpenGl_Structures for building BVH tree
110   mutable Standard_Boolean            myBVHIsLeftChildQueuedFirst; //!< Is needed for implementation of stochastic order of BVH traverse
111   mutable Standard_Boolean            myIsBVHPrimitivesNeedsReset; //!< Defines if the primitive set for BVH is outdated
112
113 public:
114
115   DEFINE_STANDARD_ALLOC
116
117 };
118
119 #endif //_OpenGl_Layer_Header