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

Revision 2762, 3.7 KB checked in by mattausch, 16 years ago (diff)

debug version

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