source: trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneManager.h @ 29

Revision 29, 3.9 KB checked in by gametools, 19 years ago (diff)
Line 
1#ifndef _OcclusionCullingSceneManager_H__
2#define _OcclusionCullingSceneManager_H__
3
4#include "OgreSceneNode.h"
5#include "OgreSceneManager.h"
6#include "OgrePrerequisites.h"
7#include "OgreSolidHalfBoundingBox.h"
8#include <queue>
9
10using namespace std;
11
12namespace Ogre {
13        /**
14                This class implements the compare operator for the priority queue.
15                a lower distance has a higher value in the queue
16        */
17        template <typename T> class myless
18        {
19        public:
20                myless(Camera *cam) { mCamera = cam; }
21                //bool operator() (HierarchyNode *v1, HierarchyNode *v2) const
22                bool operator() (T v1, T v2) const
23                {
24                        return v1->getSquaredViewDepth(mCamera) > v2->getSquaredViewDepth(mCamera);
25                }
26        private:
27                Camera *mCamera;
28        };
29
30        typedef pair<SceneNode *, HardwareOcclusionQuery *> query_pair;
31        typedef priority_queue<SceneNode *, vector<SceneNode *>, myless<vector<SceneNode *>::value_type> > PriorityQueue;
32        typedef queue<query_pair> QueryQueue;
33        /**
34                Class which implements a scene mangager which uses occlusion queries for culling occluded objects
35        */
36        class OcclusionCullingSceneManager : public SceneManager
37        {
38        public:
39                OcclusionCullingSceneManager();
40                ~OcclusionCullingSceneManager();
41       
42                enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES};
43               
44                /** Overriden from SceneManager. Renders the scene with the specified algorithm
45                /**
46                        The algorithm is one of
47                        RENDER_CULL_FRUSTUM: renders the scene with view frustum culling only
48                        RENDER_STOP_AND_WAIT: renders the scene with the hierarchical stop and wait algorithm
49                        RENDER_COHERENT: renders the scene with the coherent hierarchical algorithm
50                */
51                void _renderVisibleObjects(void);
52                void _findVisibleObjects(Camera* cam, bool onlyShadowCasters);
53                void _updateSceneGraph(Camera* cam);
54
55                /** Sets the given option for the SceneManager
56                               @remarks
57                        Options are:
58                        "Algorithm", int *;                     
59                */
60                virtual bool setOption( const String &, const void * );
61                /** Gets the given option for the Scene Manager.
62                @remarks
63                    See setOption
64                */
65                virtual bool getOption( const String &, void * );
66
67                bool getOptionValues( const String & key, StringVector &refValueList );
68                bool getOptionKeys( StringVector &refKeys );
69
70        protected:
71                enum {MODE_QUERY, MODE_RENDER};
72
73                int isLeaf(SceneNode *node);
74                int countSceneNodes(SceneNode *node);
75                void renderZPass();
76                void traverseNode(SceneNode *node);
77                /** Renders current node */
78                void render(SceneNode *node);
79                /** Sets rendering mode, e.g. query mode or render mode*/
80                void setRenderingMode(int mode);
81               
82                /** Renders the scene with view frustum culling only. */
83                void renderCullFrustum();
84                /** Renders the scene with the hierarchical stop and wait algorithm. */
85                void renderStopAndWait();
86                /** Renders the scene with the coherent hierarchical algorithm and the query queye. */
87                void renderCoherentWithQueue();
88                /** Issue a occlusion query for this node. */
89                HardwareOcclusionQuery *issueOcclusionQuery(SceneNode *node, bool wasVisible);
90                /** Pulls up the visibility from the child nodes. */
91                void pullUpVisibility(SceneNode *node);
92                /** delete all previously defined occlusion queries */
93                void deleteQueries();
94                /** Renders bounding box of specified node.
95                @param the node which bounding box is to be rendered
96                */
97                void renderBoundingBox(SceneNode *node);
98                /** Returns one half of the bounding box.
99                @param the half of the bouding box
100                */
101                SolidHalfBoundingBox *getSolidHalfBoundingBox(int half);
102               
103
104                // we use a priority queue rather than a renderstack
105                PriorityQueue *mDistanceQueue;
106               
107                unsigned int mFrameId;
108                unsigned int mVisibilityThreshold;
109                unsigned int mNumSceneNodes;
110                int mCurrentTestIdx;
111                int mQueryMode;
112               
113                std::vector<HardwareOcclusionQuery *> mOcclusionQueries;
114                // two halfes of a aabb
115                SolidHalfBoundingBox *mHalfBoundingBox[2];     
116                int mCurrentAlgorithm;
117        };
118
119}
120#endif // OCCLUSIONCULLINGSCENEMANAGER_H
Note: See TracBrowser for help on using the repository browser.