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

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