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

Revision 2802, 5.2 KB checked in by mattausch, 17 years ago (diff)

worked on renderqueue

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        /** 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        /** Renders a visualization of the hierarchy
83        */
84        void RenderVisualization();
85        /** Sets the current render state
86        */
87        void SetRenderState(RenderState *state);
88        /** The traversal statistics
89        */
90        const TraversalStatistics &GetStats() const { return mStats; }
91        /** The current frame id
92        */
93        int GetCurrentFrameId() const { return mFrameId; }
94       
95        //////////////////
96        //-- options for the different rendering algorithms
97
98        /** If a render queue should be used to batch up and sort scene entities before
99                rendering.
100        */
101        void SetUseRenderQueue(bool useRenderQueue);
102        /** If depth pass should be used.
103                If true, the entities found visible in the current pass are stored
104        */
105        void SetUseDepthPass(bool storeVisibleObjects);
106        /** Sets visible pixels threshold for visibility classification
107        */
108        void SetVisibilityThreshold(int threshold);
109
110        ///////////////////
111        //-- CHC / CHC ++ related options
112
113        /** CHC optimization to query the geometry itself instead of the bounding box.
114        */
115        void SetUseOptimization(bool useOptimization);
116        /** The number of frames a previously visible node is assumed to stay visible.
117        */
118        void SetAssumedVisibleFrames(int assumedVisibleFrames);
119        /** The maximum batch size for the i-queue
120        */
121        void SetMaxBatchSize(int batchSize);
122        /** If multiqueries should be used.
123        */
124        void SetUseMultiQueries(bool useMultiQueries);
125        /** If thight bounds should be used or the bounding boxes should be tested.
126        */
127        void SetUseTightBounds(bool useTightBounds);
128        /** If bounds should be shown
129        */
130        void SetShowBounds(bool showBounds);
131        /** Returns the entities found visible in current frame
132            (only if StoreVisibleObjects is set)
133        */
134        const SceneEntityContainer &GetVisibleObjects() const { return mVisibleObjects; }
135
136protected:
137
138        /** This is the actual rendering algorithm. It must be implemented by all
139                the subclasses.
140        */
141        virtual void Traverse() = 0;
142        /** Hierarchy traversal
143        */
144        void TraverseNode(BvhNode *node);
145        /** Issues occlusion query for a single node
146        */
147        OcclusionQuery *IssueOcclusionQuery(BvhNode *node);
148        /** Issue multiquery.
149        */
150        void IssueOcclusionQuery(const OcclusionQuery &query);
151        /** Retunrs true if the current bvh node intersects the near plane.
152        */
153        inline bool IntersectsNearPlane(BvhNode *node) const;
154        /** Enqueues a bvh node for distance traversal
155        */
156        void EnqueueNode(BvhNode *node);
157        /** Renders the bvh node.
158        */
159        void RenderNode(BvhNode *node);
160        /** Renders and clears the contents of the render queue.
161        */
162        void ApplyRenderQueue();
163
164
165        ////////////
166        //-- members
167
168        /// the current camera
169        Camera *mCamera;
170        /// the root of the scene hierarchy
171        Bvh *mBvh;
172        /// the priority queue used for front to back traversal
173        TraversalQueue mDistanceQueue;
174        /// the current frame id
175        int mFrameId;
176        /// the current render state
177        RenderState *mRenderState;
178        /// manages creation and destruction of the queries
179        QueryHandler mQueryHandler;
180        /// the statisitcs
181        TraversalStatistics mStats;
182       
183        RenderQueue *mRenderQueue;
184
185        /// the objects found visible in current frame
186        SceneEntityContainer mVisibleObjects;
187
188
189        /////////////////
190        //-- algorithm parametes
191
192        int mVisibilityThreshold;
193       
194        bool mUseOptimization;
195
196        bool mUseRenderQueue;
197
198        int mAssumedVisibleFrames;
199
200        int mMaxBatchSize;
201
202        bool mUseMultiQueries;
203
204        bool mUseTightBounds;
205
206        bool mShowBounds;
207
208        bool mUseDepthPass;
209};
210
211
212inline bool RenderTraverser::IntersectsNearPlane(BvhNode *node) const
213{
214        return mBvh->GetDistance(node) < mCamera->GetNear();
215}
216
217
218
219}
220
221
222
223#endif // RENDERTRAVERSER_H
Note: See TracBrowser for help on using the repository browser.