[59] | 1 | #ifndef _GtpVisibilityHierarchyInterface_H__
|
---|
| 2 | #define _GtpVisibilityHierarchyInterface_H__
|
---|
| 3 |
|
---|
| 4 | #include "DistanceQueue.h"
|
---|
[130] | 5 | #include "VisibilityMesh.h"
|
---|
[59] | 6 |
|
---|
| 7 | namespace GtpVisibility {
|
---|
| 8 |
|
---|
[112] | 9 | enum CullingType {QUERY_CULLED, FRUSTUM_CULLED};
|
---|
| 10 |
|
---|
[130] | 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 |
|
---|
[59] | 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 | */
|
---|
[74] | 29 | virtual bool IsLeaf(HierarchyNode *node) const = 0;
|
---|
[59] | 30 | /** Traverses the given node.
|
---|
| 31 | @param node the hierarchy node
|
---|
| 32 | */
|
---|
| 33 | virtual void TraverseNode(HierarchyNode *node) = 0;
|
---|
[130] | 34 | /** Renders current hierarchy node.
|
---|
| 35 | @param node current hierarchy node to be rendered
|
---|
[59] | 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 | */
|
---|
[86] | 46 | virtual OcclusionQuery *IssueOcclusionQuery(HierarchyNode *node,
|
---|
| 47 | const bool wasVisible = false) = 0;
|
---|
[59] | 48 | /** Sets the root of the scene hierarchy.
|
---|
| 49 | @param root the hierarchy root
|
---|
| 50 | */
|
---|
| 51 | void SetSceneRoot(HierarchyNode *root);
|
---|
[74] | 52 | /** Get the root of the scene hierarchy.
|
---|
| 53 | @return the hierarchy root
|
---|
| 54 | */
|
---|
| 55 | HierarchyNode *GetSceneRoot() const;
|
---|
[59] | 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 | */
|
---|
[74] | 64 | unsigned int GetFrameId() const;
|
---|
[59] | 65 | /** Returns the current distance queue.
|
---|
| 66 | @returns current distance queue
|
---|
| 67 | */
|
---|
| 68 | DistanceQueue *GetQueue();
|
---|
[87] | 69 | /** Returns distance of the node to the view plane.
|
---|
| 70 | @param node1 the hierarchy node
|
---|
[59] | 71 | */
|
---|
[87] | 72 | virtual float GetSquaredDistance(HierarchyNode *node) const = 0;
|
---|
[59] | 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;
|
---|
[74] | 78 | /** Checks if the node is visible from the current view frustum.
|
---|
| 79 | @param node the current node
|
---|
| 80 | */
|
---|
| 81 | bool CheckFrustumVisible(HierarchyNode *node);
|
---|
[59] | 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 | */
|
---|
[74] | 90 | virtual bool HasGeometry(HierarchyNode *node) const = 0;
|
---|
[59] | 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 | */
|
---|
[74] | 98 | virtual bool IsNodeVisible(HierarchyNode *node) const = 0;
|
---|
[59] | 99 | /** Sets the last visited frame id for this node.
|
---|
| 100 | @param node the current node
|
---|
| 101 | @param frameId the current frame id
|
---|
| 102 | */
|
---|
[74] | 103 | virtual void SetLastVisited(HierarchyNode *node,
|
---|
| 104 | const unsigned int frameId) = 0;
|
---|
[59] | 105 | /** Returns frame id when this node was last visited by the traverser. See set
|
---|
| 106 | */
|
---|
[74] | 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();
|
---|
[86] | 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);
|
---|
[112] | 119 | //bool mIsShadowPass;
|
---|
[59] | 120 |
|
---|
[112] | 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;
|
---|
[111] | 126 |
|
---|
[130] | 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 |
|
---|
[154] | 146 | /** Renders the given geometry.
|
---|
[130] | 147 | */
|
---|
| 148 | virtual void RenderGeometry(GtpVisibility::Mesh *geom) = 0;
|
---|
| 149 |
|
---|
[154] | 150 | /** Sets node id to specified value.
|
---|
| 151 | */
|
---|
| 152 | virtual void SetNodeId(HierarchyNode *node, int id) = 0;
|
---|
| 153 | /** Returns id of given node.
|
---|
| 154 | */
|
---|
| 155 | virtual int GetNodeId(HierarchyNode *node) = 0;
|
---|
[59] | 156 | protected:
|
---|
| 157 |
|
---|
[86] | 158 | bool mUseOptimization;
|
---|
[59] | 159 | unsigned int mFrameId;
|
---|
| 160 |
|
---|
| 161 | int mCurrentTestIdx;
|
---|
| 162 |
|
---|
| 163 | //--- statistics
|
---|
| 164 | unsigned int mNumTraversedNodes;
|
---|
| 165 |
|
---|
| 166 | DistanceQueue *mDistanceQueue;
|
---|
| 167 | HierarchyNode *mSceneRoot;
|
---|
[85] | 168 | HierarchyNode *mPreviousNode;
|
---|
[111] | 169 |
|
---|
[130] | 170 | std::vector<HierarchyNode *> mRenderedNodes;
|
---|
[59] | 171 | };
|
---|
| 172 | } // namespace GtpVisibility
|
---|
[112] | 173 | #endif // GtpVisisibilityHierarchyInterface_H |
---|