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

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

orthocam not working yet

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