source: GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h @ 2776

Revision 2776, 4.0 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
82
83        //////////////////
84        //-- options for the different rendering algorithms
85
86        /** If a render queue should be used to batch up and sort scene entities before
87                rendering.
88        */
89        void SetUseRenderQueue(bool useRenderQueue);
90        /** Sets visible pixels threshold for visibility classification
91        */
92        void SetVisibilityThreshold(int threshold);
93
94
95        ///////////////////
96        //-- CHC / CHC ++ related options
97
98
99        /** CHC optimization to query the geometry itself instead of the bounding box.
100        */
101        void SetUseOptimization(bool useOptimization);
102        /** The number of frames a previously visible node is assumed to stay visible.
103        */
104        void SetAssumedVisibleFrames(int assumedVisibleFrames);
105        /** The maximum batch size for the i-queue
106        */
107        void SetMaxBatchSize(int batchSize);
108        /** If multiqueries should be used.
109        */
110        void SetUseMultiQueries(bool useMultiQueries);
111
112protected:
113
114        /** This is the actual rendering algorithm. It must be implemented by all
115                the subclasses.
116        */
117        virtual void Traverse() = 0;
118        /** Hierarchy traversal
119        */
120        void TraverseNode(BvhNode *node);
121        /** Issues occlusion query for a single node
122        */
123        OcclusionQuery *IssueOcclusionQuery(BvhNode *node, bool wasVisible);
124        /** Issue multiquery.
125        */
126        void IssueOcclusionQuery(const OcclusionQuery &query, bool wasVisible);
127        /** Retunrs true if the current bvh node intersects the near plane.
128        */
129        inline bool IntersectsNearPlane(BvhNode *node) const;
130        /** Enqueues a bvh node for distance traversal
131        */
132        void EnqueueNode(BvhNode *node);
133        /** Renders the bvh node.
134        */
135        void RenderNode(BvhNode *node);
136
137
138        ////////////
139        //-- members
140
141        /// the current camera
142        Camera *mCamera;
143        /// the root of the scene hierarchy
144        Bvh *mBvh;
145        /// the priority queue used for front to back traversal
146        TraversalQueue mDistanceQueue;
147        /// the current frame id
148        int mFrameId;
149        /// the current render state
150        RenderState *mRenderState;
151        /// manages creation and destruction of the queries
152        QueryHandler mQueryHandler;
153        /// the statisitcs
154        TraversalStatistics mStats;
155       
156        RenderQueue mRenderQueue;
157
158
159        /////////////////
160        //-- algorithm parametes
161
162        int mVisibilityThreshold;
163       
164        bool mUseOptimization;
165
166        bool mUseRenderQueue;
167
168        int mAssumedVisibleFrames;
169
170        int mMaxBatchSize;
171
172        bool mUseMultiQueries;
173};
174
175
176inline bool RenderTraverser::IntersectsNearPlane(BvhNode *node) const
177{
178        return mBvh->GetDistance(node) < mCamera->GetNear();
179}
180
181
182}
183
184
185
186#endif // RENDERTRAVERSER_H
Note: See TracBrowser for help on using the repository browser.