1 | #ifndef __RENDERTRAVERSER_H
|
---|
2 | #define __RENDERTRAVERSER_H
|
---|
3 |
|
---|
4 | #include <queue>
|
---|
5 | #include <stack>
|
---|
6 | #include "glInterface.h"
|
---|
7 | #include "Bvh.h"
|
---|
8 |
|
---|
9 | namespace CHCDemo
|
---|
10 | {
|
---|
11 |
|
---|
12 | class Camera;
|
---|
13 | class Matrix4x4;
|
---|
14 |
|
---|
15 |
|
---|
16 | struct TraversalStatistics
|
---|
17 | {
|
---|
18 | friend class RenderTraverser;
|
---|
19 |
|
---|
20 | public:
|
---|
21 |
|
---|
22 | //////////
|
---|
23 | //-- several statistics for a rendering pass
|
---|
24 |
|
---|
25 | long GetRenderTime();
|
---|
26 | int GetNumTraversedNodes();
|
---|
27 | int GetNumQueryCulledNodes();
|
---|
28 | int GetNumFrustumCulledNodes();
|
---|
29 | int GetNumRenderedGeometry();
|
---|
30 |
|
---|
31 | protected:
|
---|
32 |
|
---|
33 | // statistics
|
---|
34 | int mNumTraversedNodes;
|
---|
35 | int mNumQueryCulledNodes;
|
---|
36 | int mNumFrustumCulledNodes;
|
---|
37 | int mNumRenderedGeometry;
|
---|
38 |
|
---|
39 | long mRenderTime;
|
---|
40 | };
|
---|
41 |
|
---|
42 |
|
---|
43 | //typedef std::priority_queue<BvhNode *, std::vector<BvhNode *>, myless<std::vector<BvhNode *>::value_type> > TraversalQueue;
|
---|
44 | typedef std::priority_queue<BvhNode *, std::vector<BvhNode *>, myless> TraversalQueue;
|
---|
45 |
|
---|
46 | /** Abstract class implementing a scene traversal for rendering.
|
---|
47 | */
|
---|
48 | class RenderTraverser
|
---|
49 | {
|
---|
50 | public:
|
---|
51 | //enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES};
|
---|
52 |
|
---|
53 | RenderTraverser();
|
---|
54 | ~RenderTraverser();
|
---|
55 |
|
---|
56 | //! Renders the scene with the specified method
|
---|
57 | /**
|
---|
58 | The mode is one of
|
---|
59 | RENDER_CULL_FRUSTUM: renders the scene with view frustum culling only
|
---|
60 | RENDER_STOP_AND_WAIT: renders the scene with the hierarchical stop and wait algorithm
|
---|
61 | RENDER_COHERENT: renders the scene with the coherent hierarchical algorithm
|
---|
62 | */
|
---|
63 | virtual void Render() = 0;
|
---|
64 | /** Sets the scene hierarchy.
|
---|
65 | */
|
---|
66 | void SetHierarchy(Bvh *bvh);
|
---|
67 | /** Sets the camera.
|
---|
68 | */
|
---|
69 | void SetCamera(Camera *camera);
|
---|
70 | /** sets view projection matrix
|
---|
71 | */
|
---|
72 | //void SetProjViewMatrix(Matrix4x4 const &projViewMatrix);
|
---|
73 | /** Sets visible pixels threshold for visibility classification
|
---|
74 | */
|
---|
75 | void SetVisibilityThreshold(int threshold);
|
---|
76 | /** Returns visibility threshold
|
---|
77 | */
|
---|
78 | int GetVisibilityThreshold() const;
|
---|
79 | /** renders a visualization of the hierarchy
|
---|
80 | */
|
---|
81 | void RenderVisualization();
|
---|
82 | /** use optimization to take leaf nodes instead of bounding box for occlusion queries
|
---|
83 | */
|
---|
84 | void SetUseOptimization(bool useOptimization);
|
---|
85 |
|
---|
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 | */
|
---|
99 | void IssueOcclusionQuery(BvhNode *node, bool wasVisible);
|
---|
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 |
|
---|
113 | void EnqueueNode(BvhNode *node);
|
---|
114 |
|
---|
115 | ////////////
|
---|
116 | //-- members
|
---|
117 |
|
---|
118 | // /the current clip planes of the view frustum
|
---|
119 | //VecPlane mClipPlanes;
|
---|
120 | /// the indices of the np-vertices of the bounding box for view frustum culling
|
---|
121 | //int mNPVertexIndices[12];
|
---|
122 |
|
---|
123 | /// the current camera
|
---|
124 | Camera *mCamera;
|
---|
125 | //Matrix4x4 mProjViewMatrix;
|
---|
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;
|
---|
133 |
|
---|
134 | //unsigned int *mOcclusionQueries;
|
---|
135 | int mCurrentQueryIdx;
|
---|
136 | bool mIsQueryMode;
|
---|
137 |
|
---|
138 | //bool mIntersects;
|
---|
139 | bool mUseOptimization;
|
---|
140 | };
|
---|
141 |
|
---|
142 | }
|
---|
143 |
|
---|
144 |
|
---|
145 |
|
---|
146 | #endif // RENDERTRAVERSER_H |
---|