source: branches/VUT/0.2/chcdemo/RenderTraverser.h @ 22

Revision 22, 3.8 KB checked in by gametools, 20 years ago (diff)
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
60protected:
61
62        //! renders the scene with view frustum culling only
63        void RenderCullFrustum();
64        //! renders the scene with the hierarchical stop and wait algorithm
65        void RenderStopAndWait();
66        //! renders the scene with the coherent hierarchical algorithm and the query queye
67        void RenderCoherentWithQueue();
68        //! does some importand initialisations
69        void Preprocess();
70       
71        //! returns occlusion query result for specified node
72        int GetOcclusionQueryResult(HierarchyNode *node);
73        //! the node is traversed as usual
74        void TraverseNode(HierarchyNode *node);
75        //! visibility is pulled up from visibility of children
76        void PullUpVisibility(HierarchyNode *node);
77        //! is result available from query queue?
78        bool ResultAvailable(HierarchyNode *node);
79        //! issues occlusion query for specified node
80        void IssueOcclusionQuery(HierarchyNode *node, bool wasVisible);
81        //! resets occlusion queries after a traversal
82        void ResetQueries();
83        //! does view frustum culling. returns intersect (if intersects view plane)
84        bool InsideViewFrustum(HierarchyNode *node, bool &intersects);
85        //! switches to normal render mode
86        void Switch2GLRenderState();
87        //! switches to occlusion query mode (geometry not rendered on the screen)
88        void Switch2GLQueryState();
89
90protected:
91
92        // the current clip planes of the view frustum
93        VecPlane mClipPlanes;
94        // the indices of the np-vertices of the bounding box for view frustum culling
95        int mNPVertexIndices[12];
96
97        Vector3 mViewpoint;
98        Matrix4x4 mProjViewMatrix;
99        HierarchyNode *mHierarchyRoot;
100        //TraversalStack mTraversalStack;
101        PriorityQueue mDistanceQueue; // use a priority queue rather than a renderstack
102       
103        //priority_queue<vector<HierarchyNode *>, HierarchyNode *> mPriorityQueue;
104        int mFrameID;
105        int mVisibilityThreshold;
106        unsigned int *mOcclusionQueries;
107        int mCurrentTestIdx;
108        bool mIsQueryMode;
109       
110        bool mIntersects;
111
112        // statistics
113        int mNumTraversedNodes;
114        int mNumQueryCulledNodes;
115        int mNumFrustumCulledNodes;
116        int mNumRenderedGeometry;
117
118        long mRenderTime;
119
120        bool mUseOptimization;
121};
122
123#endif // RENDERTRAVERSER_H
Note: See TracBrowser for help on using the repository browser.