0024717: TKOpenGl - globally defined clipping planes blink when operating with view
[occt.git] / src / OpenGl / OpenGl_PriorityList.hxx
1 // Created on: 2011-11-02
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 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_PriorityList_Header
17 #define _OpenGl_PriorityList_Header
18
19 #include <NCollection_Sequence.hxx>
20 #include <NCollection_Array1.hxx>
21
22 #include <InterfaceGraphic_telem.hxx>
23
24 #include <Handle_OpenGl_Workspace.hxx>
25 #include <OpenGl_BVHClipPrimitiveSet.hxx>
26 #include <OpenGl_BVHTreeSelector.hxx>
27
28 class OpenGl_Structure;
29
30 typedef NCollection_Sequence<const OpenGl_Structure*> OpenGl_SequenceOfStructure;
31 typedef NCollection_Array1<OpenGl_SequenceOfStructure> OpenGl_ArrayOfStructure;
32
33 class OpenGl_PriorityList
34 {
35 public:
36
37   // Empty constructor.
38   OpenGl_PriorityList (const Standard_Integer theNbPriorities = 11);
39
40   //! Destructor.
41   virtual ~OpenGl_PriorityList();
42
43   void Add (const OpenGl_Structure* theStructure,
44             const Standard_Integer  thePriority,
45             Standard_Boolean isForChangePriority = Standard_False);
46
47   //! Remove structure and returns its priority, if the structure is not found, method returns negative value
48   Standard_Integer Remove (const OpenGl_Structure* theStructure,
49                            Standard_Boolean isForChangePriority = Standard_False);
50
51   //! @return the number of structures
52   Standard_Integer NbStructures() const { return myNbStructures; }
53
54   // Render all structures.
55   void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
56
57   //! Returns the number of available priority levels
58   Standard_Integer NbPriorities() const;
59
60   //! Append priority list of acceptable type (with similar number of priorities
61   //! or less). Returns Standard_False if the list can not be accepted.
62   Standard_Boolean Append (const OpenGl_PriorityList& theOther);
63
64   //! Returns array of OpenGL structures.
65   const OpenGl_ArrayOfStructure& ArrayOfStructures() const { return myArray; }
66
67   //! Marks BVH tree for given priority list as dirty and
68   //! marks primitive set for rebuild.
69   void InvalidateBVHData();
70
71 protected:
72
73   //! Traverses through BVH tree to determine which structures are in view volume.
74   void traverse (OpenGl_BVHTreeSelector& theSelector) const;
75
76   //! Iterates through the hierarchical list of existing structures and renders them all.
77   void renderAll (const Handle(OpenGl_Workspace)& theWorkspace) const;
78
79   //! Iterates through the hierarchical list of existing structures and renders only overlapping ones.
80   void renderTraverse (const Handle(OpenGl_Workspace)& theWorkspace) const;
81
82 protected:
83
84   OpenGl_ArrayOfStructure            myArray;
85   Standard_Integer                   myNbStructures;
86   mutable OpenGl_BVHClipPrimitiveSet myBVHPrimitives;             //<! Set of OpenGl_Structures for building BVH tree
87   mutable Standard_Boolean           myBVHIsLeftChildQueuedFirst; //<! Is needed for implementation of stochastic order of BVH traverse
88   mutable Standard_Boolean           myIsBVHPrimitivesNeedsReset; //<! Defines if the primitive set for BVH is outdated
89
90 public:
91
92   DEFINE_STANDARD_ALLOC
93
94 };
95
96 #endif // _OpenGl_PriorityList_Header