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