source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h @ 3284

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