source: trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneTraverser.h @ 51

Revision 51, 5.8 KB checked in by mattausch, 19 years ago (diff)
Line 
1#ifndef _OcclusionCullingSceneTraverser_H__
2#define _OcclusionCullingSceneTraverser_H__
3
4#include "OgreSceneNode.h"
5#include "OgreSceneManager.h"
6#include "OgrePrerequisites.h"
7#include "OgreSolidHalfBoundingBox.h"
8#include "OgreCamera.h"
9#include "OgreRenderSystem.h"
10#include <queue>
11
12using namespace std;
13
14namespace Ogre {
15        /**
16                This class implements the compare operator for the priority queue.
17                a lower distance has a higher value in the queue
18        */
19        template <typename T> class myless
20        {
21        public:
22                myless(Camera *cam) { mCamera = cam; }
23                //bool operator() (HierarchyNode *v1, HierarchyNode *v2) const
24                bool operator() (T v1, T v2) const
25                {
26                        return v1->getSquaredViewDepth(mCamera) > v2->getSquaredViewDepth(mCamera);
27                }
28        private:
29                Camera *mCamera;
30        };
31
32        typedef pair<SceneNode *, HardwareOcclusionQuery *> QueryPair;
33        typedef priority_queue<SceneNode *, vector<SceneNode *>, myless<vector<SceneNode *>::value_type> > PriorityQueue;
34        typedef queue<QueryPair> QueryQueue;
35        /**
36                Class which implements a scene mangager which uses occlusion queries for culling occluded objects
37        */
38        class OcclusionCullingSceneTraverser
39        {
40        public:
41                /** Construction taking the current scene manager and the current rendersystem as argument
42                @param sm current scene manager
43                @param rsys current render system
44                */
45                OcclusionCullingSceneTraverser(SceneManager *sm, RenderSystem *rsys);
46                ~OcclusionCullingSceneTraverser();
47       
48                enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES};
49               
50                /** Renders the scene with the specified algorithm
51                        @comment
52                        The algorithm type can be set with the parameter "Algorithm" and setOption.
53
54                        The algorithm is one of:
55                        RENDER_CULL_FRUSTUM: renders the scene with view frustum culling only
56                        RENDER_STOP_AND_WAIT: renders the scene with the hierarchical stop and wait algorithm
57                        RENDER_COHERENT: renders the scene with the coherent hierarchical algorithm
58                       
59                        @param cam current camera
60                */
61                void renderScene( Camera *cam );
62       
63                /** Sets the given option for the scene traverser.
64                               @remarks
65                        Options are:
66                        "Algorithm", int *;                     
67                */
68                bool setOption( const String &, const void * );
69                /** Gets the given option for the scene traverser.
70                @remarks
71                    See setOption
72                */
73                bool getOption( const String &, void * );
74                bool getOptionKeys( StringVector &refKeys );
75               
76                /** Sets pointer to the current scene manager.
77                @param the scene manager */
78                void setSceneManager( SceneManager *sm );
79               
80                /** Sets pointer to the current render system
81                @param the rendersystem */
82                void setRenderSystem( RenderSystem *rsys );
83               
84                /** Sets the current number of scene nodes in the scene.
85                @param num number of scene nodes
86                */
87                void setNumSceneNodes(int num );
88
89                /** Sets the root of the scene hierarchy. */
90                void setSceneRoot(SceneNode *root);
91
92                /** Sets the required number of occlusion queries.
93                @param num number occlusion queries
94                */
95                //void setNumQueries( int num );
96
97                /** Doing some necessary preprocessing.
98                @comment e.g., initialises occlusion queries */
99                //void preprocess( void );
100
101        protected:
102                /** query mode (= without color) or RENDER_MODE */
103                enum {MODE_QUERY, MODE_RENDER};
104                /** returns true if node is leaf of the hierarchy */
105                bool isLeaf( SceneNode *node );
106                //HACK
107                //unsigned int countSceneNodes(SceneNode *node);
108                void traverseNode( Camera *cam, SceneNode *node );
109                /** Renders current scene node
110                @param cam current camera
111                @param node current scene node to be rendered
112                */
113                void renderSceneNode( Camera *cam, SceneNode *node);
114                /** Sets rendering mode, e.g. query mode or render mode*/
115                void setRenderingMode( int mode );
116               
117               
118                /** Renders the scene with view frustum culling only. */
119                virtual void renderCullFrustum( Camera *cam );
120                /** Renders the scene with the hierarchical stop and wait algorithm. */
121                virtual void renderStopAndWait( Camera *cam );
122                /** Renders the scene with the coherent hierarchical algorithm and the query queye. */
123                virtual void renderCoherentWithQueue( Camera *cam );
124
125                /** Issue a occlusion query for this node.
126                @param box the axis aligned bounding box of the node
127                @wasVisible if the node was visible in previous frame
128                */
129                HardwareOcclusionQuery *issueOcclusionQuery( AxisAlignedBox *box, bool wasVisible );
130                /** Returns next available occlusion query or creates new one.
131                @return the next occlusion query
132                */
133                HardwareOcclusionQuery *getNextOcclusionQuery(void);
134                /** Pulls up the visibility from the child nodes. */
135                void pullUpVisibility( Camera *cam, SceneNode *node );
136                /** delete all previously defined occlusion queries */
137                void deleteQueries();
138                /** Renders bounding box of specified node.
139                @param box the bounding box of the scene node to be rendered */
140                void renderBoundingBox( AxisAlignedBox *box );
141                /** Returns one half of the bounding box.
142                @param half the half index of the bouding box (0 or 1)
143                */
144                SolidHalfBoundingBox *getSolidHalfBoundingBox( int half );
145
146                /** Initialises the distance queue. */
147                virtual void initDistanceQueue(Camera *cam);
148               
149                std::vector<HardwareOcclusionQuery *> mOcclusionQueries;
150                // two halfes of a aabb
151                SolidHalfBoundingBox *mHalfBoundingBox[2];     
152
153                int mCurrentAlgorithm;
154
155                unsigned int mFrameId;
156                unsigned int mVisibilityThreshold;
157               
158                SceneManager *mSceneManager;
159                RenderSystem *mRenderSystem;
160       
161                int mCurrentTestIdx;
162                int mQueryMode;
163
164                unsigned int mNumQueries;
165
166                //--- statistics
167                unsigned int mNumSceneNodes;
168                unsigned int mNumTraversedNodes;
169                unsigned int mNumQueryCulledNodes;
170                unsigned int mNumFrustumCulledNodes;
171                unsigned int mNumRenderedGeometry;
172                unsigned int mNumRenderedNodes;
173
174        private:
175                // the scene root
176                SceneNode *mSceneRoot;
177                // we use a priority queue ordered by distance
178                PriorityQueue *mDistanceQueue;
179        };
180
181}
182#endif // OCCLUSIONCULLINGSCENEMANAGER_H
Note: See TracBrowser for help on using the repository browser.