[2755] | 1 | #ifndef __RENDERTRAVERSER_H
|
---|
| 2 | #define __RENDERTRAVERSER_H
|
---|
| 3 |
|
---|
| 4 | #include <queue>
|
---|
| 5 | #include <stack>
|
---|
| 6 | #include "glInterface.h"
|
---|
| 7 | #include "Bvh.h"
|
---|
[2763] | 8 | #include "OcclusionQuery.h"
|
---|
[2764] | 9 | #include "Camera.h"
|
---|
[2755] | 10 |
|
---|
[2754] | 11 | namespace CHCDemo
|
---|
[2755] | 12 | {
|
---|
| 13 |
|
---|
| 14 | class Camera;
|
---|
| 15 | class Matrix4x4;
|
---|
| 16 |
|
---|
| 17 |
|
---|
[2760] | 18 |
|
---|
[2755] | 19 | struct TraversalStatistics
|
---|
| 20 | {
|
---|
| 21 | public:
|
---|
| 22 |
|
---|
[2764] | 23 | void Reset();
|
---|
| 24 |
|
---|
[2755] | 25 | //////////
|
---|
| 26 | //-- several statistics for a rendering pass
|
---|
| 27 |
|
---|
| 28 | int mNumTraversedNodes;
|
---|
| 29 | int mNumQueryCulledNodes;
|
---|
| 30 | int mNumFrustumCulledNodes;
|
---|
| 31 | int mNumRenderedGeometry;
|
---|
[2764] | 32 | int mNumRenderedTriangles;
|
---|
| 33 | int mNumIssuedQueries;
|
---|
[2755] | 34 |
|
---|
| 35 | long mRenderTime;
|
---|
| 36 | };
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | //typedef std::priority_queue<BvhNode *, std::vector<BvhNode *>, myless<std::vector<BvhNode *>::value_type> > TraversalQueue;
|
---|
| 40 | typedef std::priority_queue<BvhNode *, std::vector<BvhNode *>, myless> TraversalQueue;
|
---|
| 41 |
|
---|
| 42 | /** Abstract class implementing a scene traversal for rendering.
|
---|
| 43 | */
|
---|
| 44 | class RenderTraverser
|
---|
| 45 | {
|
---|
| 46 | public:
|
---|
[2764] | 47 | enum {CULL_FRUSTUM, STOP_AND_WAIT, CHC, NUM_RENDERMODES};
|
---|
[2755] | 48 |
|
---|
| 49 | RenderTraverser();
|
---|
| 50 | ~RenderTraverser();
|
---|
| 51 |
|
---|
| 52 | //! Renders the scene with the specified method
|
---|
| 53 | /**
|
---|
| 54 | The mode is one of
|
---|
| 55 | RENDER_CULL_FRUSTUM: renders the scene with view frustum culling only
|
---|
| 56 | RENDER_STOP_AND_WAIT: renders the scene with the hierarchical stop and wait algorithm
|
---|
| 57 | RENDER_COHERENT: renders the scene with the coherent hierarchical algorithm
|
---|
| 58 | */
|
---|
| 59 | virtual void Render() = 0;
|
---|
| 60 | /** Sets the scene hierarchy.
|
---|
| 61 | */
|
---|
| 62 | void SetHierarchy(Bvh *bvh);
|
---|
| 63 | /** Sets the camera.
|
---|
| 64 | */
|
---|
[2762] | 65 | void SetCamera(Camera *cam) {mCamera = cam;}
|
---|
[2755] | 66 | /** Sets visible pixels threshold for visibility classification
|
---|
| 67 | */
|
---|
| 68 | void SetVisibilityThreshold(int threshold);
|
---|
| 69 | /** Returns visibility threshold
|
---|
| 70 | */
|
---|
| 71 | int GetVisibilityThreshold() const;
|
---|
| 72 | /** renders a visualization of the hierarchy
|
---|
| 73 | */
|
---|
| 74 | void RenderVisualization();
|
---|
| 75 | /** use optimization to take leaf nodes instead of bounding box for occlusion queries
|
---|
| 76 | */
|
---|
| 77 | void SetUseOptimization(bool useOptimization);
|
---|
[2760] | 78 | /** Sets the current render state
|
---|
| 79 | */
|
---|
| 80 | void SetRenderState(RenderState *state);
|
---|
[2762] | 81 |
|
---|
| 82 | void RenderFrustum();
|
---|
[2755] | 83 |
|
---|
[2764] | 84 | const TraversalStatistics &GetStats() const { return mStats; }
|
---|
[2760] | 85 |
|
---|
[2755] | 86 | protected:
|
---|
| 87 |
|
---|
| 88 | /** does some important initializations
|
---|
| 89 | */
|
---|
| 90 | void Preprocess();
|
---|
| 91 | /** Hierarchy traversal
|
---|
| 92 | */
|
---|
| 93 | void TraverseNode(BvhNode *node);
|
---|
| 94 | /** Visibility is pulled up from visibility of children
|
---|
| 95 | */
|
---|
| 96 | void PullUpVisibility(BvhNode *node);
|
---|
| 97 | /** Issues occlusion query for specified node
|
---|
| 98 | */
|
---|
[2763] | 99 | OcclusionQuery *IssueOcclusionQuery(BvhNode *node, bool wasVisible);
|
---|
[2755] | 100 | /** Resets occlusion queries after a traversal
|
---|
| 101 | */
|
---|
| 102 | void DelQueries();
|
---|
| 103 | /** Does view frustum culling. returns intersect (if intersects view plane)
|
---|
| 104 | */
|
---|
| 105 | bool InsideViewFrustum(BvhNode *node, bool &intersects);
|
---|
| 106 | /** switches to normal render mode
|
---|
| 107 | */
|
---|
| 108 | void Switch2GLRenderState();
|
---|
| 109 | /** switches to occlusion query mode (geometry not rendered on the screen)
|
---|
| 110 | */
|
---|
| 111 | void Switch2GLQueryState();
|
---|
| 112 |
|
---|
[2764] | 113 | inline bool IntersectsNearPlane(BvhNode *node) const {return mBvh->GetDistance(node) < mCamera->GetNear();}
|
---|
| 114 |
|
---|
[2755] | 115 | void EnqueueNode(BvhNode *node);
|
---|
| 116 |
|
---|
[2762] | 117 | void RenderBox(const AxisAlignedBox3 &box);
|
---|
[2760] | 118 |
|
---|
[2762] | 119 |
|
---|
| 120 |
|
---|
[2755] | 121 | ////////////
|
---|
| 122 | //-- members
|
---|
| 123 |
|
---|
| 124 | /// the current camera
|
---|
| 125 | Camera *mCamera;
|
---|
| 126 | /// the root of the scene hierarchy
|
---|
| 127 | Bvh *mBvh;
|
---|
| 128 | /// use a priority queue rather than a renderstack
|
---|
| 129 | TraversalQueue mDistanceQueue;
|
---|
| 130 |
|
---|
| 131 | int mFrameID;
|
---|
| 132 | int mVisibilityThreshold;
|
---|
[2764] | 133 |
|
---|
[2755] | 134 | bool mIsQueryMode;
|
---|
| 135 |
|
---|
| 136 | //bool mIntersects;
|
---|
| 137 | bool mUseOptimization;
|
---|
[2760] | 138 |
|
---|
| 139 | RenderState *mRenderState;
|
---|
[2763] | 140 |
|
---|
| 141 | QueryHandler mQueryHandler;
|
---|
[2764] | 142 |
|
---|
| 143 | TraversalStatistics mStats;
|
---|
[2755] | 144 | };
|
---|
| 145 |
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 |
|
---|
| 149 |
|
---|
[2642] | 150 | #endif // RENDERTRAVERSER_H |
---|