[12] | 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] | 19 | myless(Camera *cam) { mCamera = cam; } |
---|
[12] | 20 | //bool operator() (HierarchyNode *v1, HierarchyNode *v2) const
|
---|
| 21 | bool operator() (T v1, T v2) const
|
---|
| 22 | {
|
---|
[19] | 23 | return v1->getSquaredViewDepth(mCamera) > v2->getSquaredViewDepth(mCamera);
|
---|
[12] | 24 | }
|
---|
[19] | 25 | private:
|
---|
| 26 | Camera *mCamera;
|
---|
[12] | 27 | };
|
---|
| 28 |
|
---|
| 29 | typedef priority_queue<SceneNode *, vector<SceneNode *>, myless<vector<SceneNode *>::value_type> > PriorityQueue;
|
---|
[22] | 30 | typedef queue<SceneNode *> QueryQueue;
|
---|
[12] | 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};
|
---|
[22] | 38 |
|
---|
[12] | 39 | OcclusionCullingSceneManager();
|
---|
[22] | 40 | ~OcclusionCullingSceneManager();
|
---|
[12] | 41 |
|
---|
| 42 | /** Overriden from SceneManager. */
|
---|
| 43 | void _renderVisibleObjects(void);
|
---|
[19] | 44 | void _findVisibleObjects(Camera* cam, bool onlyShadowCasters);
|
---|
[22] | 45 | void _updateSceneGraph(Camera* cam);
|
---|
| 46 |
|
---|
[12] | 47 | protected:
|
---|
[22] | 48 | enum {MODE_QUERY, MODE_RENDER};
|
---|
[12] | 49 |
|
---|
[22] | 50 | int isLeaf(SceneNode *node);
|
---|
| 51 | int countSceneNodes(SceneNode *node);
|
---|
[19] | 52 | void renderZPass();
|
---|
| 53 | void traverseNode(SceneNode *node);
|
---|
[22] | 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);
|
---|
[21] | 58 |
|
---|
[22] | 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. */
|
---|
[21] | 66 | void issueOcclusionQuery(SceneNode *node, bool wasVisible);
|
---|
[22] | 67 | /** Pulls up the visibility from the child nodes. */
|
---|
| 68 | void pullUpVisibility(SceneNode *node);
|
---|
[21] | 69 |
|
---|
[22] | 70 | void deleteQueries();
|
---|
| 71 |
|
---|
[12] | 72 | /** we use a priority queue rather than a renderstack */
|
---|
[19] | 73 | PriorityQueue *mDistanceQueue;
|
---|
| 74 |
|
---|
[23] | 75 | unsigned int mFrameId;
|
---|
[22] | 76 | unsigned int mVisibilityThreshold;
|
---|
| 77 | unsigned int mNumSceneNodes;
|
---|
[21] | 78 | int mCurrentTestIdx;
|
---|
[22] | 79 | int mQueryMode;
|
---|
| 80 |
|
---|
[21] | 81 | std::vector<HardwareOcclusionQuery *> mOcclusionQueries;
|
---|
[12] | 82 | };
|
---|
| 83 |
|
---|
| 84 | }
|
---|
| 85 | #endif // OCCLUSIONCULLINGSCENEMANAGER_H |
---|