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