1 | #ifndef _OcclusionCullingSceneManager_H__
|
---|
2 | #define _OcclusionCullingSceneManager_H__
|
---|
3 |
|
---|
4 | #include "OgreSceneNode.h"
|
---|
5 | #include "OgreSceneManager.h"
|
---|
6 | #include "OgrePrerequisites.h"
|
---|
7 | #include <queue>
|
---|
8 |
|
---|
9 | using namespace std; |
---|
10 | |
---|
11 | namespace Ogre { |
---|
12 | /** |
---|
13 | This class implements the compare operator for the priority queue. |
---|
14 | a lower distance has a higher value in the queue |
---|
15 | */ |
---|
16 | template <typename T> class myless
|
---|
17 | {
|
---|
18 | public:
|
---|
19 | myless(Camera *cam) { mCamera = cam; } |
---|
20 | //bool operator() (HierarchyNode *v1, HierarchyNode *v2) const
|
---|
21 | bool operator() (T v1, T v2) const
|
---|
22 | {
|
---|
23 | return v1->getSquaredViewDepth(mCamera) > v2->getSquaredViewDepth(mCamera);
|
---|
24 | }
|
---|
25 | private:
|
---|
26 | Camera *mCamera;
|
---|
27 | };
|
---|
28 |
|
---|
29 | typedef priority_queue<SceneNode *, vector<SceneNode *>, myless<vector<SceneNode *>::value_type> > PriorityQueue;
|
---|
30 | typedef queue<SceneNode *> QueryQueue;
|
---|
31 | /**
|
---|
32 | Class which implements a scene mangager which uses occlusion queries for culling occluded objects
|
---|
33 | */
|
---|
34 | class OcclusionCullingSceneManager : public SceneManager
|
---|
35 | {
|
---|
36 | public:
|
---|
37 | enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES};
|
---|
38 |
|
---|
39 | OcclusionCullingSceneManager();
|
---|
40 | ~OcclusionCullingSceneManager();
|
---|
41 |
|
---|
42 | /** Overriden from SceneManager. */
|
---|
43 | void _renderVisibleObjects(void);
|
---|
44 | void _findVisibleObjects(Camera* cam, bool onlyShadowCasters);
|
---|
45 | void _updateSceneGraph(Camera* cam);
|
---|
46 |
|
---|
47 | protected:
|
---|
48 | enum {MODE_QUERY, MODE_RENDER};
|
---|
49 |
|
---|
50 | int isLeaf(SceneNode *node);
|
---|
51 | int countSceneNodes(SceneNode *node);
|
---|
52 | void renderZPass();
|
---|
53 | void traverseNode(SceneNode *node);
|
---|
54 | /** Renders current node */
|
---|
55 | void render(SceneNode *node);
|
---|
56 | /** Sets rendering mode, e.g. query mode or render mode*/
|
---|
57 | void setRenderingMode(int mode);
|
---|
58 |
|
---|
59 | /** Renders the scene with view frustum culling only. */ |
---|
60 | void renderCullFrustum(); |
---|
61 | /** Renders the scene with the hierarchical stop and wait algorithm. */ |
---|
62 | void renderStopAndWait(); |
---|
63 | /** Renders the scene with the coherent hierarchical algorithm and the query queye. */ |
---|
64 | void renderCoherentWithQueue();
|
---|
65 | /** Issue a occlusion query for this node. */
|
---|
66 | void issueOcclusionQuery(SceneNode *node, bool wasVisible);
|
---|
67 | /** Pulls up the visibility from the child nodes. */
|
---|
68 | void pullUpVisibility(SceneNode *node);
|
---|
69 |
|
---|
70 | void deleteQueries();
|
---|
71 |
|
---|
72 | /** we use a priority queue rather than a renderstack */
|
---|
73 | PriorityQueue *mDistanceQueue;
|
---|
74 |
|
---|
75 | unsigned int mFrameId;
|
---|
76 | unsigned int mVisibilityThreshold;
|
---|
77 | unsigned int mNumSceneNodes;
|
---|
78 | int mCurrentTestIdx;
|
---|
79 | int mQueryMode;
|
---|
80 |
|
---|
81 | std::vector<HardwareOcclusionQuery *> mOcclusionQueries;
|
---|
82 | };
|
---|
83 |
|
---|
84 | }
|
---|
85 | #endif // OCCLUSIONCULLINGSCENEMANAGER_H |
---|