1 | #include "OgreOcclusionCullingSceneManager.h"
|
---|
2 | #include "OgreMath.h"
|
---|
3 | #include "OgreIteratorWrappers.h"
|
---|
4 | #include "OgreRenderSystem.h"
|
---|
5 | #include "OgreCamera.h"
|
---|
6 | #include <windows.h>
|
---|
7 |
|
---|
8 | namespace Ogre {
|
---|
9 |
|
---|
10 | //-----------------------------------------------------------------------
|
---|
11 | OcclusionCullingSceneManager::OcclusionCullingSceneManager():
|
---|
12 | mFrameID(1), mDistanceQueue(NULL)
|
---|
13 | {
|
---|
14 | }
|
---|
15 |
|
---|
16 | void OcclusionCullingSceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters)
|
---|
17 | {
|
---|
18 | // empty because we have to find in _renderVisibleObjects
|
---|
19 | }
|
---|
20 |
|
---|
21 | //-----------------------------------------------------------------------
|
---|
22 | void OcclusionCullingSceneManager::_renderVisibleObjects(void)
|
---|
23 | {
|
---|
24 | mDistanceQueue = new PriorityQueue(myless<SceneNode *>(mCameraInProgress));
|
---|
25 | mDistanceQueue->push(mSceneRoot);
|
---|
26 | //renderZPass();
|
---|
27 | renderCullFrustum();
|
---|
28 | delete mDistanceQueue;
|
---|
29 | //mDestRenderSystem->_setDepthBufferParams(true, false, CMPF_LESS);
|
---|
30 | //SceneManager::_renderVisibleObjects();
|
---|
31 | //mDestRenderSystem->_setDepthBufferParams();
|
---|
32 | //mDistanceQueue.push(mSceneRoot);
|
---|
33 | //Preprocess();
|
---|
34 |
|
---|
35 | //renderCullFrustum();
|
---|
36 |
|
---|
37 | //mFrameID ++;
|
---|
38 | //ResetQueries();
|
---|
39 | }
|
---|
40 |
|
---|
41 | //-----------------------------------------------------------------------
|
---|
42 | void OcclusionCullingSceneManager::renderZPass()
|
---|
43 | {
|
---|
44 | traverseNode(mSceneRoot);
|
---|
45 | }
|
---|
46 |
|
---|
47 | //-----------------------------------------------------------------------
|
---|
48 | void OcclusionCullingSceneManager::renderCullFrustum()
|
---|
49 | {
|
---|
50 | while(!mDistanceQueue->empty()) |
---|
51 | { |
---|
52 | SceneNode *node = mDistanceQueue->top(); |
---|
53 | mDistanceQueue->pop(); |
---|
54 | |
---|
55 | // interesting for the visualization, so rest and set |
---|
56 | //node->SetVisible(false); |
---|
57 | |
---|
58 | if(mCameraInProgress->isVisible(node->_getWorldAABB())) |
---|
59 | { |
---|
60 | // update node's visited flag => needed for rendering |
---|
61 | // so set it also here |
---|
62 | //node->SetLastVisited(mFrameID); |
---|
63 | //node->SetVisible(true); |
---|
64 | traverseNode(node); |
---|
65 | } |
---|
66 | //else |
---|
67 | //MessageBox( NULL, "myplugin registered", "this is my plugin", MB_OK | MB_ICONERROR | MB_TASKMODAL); |
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | //-----------------------------------------------------------------------
|
---|
72 | void OcclusionCullingSceneManager::traverseNode(SceneNode *node)
|
---|
73 | {
|
---|
74 | if(node->numChildren() == 0) // reached leaf
|
---|
75 | {
|
---|
76 | renderSceneNode(node);
|
---|
77 | }
|
---|
78 | else // internal node: add children to priority queue for further processing
|
---|
79 | {
|
---|
80 | Node::ChildNodeIterator it = node->getChildIterator();
|
---|
81 | char str[100]; sprintf(str, "number of children: %d", node->numChildren());
|
---|
82 |
|
---|
83 | while (it.hasMoreElements())
|
---|
84 | {
|
---|
85 | SceneNode* sceneChild = static_cast<SceneNode*>(it.getNext());
|
---|
86 | //mDistanceQueue->addRenderable(sceneChild);
|
---|
87 | mDistanceQueue->push(sceneChild);
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | /*
|
---|
92 | static RenderOperation ro;
|
---|
93 | node->getRenderOperation(ro);
|
---|
94 | ro.srcRenderable = node;
|
---|
95 | mDestRenderSystem->_render(ro);
|
---|
96 | Pass pass();
|
---|
97 | renderSingleObject(node, &pass, true);
|
---|
98 | */
|
---|
99 | }
|
---|
100 |
|
---|
101 | void OcclusionCullingSceneManager::renderSceneNode(SceneNode *node)
|
---|
102 | {
|
---|
103 | node->_findVisibleObjects(mCameraInProgress, getRenderQueue(), false,
|
---|
104 | mDisplayNodes, false);
|
---|
105 | SceneManager::_renderVisibleObjects();
|
---|
106 | getRenderQueue()->clear();
|
---|
107 | }
|
---|
108 | }
|
---|