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

Revision 3147, 5.3 KB checked in by mattausch, 16 years ago (diff)

updated shader loading

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