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