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

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