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

Revision 2795, 4.3 KB checked in by mattausch, 17 years ago (diff)
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
10
11
12namespace CHCDemoEngine
13{
14
15class Camera;
16class Matrix4x4;
17
18
19
20struct TraversalStatistics
21{
22public:
23
24        void Reset();
25
26        //////////
27        //-- several statistics for a rendering pass
28
29        int mNumTraversedNodes;
30        int mNumQueryCulledNodes;
31        int mNumFrustumCulledNodes;
32       
33        int mNumRenderedGeometry;
34        int mNumRenderedTriangles;
35        int mNumRenderedNodes;
36
37        int mNumIssuedQueries;
38        int mNumStateChanges;
39       
40        double mRenderTime;
41};
42
43
44
45/** Abstract class implementing a scene traversal for rendering.
46*/
47class RenderTraverser
48{
49public:
50       
51        enum {CULL_FRUSTUM, STOP_AND_WAIT, CHC, CHCPLUSPLUS, NUM_RENDERMODES};
52
53        RenderTraverser();
54        ~RenderTraverser();
55
56        //! Renders the scene with the specified method
57        /**
58                The method is one of
59                CULL_FRUSTUM: view frustum culling only
60                STOP_AND_WAIT: hierarchical stop and wait algorithm
61                CHC: coherent hierarchical algorithm
62                CHCPLUSPLUS: coherent hierarchical algorithm revisited
63        */
64        void RenderScene();
65        /** Sets the scene hierarchy.
66        */
67        void SetHierarchy(Bvh *bvh);
68        /** Sets the camera.
69        */
70        void SetCamera(Camera *cam)  {mCamera = cam;}
71        /** Renders a visualization of the hierarchy
72        */
73        void RenderVisualization();
74        /** Sets the current render state
75        */
76        void SetRenderState(RenderState *state);
77        /** The traversal statistics
78        */
79        const TraversalStatistics &GetStats() const { return mStats; }
80        /** The current frame id
81        */
82        int GetCurrentFrameId() const { return mFrameId; }
83
84
85        //////////////////
86        //-- options for the different rendering algorithms
87
88        /** If a render queue should be used to batch up and sort scene entities before
89                rendering.
90        */
91        void SetUseRenderQueue(bool useRenderQueue);
92        /** Sets visible pixels threshold for visibility classification
93        */
94        void SetVisibilityThreshold(int threshold);
95
96
97        ///////////////////
98        //-- CHC / CHC ++ related options
99
100
101        /** CHC optimization to query the geometry itself instead of the bounding box.
102        */
103        void SetUseOptimization(bool useOptimization);
104        /** The number of frames a previously visible node is assumed to stay visible.
105        */
106        void SetAssumedVisibleFrames(int assumedVisibleFrames);
107        /** The maximum batch size for the i-queue
108        */
109        void SetMaxBatchSize(int batchSize);
110        /** If multiqueries should be used.
111        */
112        void SetUseMultiQueries(bool useMultiQueries);
113        /** If thight bounds should be used or the bounding boxes should be tested.
114        */
115        void SetUseTightBounds(bool useTightBounds);
116        /** If bounds should be shown
117        */
118        void SetShowBounds(bool showBounds);
119
120       
121protected:
122
123        /** This is the actual rendering algorithm. It must be implemented by all
124                the subclasses.
125        */
126        virtual void Traverse() = 0;
127        /** Hierarchy traversal
128        */
129        void TraverseNode(BvhNode *node);
130        /** Issues occlusion query for a single node
131        */
132        OcclusionQuery *IssueOcclusionQuery(BvhNode *node);
133        /** Issue multiquery.
134        */
135        void IssueOcclusionQuery(const OcclusionQuery &query);
136        /** Retunrs true if the current bvh node intersects the near plane.
137        */
138        inline bool IntersectsNearPlane(BvhNode *node) const;
139        /** Enqueues a bvh node for distance traversal
140        */
141        void EnqueueNode(BvhNode *node);
142        /** Renders the bvh node.
143        */
144        void RenderNode(BvhNode *node);
145        /** Renders and clears the contents of the render queue.
146        */
147        void ApplyRenderQueue();
148
149
150        ////////////
151        //-- members
152
153        /// the current camera
154        Camera *mCamera;
155        /// the root of the scene hierarchy
156        Bvh *mBvh;
157        /// the priority queue used for front to back traversal
158        TraversalQueue mDistanceQueue;
159        /// the current frame id
160        int mFrameId;
161        /// the current render state
162        RenderState *mRenderState;
163        /// manages creation and destruction of the queries
164        QueryHandler mQueryHandler;
165        /// the statisitcs
166        TraversalStatistics mStats;
167       
168        RenderQueue mRenderQueue;
169
170
171        /////////////////
172        //-- algorithm parametes
173
174        int mVisibilityThreshold;
175       
176        bool mUseOptimization;
177
178        bool mUseRenderQueue;
179
180        int mAssumedVisibleFrames;
181
182        int mMaxBatchSize;
183
184        bool mUseMultiQueries;
185
186        bool mUseTightBounds;
187
188        bool mShowBounds;
189};
190
191
192inline bool RenderTraverser::IntersectsNearPlane(BvhNode *node) const
193{
194        return mBvh->GetDistance(node) < mCamera->GetNear();
195}
196
197
198}
199
200
201
202#endif // RENDERTRAVERSER_H
Note: See TracBrowser for help on using the repository browser.