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

Revision 3284, 5.7 KB checked in by mattausch, 15 years ago (diff)
RevLine 
[2755]1#ifndef __RENDERTRAVERSER_H
2#define __RENDERTRAVERSER_H
3
[3258]4
[2755]5#include "Bvh.h"
[2763]6#include "OcclusionQuery.h"
[3258]7//#include "Timer/PerfTimer.h"
8#include <queue>
[2755]9
[2767]10
[2776]11namespace CHCDemoEngine
[2755]12{
13
[3258]14
[2755]15class Camera;
[3258]16class RenderQueue;
[2755]17
18
19struct TraversalStatistics
20{
21public:
22
[2764]23        void Reset();
24
[2755]25        //////////
26        //-- several statistics for a rendering pass
27
28        int mNumTraversedNodes;
29        int mNumQueryCulledNodes;
30        int mNumFrustumCulledNodes;
[2773]31       
[2755]32        int mNumRenderedGeometry;
[2764]33        int mNumRenderedTriangles;
[2773]34        int mNumRenderedNodes;
35
[2764]36        int mNumIssuedQueries;
[2770]37        int mNumStateChanges;
[2800]38        int mNumBatches;
39
40        double mWaitTime;
41        double mQueryTime;
42        double mRestTime;
[2755]43};
44
45
46/** Abstract class implementing a scene traversal for rendering.
47*/
48class RenderTraverser
49{
50public:
51
[3147]52        /// types of traversers
[3258]53        enum {CULL_FRUSTUM,
54                  STOP_AND_WAIT,
55                  CHC, CHCPLUSPLUS,
[3284]56                  //CULL_COLLECTOR,
[3258]57                  NUM_TRAVERSAL_TYPES};
[3147]58
[2801]59        /** Default constructor.
60        */
[2755]61        RenderTraverser();
[3258]62        /** Virtual constructor, has to be redefined in subclasses.
[2801]63        */
64        virtual ~RenderTraverser();
[3258]65        /** Maim method that traverses and renders the scene.
[2801]66        */
67        void RenderScene();
[2755]68
[2801]69        /** Returns the type of the traversal.
70            The type is one of
[2767]71                CULL_FRUSTUM: view frustum culling only
72                STOP_AND_WAIT: hierarchical stop and wait algorithm
73                CHC: coherent hierarchical algorithm
74                CHCPLUSPLUS: coherent hierarchical algorithm revisited
[2755]75        */
[2801]76        virtual int GetType() const = 0;
[2755]77        /** Sets the scene hierarchy.
78        */
79        void SetHierarchy(Bvh *bvh);
80        /** Sets the camera.
81        */
[3258]82        void SetCamera(Camera *cam);
[2801]83        /** Sets the render queue.
84        */
[3258]85        void SetRenderQueue(RenderQueue *rq);
86        /** Sets the current render state.
[2760]87        */
88        void SetRenderState(RenderState *state);
[2771]89        /** The traversal statistics
90        */
[3258]91        const TraversalStatistics &GetStats() const;
[2787]92        /** The current frame id
93        */
[3258]94        inline int GetCurrentFrameId() const;
[2801]95       
[3258]96
97
[2771]98        //////////////////
[3258]99        //-- methods that concern one or more of the implemented rendering algorithms
[2771]100
101        /** If a render queue should be used to batch up and sort scene entities before
102                rendering.
103        */
[2767]104        void SetUseRenderQueue(bool useRenderQueue);
[2801]105        /** If depth pass should be used.
106                If true, the entities found visible in the current pass are stored
107        */
108        void SetUseDepthPass(bool storeVisibleObjects);
[2771]109        /** Sets visible pixels threshold for visibility classification
110        */
111        void SetVisibilityThreshold(int threshold);
[2760]112
[3258]113
[2771]114        ///////////////////
115        //-- CHC / CHC ++ related options
[3258]116        //-- note: could be implemented more cleanly in a CoherentOcclusionCullingTraverser parent class!
[2771]117
118        /** CHC optimization to query the geometry itself instead of the bounding box.
119        */
120        void SetUseOptimization(bool useOptimization);
121        /** The number of frames a previously visible node is assumed to stay visible.
122        */
123        void SetAssumedVisibleFrames(int assumedVisibleFrames);
124        /** The maximum batch size for the i-queue
125        */
126        void SetMaxBatchSize(int batchSize);
[2776]127        /** If multiqueries should be used.
128        */
129        void SetUseMultiQueries(bool useMultiQueries);
[2786]130        /** If thight bounds should be used or the bounding boxes should be tested.
131        */
132        void SetUseTightBounds(bool useTightBounds);
[2790]133        /** If bounds should be shown
134        */
135        void SetShowBounds(bool showBounds);
[2801]136        /** Returns the entities found visible in current frame
137            (only if StoreVisibleObjects is set)
138        */
[3258]139        const SceneEntityContainer &GetVisibleObjects() const;
[2897]140        /** Returns the current camera.
141        */
[3258]142        Camera *GetCamera() const;
[2947]143        /** Returns the maximal visible distance encountered in the scene.
144            Useful for e.g., shadow map focussing
145        */
[3258]146        float GetMaxVisibleDistance() const;
147        /** Render objects declared as dynamic (non-static)
[3102]148        */
149        void SetRenderDynamicObjects(bool dynamic);
[2771]150
[2897]151
[2755]152protected:
153
[2767]154        /** This is the actual rendering algorithm. It must be implemented by all
155                the subclasses.
[2755]156        */
[2767]157        virtual void Traverse() = 0;
[2755]158        /** Hierarchy traversal
159        */
160        void TraverseNode(BvhNode *node);
[2773]161        /** Issues occlusion query for a single node
[2755]162        */
[2792]163        OcclusionQuery *IssueOcclusionQuery(BvhNode *node);
[2773]164        /** Issue multiquery.
165        */
[2792]166        void IssueOcclusionQuery(const OcclusionQuery &query);
[2770]167        /** Enqueues a bvh node for distance traversal
[2767]168        */
[2755]169        void EnqueueNode(BvhNode *node);
[2770]170        /** Renders the bvh node.
171        */
172        void RenderNode(BvhNode *node);
[2795]173        /** Renders and clears the contents of the render queue.
174        */
175        void ApplyRenderQueue();
[3258]176        /** Returns true if at least one of the objects in this node are
177                marked as visible. maxSize describes the maximum sized node
178                (in # of objects) that is tested. if maxSize is -1, all nodes are tested.
179        */
180        bool IsNodeGeometryVisible(BvhNode *node, int maxSize);
[2755]181
[2760]182
[2755]183        ////////////
184        //-- members
185
186        /// the current camera
187        Camera *mCamera;
188        /// the root of the scene hierarchy
189        Bvh *mBvh;
[2767]190        /// the priority queue used for front to back traversal
[2755]191        TraversalQueue mDistanceQueue;
[2767]192        /// the current frame id
[2765]193        int mFrameId;
[2771]194        /// the current render state
[2760]195        RenderState *mRenderState;
[2771]196        /// manages creation and destruction of the queries
[2763]197        QueryHandler mQueryHandler;
[2771]198        /// the statisitcs
[2764]199        TraversalStatistics mStats;
[3258]200        /// the render queue
[2801]201        RenderQueue *mRenderQueue;
202        /// the objects found visible in current frame
203        SceneEntityContainer mVisibleObjects;
[2947]204        /// the maximal visible distance in the scene
205        float mMaxVisibleDistance;
[2801]206
[3258]207
[2771]208        /////////////////
[2947]209        //-- algorithm parameters
[2771]210
[2767]211        int mVisibilityThreshold;
212       
213        bool mUseOptimization;
214
215        bool mUseRenderQueue;
[2770]216
217        int mAssumedVisibleFrames;
[2771]218
219        int mMaxBatchSize;
[2776]220
221        bool mUseMultiQueries;
[2786]222
223        bool mUseTightBounds;
[2790]224
225        bool mShowBounds;
[2800]226
[2801]227        bool mUseDepthPass;
[3102]228
229        bool mRenderDynamicObjects;
[2755]230};
231
[2767]232
[3258]233inline int RenderTraverser::GetCurrentFrameId() const
234{
235        return mFrameId;
[2755]236}
237
238
[3258]239}
[2801]240
[3258]241
242
[2642]243#endif // RENDERTRAVERSER_H
Note: See TracBrowser for help on using the repository browser.