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

Revision 26, 3.6 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
43                enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES};
44               
45                /** Overriden from SceneManager. Renders the scene with the specified algorithm
46                /**
47                        The algorithm is one of
48                        RENDER_CULL_FRUSTUM: renders the scene with view frustum culling only
49                        RENDER_STOP_AND_WAIT: renders the scene with the hierarchical stop and wait algorithm
50                        RENDER_COHERENT: renders the scene with the coherent hierarchical algorithm
51                */
52                void _renderVisibleObjects(void);
53                void _findVisibleObjects(Camera* cam, bool onlyShadowCasters);
54                void _updateSceneGraph(Camera* cam);
55
56        protected:
57                enum {MODE_QUERY, MODE_RENDER};
58
59                int isLeaf(SceneNode *node);
60                int countSceneNodes(SceneNode *node);
61                void renderZPass();
62                void traverseNode(SceneNode *node);
63                /** Renders current node */
64                void render(SceneNode *node);
65                /** Sets rendering mode, e.g. query mode or render mode*/
66                void setRenderingMode(int mode);
67               
68                /** Renders the scene with view frustum culling only. */
69                void renderCullFrustum();
70                /** Renders the scene with the hierarchical stop and wait algorithm. */
71                void renderStopAndWait();
72                /** Renders the scene with the coherent hierarchical algorithm and the query queye. */
73                void renderCoherentWithQueue();
74                /** Issue a occlusion query for this node. */
75                HardwareOcclusionQuery *issueOcclusionQuery(SceneNode *node, bool wasVisible);
76                /** Pulls up the visibility from the child nodes. */
77                void pullUpVisibility(SceneNode *node);
78                /** delete all previously defined occlusion queries */
79                void deleteQueries();
80                /** Renders bounding box of specified node.
81                @param the node which bounding box is to be rendered
82                */
83                void renderBoundingBox(SceneNode *node);
84                /** Returns one half of the bounding box.
85                @param the half of the bouding box
86                */
87                SolidHalfBoundingBox *getSolidHalfBoundingBox(int half);
88                /** sets the type of the algorithm
89                @param algorithm type
90                */
91                void setAlgorithmType(int type);
92       
93                int getAlgorithmType();
94
95                // we use a priority queue rather than a renderstack
96                PriorityQueue *mDistanceQueue;
97               
98                unsigned int mFrameId;
99                unsigned int mVisibilityThreshold;
100                unsigned int mNumSceneNodes;
101                int mCurrentTestIdx;
102                int mQueryMode;
103               
104                std::vector<HardwareOcclusionQuery *> mOcclusionQueries;
105                // two halfes of a aabb
106                SolidHalfBoundingBox *mHalfBoundingBox[2];     
107                int mAlgorithmType;
108        };
109
110}
111#endif // OCCLUSIONCULLINGSCENEMANAGER_H
Note: See TracBrowser for help on using the repository browser.