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

Revision 32, 4.5 KB checked in by gametools, 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 *> query_pair;
33        typedef priority_queue<SceneNode *, vector<SceneNode *>, myless<vector<SceneNode *>::value_type> > PriorityQueue;
34        typedef queue<query_pair> 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                OcclusionCullingSceneTraverser();
42                ~OcclusionCullingSceneTraverser();
43       
44                enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES};
45               
46                /** Overriden from SceneManager. Renders the scene with the specified algorithm
47                /**
48                        The algorithm is one of
49                        RENDER_CULL_FRUSTUM: renders the scene with view frustum culling only
50                        RENDER_STOP_AND_WAIT: renders the scene with the hierarchical stop and wait algorithm
51                        RENDER_COHERENT: renders the scene with the coherent hierarchical algorithm
52                */
53               
54                /** Sets the given option for the SceneTraverser
55                               @remarks
56                        Options are:
57                        "Algorithm", int *;                     
58                */
59                bool setOption( const String &, const void * );
60                /** Gets the given option for the SceneTraverser.
61                @remarks
62                    See setOption
63                */
64                bool getOption( const String &, void * );
65
66                /** Renders current scene
67                @param cam current camera
68                @param root root of hierarchy */
69                void renderScene(  Camera *cam, SceneNode *root );
70
71                /** Sets the scene manager */
72                void setSceneManager( SceneManager *sm );
73                /** Sets the render system */
74                void setRenderSystem( RenderSystem *rsys );
75
76                void preprocess( void );
77
78        protected:
79                enum {MODE_QUERY, MODE_RENDER};
80                /** returns true if node is leaf of the hierarchy */
81                bool isLeaf( SceneNode *node );
82                //HACK
83                //unsigned int countSceneNodes(SceneNode *node);
84                void traverseNode( Camera *cam, SceneNode *node );
85                /** Renders current scene node
86                @param cam current camera
87                @param node current scene node to be rendered
88                */
89                void renderSceneNode( Camera *cam, SceneNode *node);
90                /** Sets rendering mode, e.g. query mode or render mode*/
91                void setRenderingMode( int mode );
92                /** Renders the scene with view frustum culling only. */
93                void renderCullFrustum( Camera *cam );
94                /** Renders the scene with the hierarchical stop and wait algorithm. */
95                void renderStopAndWait( Camera *cam );
96                /** Renders the scene with the coherent hierarchical algorithm and the query queye. */
97                void renderCoherentWithQueue( Camera *cam );
98                /** Issue a occlusion query for this node. */
99                HardwareOcclusionQuery *issueOcclusionQuery( SceneNode *node, bool wasVisible );
100                /** Pulls up the visibility from the child nodes. */
101                void pullUpVisibility( SceneNode *node );
102                /** delete all previously defined occlusion queries */
103                void deleteQueries();
104                /** Renders bounding box of specified node.
105                @param the scene node contained in the bounding box to be rendered
106                */
107                void renderBoundingBox( SceneNode *node );
108                /** Returns one half of the bounding box.
109                @param the half of the bouding box
110                */
111                SolidHalfBoundingBox *getSolidHalfBoundingBox( int half );
112
113                // we use a priority queue rather than a renderstack
114                PriorityQueue *mDistanceQueue;
115               
116                std::vector<HardwareOcclusionQuery *> mOcclusionQueries;
117                // two halfes of a aabb
118                SolidHalfBoundingBox *mHalfBoundingBox[2];     
119
120                int mCurrentAlgorithm;
121
122                unsigned int mFrameId;
123                unsigned int mVisibilityThreshold;
124               
125                SceneManager *mSceneManager;
126                RenderSystem *mRenderSystem;
127
128                int mCurrentTestIdx;
129                int mQueryMode;
130
131                //--- statistics
132                unsigned int mNumSceneNodes;
133                unsigned int mNumTraversedNodes;
134                unsigned int mNumQueryCulledNodes;
135                unsigned int mNumFrustumCulledNodes;
136                unsigned int mNumRenderedGeometry;
137        };
138
139}
140#endif // OCCLUSIONCULLINGSCENEMANAGER_H
Note: See TracBrowser for help on using the repository browser.