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