1 | #ifndef __RENDERTRAVERSER_H |
---|
2 | #define __RENDERTRAVERSER_H |
---|
3 | |
---|
4 | #include <queue> |
---|
5 | #include <stack> |
---|
6 | #include "glInterface.h" |
---|
7 | |
---|
8 | |
---|
9 | namespace CHCDemo
|
---|
10 | { |
---|
11 | |
---|
12 | class BvhNode; |
---|
13 | class Bvh; |
---|
14 | class Camera; |
---|
15 | class Matrix4x4; |
---|
16 | |
---|
17 | |
---|
18 | struct TraversalStatistics |
---|
19 | { |
---|
20 | friend class RenderTraverser; |
---|
21 | |
---|
22 | public: |
---|
23 | |
---|
24 | ////////// |
---|
25 | //-- several statistics for a rendering pass |
---|
26 | |
---|
27 | long GetRenderTime(); |
---|
28 | int GetNumTraversedNodes(); |
---|
29 | int GetNumQueryCulledNodes(); |
---|
30 | int GetNumFrustumCulledNodes(); |
---|
31 | int GetNumRenderedGeometry(); |
---|
32 | |
---|
33 | protected: |
---|
34 | |
---|
35 | // statistics |
---|
36 | int mNumTraversedNodes; |
---|
37 | int mNumQueryCulledNodes; |
---|
38 | int mNumFrustumCulledNodes; |
---|
39 | int mNumRenderedGeometry; |
---|
40 | |
---|
41 | long mRenderTime; |
---|
42 | }; |
---|
43 | |
---|
44 | |
---|
45 | //typedef std::priority_queue<BvhNode *, std::vector<BvhNode *>, myless<std::vector<BvhNode *>::value_type> > 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); |
---|
86 | |
---|
87 | protected: |
---|
88 | |
---|
89 | /** does some important initializations |
---|
90 | */ |
---|
91 | void Preprocess(); |
---|
92 | /** Hierarchy traversal |
---|
93 | */ |
---|
94 | void TraverseNode(BvhNode *node); |
---|
95 | /** Visibility is pulled up from visibility of children |
---|
96 | */ |
---|
97 | void PullUpVisibility(BvhNode *node); |
---|
98 | /** Issues occlusion query for specified node |
---|
99 | */ |
---|
100 | void IssueOcclusionQuery(BvhNode *node, bool wasVisible); |
---|
101 | /** Resets occlusion queries after a traversal |
---|
102 | */ |
---|
103 | void DelQueries(); |
---|
104 | /** Does view frustum culling. returns intersect (if intersects view plane) |
---|
105 | */ |
---|
106 | bool InsideViewFrustum(BvhNode *node, bool &intersects); |
---|
107 | /** switches to normal render mode |
---|
108 | */ |
---|
109 | void Switch2GLRenderState(); |
---|
110 | /** switches to occlusion query mode (geometry not rendered on the screen) |
---|
111 | */ |
---|
112 | void Switch2GLQueryState(); |
---|
113 | |
---|
114 | |
---|
115 | protected: |
---|
116 | |
---|
117 | // /the current clip planes of the view frustum |
---|
118 | //VecPlane mClipPlanes; |
---|
119 | /// the indices of the np-vertices of the bounding box for view frustum culling |
---|
120 | //int mNPVertexIndices[12]; |
---|
121 | |
---|
122 | /// the current camera |
---|
123 | Camera *mCamera; |
---|
124 | //Matrix4x4 mProjViewMatrix; |
---|
125 | /// the root of the scene hierarchy |
---|
126 | Bvh *mBvh; |
---|
127 | /// use a priority queue rather than a renderstack |
---|
128 | //PriorityQueue mDistanceQueue; |
---|
129 | |
---|
130 | int mFrameID; |
---|
131 | int mVisibilityThreshold; |
---|
132 | |
---|
133 | //unsigned int *mOcclusionQueries; |
---|
134 | int mCurrentQueryIdx; |
---|
135 | bool mIsQueryMode; |
---|
136 | |
---|
137 | //bool mIntersects; |
---|
138 | bool mUseOptimization; |
---|
139 | }; |
---|
140 | |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | |
---|
145 | #endif // RENDERTRAVERSER_H |
---|