[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;
|
---|
[155] | 16 | typedef std::stack<HierarchyNode *> TraversalStack;
|
---|
[130] | 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 | */
|
---|
[155] | 35 | virtual void TraverseAndRenderNode(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;
|
---|
| 58 | /** Sets the scene root and initialises this hierarchy interface for a traversal.
|
---|
| 59 | @param frontToBack
|
---|
| 60 | if traversal is initialised for front-to-back rendering or
|
---|
| 61 | simple traversal of the nodes.
|
---|
| 62 | @remark also resets the statistics evaluated in the last traversal
|
---|
[59] | 63 | */
|
---|
[155] | 64 | void InitTraversal(bool frontToBack = true);
|
---|
[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 | */
|
---|
| 100 | virtual void SetNodeVisible(HierarchyNode *node, const bool visible) = 0;
|
---|
| 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,
|
---|
| 109 | const unsigned int frameId) = 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,
|
---|
| 126 | CullingType type) = NULL;
|
---|
[111] | 127 |
|
---|
[130] | 128 | /** Returns vector of previously rendered hierarchy nodes.
|
---|
| 129 | */
|
---|
| 130 | std::vector<HierarchyNode *> *GetRenderedNodes();
|
---|
| 131 | /** Returns vector of previoulsy rendered geometry.
|
---|
| 132 | */
|
---|
| 133 |
|
---|
| 134 | /** Issue a occlusion query for this mesh.
|
---|
| 135 | @param node the current mesh
|
---|
| 136 | @returns occlusion query for this node
|
---|
| 137 | */
|
---|
| 138 | virtual GtpVisibility::OcclusionQuery *IssueOcclusionQuery(GtpVisibility::Mesh *mesh) = 0;
|
---|
| 139 |
|
---|
[155] | 140 | /** Returns the geometry of a given hierarchy node.
|
---|
| 141 | @param node the hierarchy node containing the geometry
|
---|
| 142 | @param geometryList geometry is returned in this list
|
---|
| 143 | @param includeChildren if the geometry of the children should be taken into account
|
---|
[130] | 144 | */
|
---|
[155] | 145 | virtual void GetNodeGeometryList(GtpVisibility::HierarchyNode *node,
|
---|
[130] | 146 | GeometryList *geometryList,
|
---|
| 147 | bool includeChildren) = 0;
|
---|
| 148 |
|
---|
| 149 |
|
---|
[154] | 150 | /** Renders the given geometry.
|
---|
[130] | 151 | */
|
---|
| 152 | virtual void RenderGeometry(GtpVisibility::Mesh *geom) = 0;
|
---|
| 153 |
|
---|
[154] | 154 | /** Sets node id to specified value.
|
---|
| 155 | */
|
---|
| 156 | virtual void SetNodeId(HierarchyNode *node, int id) = 0;
|
---|
| 157 | /** Returns id of given node.
|
---|
| 158 | */
|
---|
| 159 | virtual int GetNodeId(HierarchyNode *node) = 0;
|
---|
[155] | 160 |
|
---|
| 161 | /** This is an optimization when issuing the occlusion test.
|
---|
| 162 | The test is done with actual geometry rather than the bounding
|
---|
| 163 | box of leave nodes previously marked as visible
|
---|
| 164 | @param testGeometry if this optimization should be used
|
---|
| 165 | @remark this option is only useful for the coherent hierarchical culling algorithm
|
---|
| 166 | */
|
---|
| 167 | void TestGeometryForVisibleLeaves(bool testGeometry);
|
---|
| 168 |
|
---|
| 169 | /**
|
---|
| 170 | Traverses hierarchy and returns next node.
|
---|
| 171 | @returns next node in hierarchy.
|
---|
| 172 | */
|
---|
| 173 | virtual HierarchyNode *GetNextNode() = 0;
|
---|
| 174 |
|
---|
[59] | 175 | protected:
|
---|
[155] | 176 | /// chc optimization for testing geometry of leaves instead of bounding box
|
---|
| 177 | bool mTestGeometryForVisibleLeaves;
|
---|
| 178 |
|
---|
[59] | 179 | unsigned int mFrameId;
|
---|
| 180 |
|
---|
| 181 | int mCurrentTestIdx;
|
---|
| 182 |
|
---|
[155] | 183 | /// number of traversed nodes
|
---|
[59] | 184 | unsigned int mNumTraversedNodes;
|
---|
[155] | 185 | /// the distance queue used for rendering of nodes in front to back order.
|
---|
[59] | 186 | DistanceQueue *mDistanceQueue;
|
---|
[155] | 187 | /// internal structure for traversal
|
---|
| 188 | TraversalStack *mTraversalStack;
|
---|
[111] | 189 |
|
---|
[155] | 190 | /// the root of the hierarchy
|
---|
| 191 | HierarchyNode *mHierarchyRoot;
|
---|
| 192 |
|
---|
| 193 | // buffer for a node pointer
|
---|
| 194 | HierarchyNode *mSavedNode;
|
---|
| 195 |
|
---|
[130] | 196 | std::vector<HierarchyNode *> mRenderedNodes;
|
---|
[59] | 197 | };
|
---|
| 198 | } // namespace GtpVisibility
|
---|
[155] | 199 |
|
---|
[112] | 200 | #endif // GtpVisisibilityHierarchyInterface_H |
---|