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

Revision 2751, 4.1 KB checked in by mattausch, 16 years ago (diff)
Line 
1#ifndef RENDERTRAVERSER_H
2#define RENDERTRAVERSER_H
3
4
5
6#if TOIMPLEMENT
7
8#include "glInterface.h"
9#include "HierarchyNode.h"
10
11#include <queue>
12#include <stack>
13
14namespace CHCDemo
15{
16
17typedef stack<HierarchyNode *> TraversalStack;
18typedef queue<HierarchyNode *> QueryQueue;
19typedef priority_queue<HierarchyNode *, vector<HierarchyNode *>, myless<vector<HierarchyNode *>::value_type> > PriorityQueue;
20
21class RenderTraverser
22{
23public:
24        enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES};
25
26        RenderTraverser();
27        ~RenderTraverser();
28
29        //! Renders the scene with the specified method
30        /**
31                The mode is one of
32                RENDER_CULL_FRUSTUM: renders the scene with view frustum culling only
33                RENDER_STOP_AND_WAIT: renders the scene with the hierarchical stop and wait algorithm
34                RENDER_COHERENT: renders the scene with the coherent hierarchical algorithm
35        */
36        void Render(int mode=RENDER_CULL_FRUSTUM);
37        //! sets the scene hierarchy.
38        void SetHierarchy(HierarchyNode *sceneRoot);
39        //! sets viewpoint
40        void SetViewpoint(Vector3 const &viewpoint);
41        //! sets view projection matrix
42        void SetProjViewMatrix(Matrix4x4 const &projViewMatrix);
43        //! returns root of hierarchy
44        HierarchyNode *GetHierarchy();
45        //! sets visible pixels threshold for visibility classification
46        void SetVisibilityThreshold(int threshold);
47        //! returns visibility threshold
48        int GetVisibilityThreshold();
49
50        // several statistics for a rendering pass
51        long GetRenderTime();
52        int GetNumTraversedNodes();
53        int GetNumQueryCulledNodes();
54        int GetNumFrustumCulledNodes();
55        int GetNumRenderedGeometry();
56
57        //! renders a visualization of the hierarchy
58        void RenderVisualization();
59
60        //! use optimization to take leaf nodes instead of bounding box for occlusion queries   
61        void SetUseOptimization(bool useOptimization);
62
63        //! if arb queries should be used instead of nv
64        void SetUseArbQueries(const bool useArbQueries);
65        //!     see set
66        bool GetUseArbQueries() const;
67
68protected:
69
70        //! renders the scene with view frustum culling only
71        void RenderCullFrustum();
72        //! renders the scene with the hierarchical stop and wait algorithm
73        void RenderStopAndWait();
74        //! renders the scene with the coherent hierarchical algorithm and the query queye
75        void RenderCoherentWithQueue();
76        //! does some importand initialisations
77        void Preprocess();
78       
79        //! returns occlusion query result for specified node
80        unsigned int GetOcclusionQueryResult(HierarchyNode *node) const;
81        //! the node is traversed as usual
82        void TraverseNode(HierarchyNode *node);
83        //! visibility is pulled up from visibility of children
84        void PullUpVisibility(HierarchyNode *node);
85        //! is result available from query queue?
86        bool ResultAvailable(HierarchyNode *node) const;
87        //! issues occlusion query for specified node
88        void IssueOcclusionQuery(HierarchyNode *node, bool wasVisible);
89        //! resets occlusion queries after a traversal
90        void DelQueries();
91        //! does view frustum culling. returns intersect (if intersects view plane)
92        bool InsideViewFrustum(HierarchyNode *node, bool &intersects);
93        //! switches to normal render mode
94        void Switch2GLRenderState();
95        //! switches to occlusion query mode (geometry not rendered on the screen)
96        void Switch2GLQueryState();
97
98
99protected:
100
101        /// if arb queries should be instead of nv
102        bool mUseArbQueries;
103
104        // the current clip planes of the view frustum
105        VecPlane mClipPlanes;
106        // the indices of the np-vertices of the bounding box for view frustum culling
107        int mNPVertexIndices[12];
108
109        // the current view point
110        Vector3 mViewpoint;
111        Matrix4x4 mProjViewMatrix;
112        // the root of the scene hierarchy
113        HierarchyNode *mHierarchyRoot;
114        //TraversalStack mTraversalStack;
115        PriorityQueue mDistanceQueue; // use a priority queue rather than a renderstack
116       
117        //priority_queue<vector<HierarchyNode *>, HierarchyNode *> mPriorityQueue;
118        int mFrameID;
119        int mVisibilityThreshold;
120        unsigned int *mOcclusionQueries;
121        int mCurrentQueryIdx;
122        bool mIsQueryMode;
123       
124        bool mIntersects;
125
126        // statistics
127        int mNumTraversedNodes;
128        int mNumQueryCulledNodes;
129        int mNumFrustumCulledNodes;
130        int mNumRenderedGeometry;
131
132        long mRenderTime;
133
134        bool mUseOptimization;
135};
136
137}
138
139#endif
140
141
142#endif // RENDERTRAVERSER_H
Note: See TracBrowser for help on using the repository browser.