1 | #ifndef _GtpVisibilityHierarchyInterface_H__
|
---|
2 | #define _GtpVisibilityHierarchyInterface_H__
|
---|
3 |
|
---|
4 | #include "DistanceQueue.h"
|
---|
5 | #include "VisibilityMesh.h"
|
---|
6 | #include <stack>
|
---|
7 |
|
---|
8 | namespace GtpVisibility {
|
---|
9 |
|
---|
10 | enum CullingType {QUERY_CULLED, FRUSTUM_CULLED};
|
---|
11 |
|
---|
12 | typedef std::vector<HierarchyNode *> NodeVector;
|
---|
13 | typedef std::vector<GtpVisibility::Mesh *> GeometryVector;
|
---|
14 | typedef std::vector<GtpVisibility::Patch *> PatchVector;
|
---|
15 | typedef std::pair<HierarchyNode *, OcclusionQuery *> QueryPair;
|
---|
16 | typedef std::pair<HierarchyNode *, bool> PendingQuery;
|
---|
17 | typedef std::queue<QueryPair> QueryQueue;
|
---|
18 | typedef std::queue<PendingQuery> PendingQueue;
|
---|
19 |
|
---|
20 |
|
---|
21 | /** Class which implements a hierarchy interface for a scene hierarchy. It has to be implemented
|
---|
22 | for any rendering engine to use the CHC algorithm.
|
---|
23 | */
|
---|
24 | class HierarchyInterface
|
---|
25 | {
|
---|
26 | public:
|
---|
27 | /** Default constructor.
|
---|
28 | */
|
---|
29 | HierarchyInterface();
|
---|
30 | virtual ~HierarchyInterface();
|
---|
31 | /** Returns true if current node is leaf of the hierarchy.
|
---|
32 | @param node hierarchy node
|
---|
33 | @returns true if node is leaf
|
---|
34 | */
|
---|
35 | virtual bool IsLeaf(HierarchyNode *node) const = 0;
|
---|
36 | /** Traverses and renders the hierarchy from the given node.
|
---|
37 | @param node the hierarchy node
|
---|
38 | */
|
---|
39 | virtual void TraverseNode(HierarchyNode *node) = 0;
|
---|
40 | /** Renders the given hierarchy node.
|
---|
41 | @param node current hierarchy node to be rendered
|
---|
42 | */
|
---|
43 | virtual void RenderNode(HierarchyNode *node) = 0;
|
---|
44 | /** Pulls up the visibility from the current node recursively to the parent nodes.
|
---|
45 | @param node the current node
|
---|
46 | */
|
---|
47 | virtual void PullUpVisibility(HierarchyNode *node) const = 0;
|
---|
48 | /** Issue a occlusion query for this node.
|
---|
49 | @param node the current hierarchy node
|
---|
50 | @param wasVisible if the node was visible in the last frame: based
|
---|
51 | on this the method can decide on the way of querying
|
---|
52 | @returns occlusion query for this node
|
---|
53 | */
|
---|
54 | virtual OcclusionQuery *IssueNodeOcclusionQuery(HierarchyNode *node,
|
---|
55 | const bool wasVisible = false) = 0;
|
---|
56 | /** Sets the root of the scene hierarchy.
|
---|
57 | @param root the hierarchy root
|
---|
58 | */
|
---|
59 | void SetHierarchyRoot(HierarchyNode *root);
|
---|
60 | /** Get the root of the scene hierarchy.
|
---|
61 | @return the hierarchy root
|
---|
62 | */
|
---|
63 | HierarchyNode *GetHierarchyRoot() const;
|
---|
64 | /** Sets the scene root and initialises this hierarchy interface for a traversal.
|
---|
65 | @remark also resets the statistics evaluated in the last traversal
|
---|
66 | */
|
---|
67 | void InitTraversal();
|
---|
68 | /** Returns current frame id.
|
---|
69 | @returns frame id
|
---|
70 | */
|
---|
71 | unsigned int GetFrameId() const;
|
---|
72 | /** Returns a pointer to the distance queue.
|
---|
73 | @returns current distance queue.
|
---|
74 | @remark the distance queue stores hierarchy nodes in a front-to-back order
|
---|
75 | */
|
---|
76 | DistanceQueue *GetQueue();
|
---|
77 |
|
---|
78 | /** Returns distance of the node to the view plane.
|
---|
79 | @param node the hierarchy node
|
---|
80 | */
|
---|
81 | virtual float GetSquaredDistance(HierarchyNode *node) const = 0;
|
---|
82 | /** Checks if the node is visible from the current view frustum.
|
---|
83 | @param node the current node
|
---|
84 | @param intersects returns true if the current node intersects the near plane
|
---|
85 | */
|
---|
86 | virtual bool CheckFrustumVisible(HierarchyNode *node,
|
---|
87 | bool &intersects) = 0;
|
---|
88 | /** Checks if the node is visible from the current view frustum.
|
---|
89 | @param node the current node
|
---|
90 | */
|
---|
91 | bool CheckFrustumVisible(HierarchyNode *node);
|
---|
92 | /** Returns next available occlusion query or creates new one.
|
---|
93 | @return the next occlusion query
|
---|
94 | */
|
---|
95 | virtual OcclusionQuery *GetNextOcclusionQuery() = 0;
|
---|
96 | /** Returns true if there is renderable geometry attached to this node
|
---|
97 | @param node the current node
|
---|
98 | @returns if the node has renderable geometry
|
---|
99 | */
|
---|
100 | virtual bool HasGeometry(HierarchyNode *node) const = 0;
|
---|
101 | /** Sets the visible flag for this node.
|
---|
102 | @param node the current node
|
---|
103 | @param visible the visible flag
|
---|
104 | */
|
---|
105 | virtual void SetNodeVisible(HierarchyNode *node,
|
---|
106 | const bool visible) const = 0;
|
---|
107 | /** Returns true if node has the visible flag set. See set
|
---|
108 | */
|
---|
109 | virtual bool IsNodeVisible(HierarchyNode *node) const = 0;
|
---|
110 | /** Sets the last visited frame id for this node.
|
---|
111 | @param node the current node
|
---|
112 | @param frameId the current frame id
|
---|
113 | */
|
---|
114 | virtual void SetLastVisited(HierarchyNode *node,
|
---|
115 | const unsigned int frameId) const = 0;
|
---|
116 | /** Returns frame id when this node was last visited by the traverser. See set
|
---|
117 | */
|
---|
118 | virtual unsigned int LastVisited(HierarchyNode *node) const = 0;
|
---|
119 | /** Returns number of traversed nodes.
|
---|
120 | */
|
---|
121 | unsigned int GetNumTraversedNodes();
|
---|
122 | /** Returns number of rendered nodes.
|
---|
123 | */
|
---|
124 | unsigned int GetNumRenderedNodes();
|
---|
125 |
|
---|
126 | //bool mIsShadowPass;
|
---|
127 |
|
---|
128 | /** Visualization of a culled node, dependent on the culling type.
|
---|
129 | @param node the hierarchy node to be visualized
|
---|
130 | @param type can be one of FRUSTUM_CULLED, QUERY_CULLED
|
---|
131 | */
|
---|
132 | virtual void VisualizeCulledNode(HierarchyNode *node,
|
---|
133 | CullingType type) const = 0;
|
---|
134 |
|
---|
135 | /** Returns vector of visible hierarchy nodes from previous render.
|
---|
136 | */
|
---|
137 | std::vector<HierarchyNode *> *GetVisibleNodes();
|
---|
138 | /** Returns vector of previoulsy rendered geometry.
|
---|
139 | */
|
---|
140 |
|
---|
141 | /** Returns the geometry of a given hierarchy node.
|
---|
142 | @param node the hierarchy node containing the geometry
|
---|
143 | @param geometryList geometry is returned in this list
|
---|
144 | @param includeChildren if the geometry of the children should be taken into account
|
---|
145 | */
|
---|
146 | virtual void GetNodeGeometryList(GtpVisibility::HierarchyNode *node,
|
---|
147 | GeometryVector *geometryList,
|
---|
148 | bool includeChildren) = 0;
|
---|
149 |
|
---|
150 |
|
---|
151 | /** This is an optimization when issuing the occlusion test.
|
---|
152 | The test is done with actual geometry rather than the bounding
|
---|
153 | box of leave nodes previously marked as visible.
|
---|
154 |
|
---|
155 | @param testGeometry if this optimization should be used
|
---|
156 | @remark this option is only useful for the coherent hierarchical culling algorithm
|
---|
157 | */
|
---|
158 | void TestGeometryForVisibleLeaves(bool testGeometry);
|
---|
159 |
|
---|
160 |
|
---|
161 | virtual void DetermineFullVisibility(GtpVisibility::HierarchyNode *node) const = 0;
|
---|
162 |
|
---|
163 | virtual void TraverseNode2(GtpVisibility::HierarchyNode *node) = 0;
|
---|
164 |
|
---|
165 | virtual HierarchyNode *GetRandomLeaf(HierarchyNode *root) = 0;
|
---|
166 | virtual bool IsNodeFullyVisible(GtpVisibility::HierarchyNode *node) const = 0;
|
---|
167 |
|
---|
168 | protected:
|
---|
169 |
|
---|
170 |
|
---|
171 | /// chc optimization for testing geometry of leaves instead of bounding box
|
---|
172 | bool mTestGeometryForVisibleLeaves;
|
---|
173 | /// the current frame number
|
---|
174 | unsigned int mFrameId;
|
---|
175 | /// index of the lcurrent occlusion query in the array of queries
|
---|
176 | /// NOTE: should rather be iterator
|
---|
177 | int mCurrentTestIdx;
|
---|
178 |
|
---|
179 | /// number of traversed nodes
|
---|
180 | unsigned int mNumTraversedNodes;
|
---|
181 |
|
---|
182 | /// The queue is useful for rendering hierarchy nodes in front to back order.
|
---|
183 | DistanceQueue *mDistanceQueue;
|
---|
184 |
|
---|
185 | /// the root of the hierarchy
|
---|
186 | HierarchyNode *mHierarchyRoot;
|
---|
187 |
|
---|
188 | /// buffer for a node pointer
|
---|
189 | HierarchyNode *mSavedNode;
|
---|
190 | /// list of rendered hierarchy nodes (e.g., useful for exact visibility queries)
|
---|
191 | std::vector<HierarchyNode *> mVisibleNodes;
|
---|
192 | };
|
---|
193 | } // namespace GtpVisibility
|
---|
194 |
|
---|
195 | #endif // GtpVisisibilityHierarchyInterface_H |
---|