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

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