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