1 | #ifndef __RENDERTRAVERSER_H
|
---|
2 | #define __RENDERTRAVERSER_H
|
---|
3 |
|
---|
4 | #include <queue>
|
---|
5 | #include "Bvh.h"
|
---|
6 | #include "OcclusionQuery.h"
|
---|
7 | #include "Camera.h"
|
---|
8 | #include "RenderQueue.h"
|
---|
9 | #include "Timer/PerfTimer.h"
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 | namespace CHCDemoEngine
|
---|
14 | {
|
---|
15 |
|
---|
16 | class Camera;
|
---|
17 | class Matrix4x4;
|
---|
18 |
|
---|
19 |
|
---|
20 |
|
---|
21 | struct TraversalStatistics
|
---|
22 | {
|
---|
23 | public:
|
---|
24 |
|
---|
25 | void Reset();
|
---|
26 |
|
---|
27 | //////////
|
---|
28 | //-- several statistics for a rendering pass
|
---|
29 |
|
---|
30 | int mNumTraversedNodes;
|
---|
31 | int mNumQueryCulledNodes;
|
---|
32 | int mNumFrustumCulledNodes;
|
---|
33 |
|
---|
34 | int mNumRenderedGeometry;
|
---|
35 | int mNumRenderedTriangles;
|
---|
36 | int mNumRenderedNodes;
|
---|
37 |
|
---|
38 | int mNumIssuedQueries;
|
---|
39 | int mNumStateChanges;
|
---|
40 | int mNumBatches;
|
---|
41 |
|
---|
42 | double mWaitTime;
|
---|
43 | double mQueryTime;
|
---|
44 | double mRestTime;
|
---|
45 | };
|
---|
46 |
|
---|
47 |
|
---|
48 | /** Abstract class implementing a scene traversal for rendering.
|
---|
49 | */
|
---|
50 | class RenderTraverser
|
---|
51 | {
|
---|
52 | public:
|
---|
53 |
|
---|
54 | /** Default constructor.
|
---|
55 | */
|
---|
56 | RenderTraverser();
|
---|
57 | /** Virtual constructor, has to be redefined in subclasses
|
---|
58 | */
|
---|
59 | virtual ~RenderTraverser();
|
---|
60 | /** Abstract method that traverses and renders the scene
|
---|
61 | */
|
---|
62 | void RenderScene();
|
---|
63 |
|
---|
64 | enum {CULL_FRUSTUM, STOP_AND_WAIT, CHC, CHCPLUSPLUS, NUM_TRAVERSAL_TYPES};
|
---|
65 | /** Returns the type of the traversal.
|
---|
66 | The type is one of
|
---|
67 | CULL_FRUSTUM: view frustum culling only
|
---|
68 | STOP_AND_WAIT: hierarchical stop and wait algorithm
|
---|
69 | CHC: coherent hierarchical algorithm
|
---|
70 | CHCPLUSPLUS: coherent hierarchical algorithm revisited
|
---|
71 | */
|
---|
72 | virtual int GetType() const = 0;
|
---|
73 | /** Sets the scene hierarchy.
|
---|
74 | */
|
---|
75 | void SetHierarchy(Bvh *bvh);
|
---|
76 | /** Sets the camera.
|
---|
77 | */
|
---|
78 | void SetCamera(Camera *cam) { mCamera = cam;}
|
---|
79 | /** Sets the render queue.
|
---|
80 | */
|
---|
81 | void SetRenderQueue(RenderQueue *rq) {mRenderQueue =rq;}
|
---|
82 | /** Sets the current render state
|
---|
83 | */
|
---|
84 | void SetRenderState(RenderState *state);
|
---|
85 | /** The traversal statistics
|
---|
86 | */
|
---|
87 | const TraversalStatistics &GetStats() const { return mStats; }
|
---|
88 | /** The current frame id
|
---|
89 | */
|
---|
90 | int GetCurrentFrameId() const { return mFrameId; }
|
---|
91 |
|
---|
92 | //////////////////
|
---|
93 | //-- options for the different rendering algorithms
|
---|
94 |
|
---|
95 | /** If a render queue should be used to batch up and sort scene entities before
|
---|
96 | rendering.
|
---|
97 | */
|
---|
98 | void SetUseRenderQueue(bool useRenderQueue);
|
---|
99 | /** If depth pass should be used.
|
---|
100 | If true, the entities found visible in the current pass are stored
|
---|
101 | */
|
---|
102 | void SetUseDepthPass(bool storeVisibleObjects);
|
---|
103 | /** Sets visible pixels threshold for visibility classification
|
---|
104 | */
|
---|
105 | void SetVisibilityThreshold(int threshold);
|
---|
106 |
|
---|
107 | ///////////////////
|
---|
108 | //-- CHC / CHC ++ related options
|
---|
109 |
|
---|
110 | /** CHC optimization to query the geometry itself instead of the bounding box.
|
---|
111 | */
|
---|
112 | void SetUseOptimization(bool useOptimization);
|
---|
113 | /** The number of frames a previously visible node is assumed to stay visible.
|
---|
114 | */
|
---|
115 | void SetAssumedVisibleFrames(int assumedVisibleFrames);
|
---|
116 | /** The maximum batch size for the i-queue
|
---|
117 | */
|
---|
118 | void SetMaxBatchSize(int batchSize);
|
---|
119 | /** If multiqueries should be used.
|
---|
120 | */
|
---|
121 | void SetUseMultiQueries(bool useMultiQueries);
|
---|
122 | /** If thight bounds should be used or the bounding boxes should be tested.
|
---|
123 | */
|
---|
124 | void SetUseTightBounds(bool useTightBounds);
|
---|
125 | /** If bounds should be shown
|
---|
126 | */
|
---|
127 | void SetShowBounds(bool showBounds);
|
---|
128 | /** Returns the entities found visible in current frame
|
---|
129 | (only if StoreVisibleObjects is set)
|
---|
130 | */
|
---|
131 | const SceneEntityContainer &GetVisibleObjects() const { return mVisibleObjects; }
|
---|
132 | /** Returns the current camera.
|
---|
133 | */
|
---|
134 | Camera *GetCamera() const { return mCamera; }
|
---|
135 | /** Returns the maximal visible distance encountered in the scene.
|
---|
136 | Useful for e.g., shadow map focussing
|
---|
137 | */
|
---|
138 | float GetMaxVisibleDistance() const { return mMaxVisibleDistance; }
|
---|
139 |
|
---|
140 |
|
---|
141 | protected:
|
---|
142 |
|
---|
143 | /** This is the actual rendering algorithm. It must be implemented by all
|
---|
144 | the subclasses.
|
---|
145 | */
|
---|
146 | virtual void Traverse() = 0;
|
---|
147 | /** Hierarchy traversal
|
---|
148 | */
|
---|
149 | void TraverseNode(BvhNode *node);
|
---|
150 | /** Issues occlusion query for a single node
|
---|
151 | */
|
---|
152 | OcclusionQuery *IssueOcclusionQuery(BvhNode *node);
|
---|
153 | /** Issue multiquery.
|
---|
154 | */
|
---|
155 | void IssueOcclusionQuery(const OcclusionQuery &query);
|
---|
156 | /** Enqueues a bvh node for distance traversal
|
---|
157 | */
|
---|
158 | void EnqueueNode(BvhNode *node);
|
---|
159 | /** Renders the bvh node.
|
---|
160 | */
|
---|
161 | void RenderNode(BvhNode *node);
|
---|
162 | /** Renders and clears the contents of the render queue.
|
---|
163 | */
|
---|
164 | void ApplyRenderQueue();
|
---|
165 |
|
---|
166 |
|
---|
167 | ////////////
|
---|
168 | //-- members
|
---|
169 |
|
---|
170 | /// the current camera
|
---|
171 | Camera *mCamera;
|
---|
172 | /// the root of the scene hierarchy
|
---|
173 | Bvh *mBvh;
|
---|
174 | /// the priority queue used for front to back traversal
|
---|
175 | TraversalQueue mDistanceQueue;
|
---|
176 | /// the current frame id
|
---|
177 | int mFrameId;
|
---|
178 | /// the current render state
|
---|
179 | RenderState *mRenderState;
|
---|
180 | /// manages creation and destruction of the queries
|
---|
181 | QueryHandler mQueryHandler;
|
---|
182 | /// the statisitcs
|
---|
183 | TraversalStatistics mStats;
|
---|
184 |
|
---|
185 | RenderQueue *mRenderQueue;
|
---|
186 |
|
---|
187 | /// the objects found visible in current frame
|
---|
188 | SceneEntityContainer mVisibleObjects;
|
---|
189 | /// the maximal visible distance in the scene
|
---|
190 | float mMaxVisibleDistance;
|
---|
191 |
|
---|
192 | /////////////////
|
---|
193 | //-- algorithm parameters
|
---|
194 |
|
---|
195 | int mVisibilityThreshold;
|
---|
196 |
|
---|
197 | bool mUseOptimization;
|
---|
198 |
|
---|
199 | bool mUseRenderQueue;
|
---|
200 |
|
---|
201 | int mAssumedVisibleFrames;
|
---|
202 |
|
---|
203 | int mMaxBatchSize;
|
---|
204 |
|
---|
205 | bool mUseMultiQueries;
|
---|
206 |
|
---|
207 | bool mUseTightBounds;
|
---|
208 |
|
---|
209 | bool mShowBounds;
|
---|
210 |
|
---|
211 | bool mUseDepthPass;
|
---|
212 | };
|
---|
213 |
|
---|
214 |
|
---|
215 | }
|
---|
216 |
|
---|
217 |
|
---|
218 |
|
---|
219 | #endif // RENDERTRAVERSER_H |
---|