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

Revision 2642, 4.1 KB checked in by mattausch, 17 years ago (diff)

new demo

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