source: GTP/trunk/App/Demos/Vis/Teapots/RenderTraverser.h @ 724

Revision 724, 4.1 KB checked in by mattausch, 18 years ago (diff)

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