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

Revision 2763, 3.8 KB checked in by mattausch, 16 years ago (diff)
RevLine 
[2755]1#ifndef __RENDERTRAVERSER_H
2#define __RENDERTRAVERSER_H
3
4#include <queue>
5#include <stack>
6#include "glInterface.h"
7#include "Bvh.h"
[2763]8#include "OcclusionQuery.h"
[2755]9
[2763]10
[2754]11namespace CHCDemo
[2755]12{
13
14class Camera;
15class Matrix4x4;
16
17
[2760]18
[2755]19struct TraversalStatistics
20{
21        friend class RenderTraverser;
22
23public:
24
25        //////////
26        //-- several statistics for a rendering pass
27
28        long GetRenderTime();
29        int GetNumTraversedNodes();
30        int GetNumQueryCulledNodes();
31        int GetNumFrustumCulledNodes();
32        int GetNumRenderedGeometry();
33       
34protected:
35
36        // statistics
37        int mNumTraversedNodes;
38        int mNumQueryCulledNodes;
39        int mNumFrustumCulledNodes;
40        int mNumRenderedGeometry;
41
42        long mRenderTime;
43};
44
45
46//typedef std::priority_queue<BvhNode *, std::vector<BvhNode *>, myless<std::vector<BvhNode *>::value_type> > TraversalQueue;
47typedef std::priority_queue<BvhNode *, std::vector<BvhNode *>, myless> TraversalQueue;
48
49/** Abstract class implementing a scene traversal for rendering.
50*/
51class RenderTraverser
52{
53public:
54        //enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES};
55
56        RenderTraverser();
57        ~RenderTraverser();
58
59        //! Renders the scene with the specified method
60        /**
61                The mode is one of
62                RENDER_CULL_FRUSTUM: renders the scene with view frustum culling only
63                RENDER_STOP_AND_WAIT: renders the scene with the hierarchical stop and wait algorithm
64                RENDER_COHERENT: renders the scene with the coherent hierarchical algorithm
65        */
66        virtual void Render() = 0;
67        /** Sets the scene hierarchy.
68        */
69        void SetHierarchy(Bvh *bvh);
70        /** Sets the camera.
71        */
[2762]72        void SetCamera(Camera *cam)  {mCamera = cam;}
[2755]73        /** sets view projection matrix
74        */
75        //void SetProjViewMatrix(Matrix4x4 const &projViewMatrix);
76        /** Sets visible pixels threshold for visibility classification
77        */
78        void SetVisibilityThreshold(int threshold);
79        /** Returns visibility threshold
80        */
81        int GetVisibilityThreshold() const;
82        /** renders a visualization of the hierarchy
83        */
84        void RenderVisualization();
85        /** use optimization to take leaf nodes instead of bounding box for occlusion queries   
86        */
87        void SetUseOptimization(bool useOptimization);
[2760]88        /** Sets the current render state
89        */
90        void SetRenderState(RenderState *state);
[2762]91       
92        void RenderFrustum();
[2755]93
[2760]94
[2755]95protected:
96
97        /** does some important initializations
98        */
99        void Preprocess();
100        /** Hierarchy traversal
101        */
102        void TraverseNode(BvhNode *node);
103        /** Visibility is pulled up from visibility of children
104        */
105        void PullUpVisibility(BvhNode *node);
106        /** Issues occlusion query for specified node
107        */
[2763]108        OcclusionQuery *IssueOcclusionQuery(BvhNode *node, bool wasVisible);
[2755]109        /** Resets occlusion queries after a traversal
110        */
111        void DelQueries();
112        /** Does view frustum culling. returns intersect (if intersects view plane)
113        */
114        bool InsideViewFrustum(BvhNode *node, bool &intersects);
115        /** switches to normal render mode
116        */
117        void Switch2GLRenderState();
118        /** switches to occlusion query mode (geometry not rendered on the screen)
119        */
120        void Switch2GLQueryState();
121
122        void EnqueueNode(BvhNode *node);
123
[2762]124        void RenderBox(const AxisAlignedBox3 &box);
[2760]125
[2762]126
127
[2755]128        ////////////
129        //-- members
130
131        // /the current clip planes of the view frustum
132        //VecPlane mClipPlanes;
133        /// the indices of the np-vertices of the bounding box for view frustum culling
134        //int mNPVertexIndices[12];
135
136        /// the current camera
137        Camera *mCamera;
138        //Matrix4x4 mProjViewMatrix;
139        /// the root of the scene hierarchy
140        Bvh *mBvh;
141        /// use a priority queue rather than a renderstack
142        TraversalQueue mDistanceQueue;
143       
144        int mFrameID;
145        int mVisibilityThreshold;
146       
147        //unsigned int *mOcclusionQueries;
148        int mCurrentQueryIdx;
149        bool mIsQueryMode;
150       
151        //bool mIntersects;
152        bool mUseOptimization;
[2760]153
154        RenderState *mRenderState;
[2763]155
156        QueryHandler mQueryHandler;
[2755]157};
158
159}
160
161
162
[2642]163#endif // RENDERTRAVERSER_H
Note: See TracBrowser for help on using the repository browser.