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

Revision 3147, 5.3 KB checked in by mattausch, 16 years ago (diff)

updated shader loading

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