1 | #ifndef _GtpVisibilityHierarchyInterface_H__
|
---|
2 | #define _GtpVisibilityHierarchyInterface_H__
|
---|
3 |
|
---|
4 | #include "DistanceQueue.h"
|
---|
5 | #include "VisibilityMesh.h"
|
---|
6 |
|
---|
7 | namespace GtpVisibility {
|
---|
8 |
|
---|
9 | enum CullingType {QUERY_CULLED, FRUSTUM_CULLED};
|
---|
10 |
|
---|
11 | typedef std::vector<HierarchyNode *> HierarchyNodeList;
|
---|
12 | typedef std::vector<GtpVisibility::Mesh *> GeometryList;
|
---|
13 | typedef std::pair<HierarchyNode *, OcclusionQuery *> QueryPair;
|
---|
14 | typedef std::queue<QueryPair> QueryQueue;
|
---|
15 |
|
---|
16 | /** Class which implements a hierarchy interface for a scene hierarchy.
|
---|
17 | */
|
---|
18 | class HierarchyInterface
|
---|
19 | {
|
---|
20 | public:
|
---|
21 | /** Default constructor.
|
---|
22 | */
|
---|
23 | HierarchyInterface();
|
---|
24 | virtual ~HierarchyInterface();
|
---|
25 | /** Returns true if current node is leaf of the hierarchy.
|
---|
26 | @param node hierarchy node
|
---|
27 | @returns true if node is leaf
|
---|
28 | */
|
---|
29 | virtual bool IsLeaf(HierarchyNode *node) const = 0;
|
---|
30 | /** Traverses the given node.
|
---|
31 | @param node the hierarchy node
|
---|
32 | */
|
---|
33 | virtual void TraverseNode(HierarchyNode *node) = 0;
|
---|
34 | /** Renders current hierarchy node.
|
---|
35 | @param node current hierarchy node to be rendered
|
---|
36 | */
|
---|
37 | virtual void RenderNode(HierarchyNode *node) = 0;
|
---|
38 | /** Pulls up the visibility from the current node recursively to the parent nodes.
|
---|
39 | @param node the current node
|
---|
40 | */
|
---|
41 | virtual void PullUpVisibility(HierarchyNode *node) = 0;
|
---|
42 | /** Issue a occlusion query for this node.
|
---|
43 | @param node the current hierarchy node
|
---|
44 | @returns occlusion query for this node
|
---|
45 | */
|
---|
46 | virtual OcclusionQuery *IssueOcclusionQuery(HierarchyNode *node,
|
---|
47 | const bool wasVisible = false) = 0;
|
---|
48 | /** Sets the root of the scene hierarchy.
|
---|
49 | @param root the hierarchy root
|
---|
50 | */
|
---|
51 | void SetSceneRoot(HierarchyNode *root);
|
---|
52 | /** Get the root of the scene hierarchy.
|
---|
53 | @return the hierarchy root
|
---|
54 | */
|
---|
55 | HierarchyNode *GetSceneRoot() const;
|
---|
56 | /** Sets the scene root and initialises this scene traverser for a traversal.
|
---|
57 | @param root current scene root
|
---|
58 | @remark initialises some parameters, and also the statistics.
|
---|
59 | */
|
---|
60 | void InitFrame(HierarchyNode *root);
|
---|
61 | /** Returns current frame id.
|
---|
62 | @returns frame id
|
---|
63 | */
|
---|
64 | unsigned int GetFrameId() const;
|
---|
65 | /** Returns the current distance queue.
|
---|
66 | @returns current distance queue
|
---|
67 | */
|
---|
68 | DistanceQueue *GetQueue();
|
---|
69 | /** Returns distance of the node to the view plane.
|
---|
70 | @param node1 the hierarchy node
|
---|
71 | */
|
---|
72 | virtual float GetSquaredDistance(HierarchyNode *node) const = 0;
|
---|
73 | /** Checks if the node is visible from the current view frustum.
|
---|
74 | @param node the current node
|
---|
75 | @param intersects returns true if the current node intersects the near plane
|
---|
76 | */
|
---|
77 | virtual bool CheckFrustumVisible(HierarchyNode *node, bool &intersects) = 0;
|
---|
78 | /** Checks if the node is visible from the current view frustum.
|
---|
79 | @param node the current node
|
---|
80 | */
|
---|
81 | bool CheckFrustumVisible(HierarchyNode *node);
|
---|
82 | /** Returns next available occlusion query or creates new one.
|
---|
83 | @return the next occlusion query
|
---|
84 | */
|
---|
85 | virtual OcclusionQuery *GetNextOcclusionQuery() = 0;
|
---|
86 | /** Returns true if there is renderable geometry attached to this node
|
---|
87 | @param node the current node
|
---|
88 | @returns if the node has renderable geometry
|
---|
89 | */
|
---|
90 | virtual bool HasGeometry(HierarchyNode *node) const = 0;
|
---|
91 | /** Sets the visible flag for this node.
|
---|
92 | @param node the current node
|
---|
93 | @param visible the visible flag
|
---|
94 | */
|
---|
95 | virtual void SetNodeVisible(HierarchyNode *node, const bool visible) = 0;
|
---|
96 | /** Returns true if node has the visible flag set. See set
|
---|
97 | */
|
---|
98 | virtual bool IsNodeVisible(HierarchyNode *node) const = 0;
|
---|
99 | /** Sets the last visited frame id for this node.
|
---|
100 | @param node the current node
|
---|
101 | @param frameId the current frame id
|
---|
102 | */
|
---|
103 | virtual void SetLastVisited(HierarchyNode *node,
|
---|
104 | const unsigned int frameId) = 0;
|
---|
105 | /** Returns frame id when this node was last visited by the traverser. See set
|
---|
106 | */
|
---|
107 | virtual unsigned int LastVisited(HierarchyNode *node) const = 0;
|
---|
108 | /** Returns number of traversed nodes.
|
---|
109 | */
|
---|
110 | unsigned int GetNumTraversedNodes();
|
---|
111 | /** Returns number of rendered nodes.
|
---|
112 | */
|
---|
113 | unsigned int GetNumRenderedNodes();
|
---|
114 | /** Optimization when issuing occlusion test: test is done with actual geometry
|
---|
115 | rather than the bounding box
|
---|
116 | @param useOptimization if the optimization should be used
|
---|
117 | */
|
---|
118 | void SetUseOptimization(bool useOptimization);
|
---|
119 | //bool mIsShadowPass;
|
---|
120 |
|
---|
121 | /** Visualization of a culled node, dependent on the culling type.
|
---|
122 | @param type can be one of FRUSTUM_CULLED, QUERY_CULLED
|
---|
123 | */
|
---|
124 | virtual void VisualizeCulledNode(HierarchyNode *node,
|
---|
125 | CullingType type) = NULL;
|
---|
126 |
|
---|
127 | /** Returns vector of previously rendered hierarchy nodes.
|
---|
128 | */
|
---|
129 | std::vector<HierarchyNode *> *GetRenderedNodes();
|
---|
130 | /** Returns vector of previoulsy rendered geometry.
|
---|
131 | */
|
---|
132 |
|
---|
133 | /** Issue a occlusion query for this mesh.
|
---|
134 | @param node the current mesh
|
---|
135 | @returns occlusion query for this node
|
---|
136 | */
|
---|
137 | virtual GtpVisibility::OcclusionQuery *IssueOcclusionQuery(GtpVisibility::Mesh *mesh) = 0;
|
---|
138 |
|
---|
139 | /** Returns geometry of hierarchy node.
|
---|
140 | */
|
---|
141 | virtual void GetGeometry(GtpVisibility::HierarchyNode *node,
|
---|
142 | GeometryList *geometryList,
|
---|
143 | bool includeChildren) = 0;
|
---|
144 |
|
---|
145 |
|
---|
146 | /** Renders geometry.
|
---|
147 | */
|
---|
148 | virtual void RenderGeometry(GtpVisibility::Mesh *geom) = 0;
|
---|
149 |
|
---|
150 | protected:
|
---|
151 |
|
---|
152 | bool mUseOptimization;
|
---|
153 | unsigned int mFrameId;
|
---|
154 |
|
---|
155 | int mCurrentTestIdx;
|
---|
156 |
|
---|
157 | //--- statistics
|
---|
158 | unsigned int mNumTraversedNodes;
|
---|
159 |
|
---|
160 | DistanceQueue *mDistanceQueue;
|
---|
161 | HierarchyNode *mSceneRoot;
|
---|
162 | HierarchyNode *mPreviousNode;
|
---|
163 |
|
---|
164 | std::vector<HierarchyNode *> mRenderedNodes;
|
---|
165 | };
|
---|
166 | } // namespace GtpVisibility
|
---|
167 | #endif // GtpVisisibilityHierarchyInterface_H |
---|