1 | #include "OgreVisibilityTerrainSceneManager.h"
|
---|
2 | #include "OgreOctreeHierarchyInterface.h"
|
---|
3 | #include "OgreVisibilityOptionsManager.h"
|
---|
4 | #include <OgreMath.h>
|
---|
5 | #include <OgreIteratorWrappers.h>
|
---|
6 | #include <OgreRenderSystem.h>
|
---|
7 | #include <OgreCamera.h>
|
---|
8 | #include <OgreLogManager.h>
|
---|
9 | #include <OgreStringConverter.h>
|
---|
10 |
|
---|
11 | #include <windows.h>
|
---|
12 |
|
---|
13 | namespace Ogre {
|
---|
14 |
|
---|
15 | //-----------------------------------------------------------------------
|
---|
16 | VisibilityTerrainSceneManager::VisibilityTerrainSceneManager(
|
---|
17 | GtpVisibility::VisibilityManager *visManager)
|
---|
18 | : mVisibilityManager(visManager),
|
---|
19 | mUseVisibilityCulling(true),
|
---|
20 | mShowVisualization(false),
|
---|
21 | mRenderNodesForViz(false)
|
---|
22 | {
|
---|
23 | mHierarchyInterface =
|
---|
24 | new OctreeHierarchyInterface(this, mDestRenderSystem);
|
---|
25 |
|
---|
26 | //mDisplayNodes = true;
|
---|
27 | //mShowBoundingBoxes = true;
|
---|
28 |
|
---|
29 | // TODO: set maxdepth to reasonable value
|
---|
30 | mMaxDepth = 50;
|
---|
31 | }
|
---|
32 | //-----------------------------------------------------------------------
|
---|
33 | VisibilityTerrainSceneManager::~VisibilityTerrainSceneManager()
|
---|
34 | {
|
---|
35 | delete mHierarchyInterface;
|
---|
36 | }
|
---|
37 | //-----------------------------------------------------------------------
|
---|
38 | void VisibilityTerrainSceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters)
|
---|
39 | {
|
---|
40 | mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters);
|
---|
41 | // does nothing if hierarchical culling is used =>
|
---|
42 | // we interleave identification and rendering of objects
|
---|
43 | // in _renderVisibibleObjects
|
---|
44 | if (!mUseVisibilityCulling)
|
---|
45 | {
|
---|
46 | OctreeSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
|
---|
47 | return;
|
---|
48 | }
|
---|
49 |
|
---|
50 | //-- show visibile scene nodes and octree bounding boxes from last frame
|
---|
51 | if (mShowVisualization)
|
---|
52 | {
|
---|
53 | // add player camera for visualization purpose
|
---|
54 | try {
|
---|
55 | Camera *c;
|
---|
56 | if ((c = getCamera("PlayerCam")) != NULL)
|
---|
57 | {
|
---|
58 | getRenderQueue()->addRenderable(c);
|
---|
59 | }
|
---|
60 | }
|
---|
61 | catch(...)
|
---|
62 | {
|
---|
63 | // ignore
|
---|
64 | }
|
---|
65 |
|
---|
66 | for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
|
---|
67 | {
|
---|
68 | getRenderQueue()->addRenderable(*it);
|
---|
69 |
|
---|
70 | if (mRenderNodesForViz)
|
---|
71 | {
|
---|
72 | (*it)->_addToRenderQueue(cam, getRenderQueue(), false);
|
---|
73 | }
|
---|
74 | }
|
---|
75 | for (BoxList::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it)
|
---|
76 | {
|
---|
77 | getRenderQueue()->addRenderable(*it);
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | mVisible.clear();
|
---|
82 | mBoxes.clear();
|
---|
83 | }
|
---|
84 | //-----------------------------------------------------------------------
|
---|
85 | void VisibilityTerrainSceneManager::_renderVisibleObjects()
|
---|
86 | {
|
---|
87 | if (!mShowVisualization)
|
---|
88 | {
|
---|
89 | // two cameras (one for culling, one for rendering)
|
---|
90 | mHierarchyInterface->InitFrame(mOctree, mCameraInProgress,
|
---|
91 | mCullCamera ? getCamera("CullCamera") : NULL);
|
---|
92 |
|
---|
93 | // call initframe to reset culling manager stats
|
---|
94 | mVisibilityManager->GetCullingManager()->InitFrame();
|
---|
95 | }
|
---|
96 |
|
---|
97 | // standard terrain scenemanager rendering without hierarchical culling
|
---|
98 | if (!mUseVisibilityCulling || mShowVisualization)
|
---|
99 | {
|
---|
100 | TerrainSceneManager::_renderVisibleObjects();
|
---|
101 |
|
---|
102 | return;
|
---|
103 | }
|
---|
104 |
|
---|
105 | //-- hierarchical culling
|
---|
106 | // the objects of different layers (e.g., background, scene,
|
---|
107 | // overlay) must be identified and rendered one after another
|
---|
108 |
|
---|
109 | //-- render background
|
---|
110 | clearSpecialCaseRenderQueues();
|
---|
111 | addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND);
|
---|
112 | addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY);
|
---|
113 |
|
---|
114 | setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);
|
---|
115 | SceneManager::_renderVisibleObjects();
|
---|
116 |
|
---|
117 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
118 | _deleteRenderedQueueGroups();
|
---|
119 | #endif
|
---|
120 |
|
---|
121 | //-- render visible objects (i.e., all but overlay)
|
---|
122 | clearSpecialCaseRenderQueues();
|
---|
123 | addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
|
---|
124 | setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
|
---|
125 |
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * the hierarchical culling algorithm
|
---|
129 | **/
|
---|
130 | mVisibilityManager->ApplyVisibilityCulling();
|
---|
131 |
|
---|
132 |
|
---|
133 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
134 | _deleteRenderedQueueGroups();
|
---|
135 | #endif
|
---|
136 |
|
---|
137 | //-- render overlay
|
---|
138 | clearSpecialCaseRenderQueues();
|
---|
139 | SceneManager::_renderVisibleObjects();
|
---|
140 |
|
---|
141 | //WriteLog(); // write out stats
|
---|
142 | }
|
---|
143 | //-----------------------------------------------------------------------
|
---|
144 | void VisibilityTerrainSceneManager::_updateSceneGraph(Camera* cam)
|
---|
145 | {
|
---|
146 | mVisibilityManager->GetCullingManager()->SetHierarchyInterface(mHierarchyInterface);
|
---|
147 | mHierarchyInterface->SetRenderSystem(mDestRenderSystem);
|
---|
148 |
|
---|
149 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
150 | mHierarchyInterface->SetNumOctreeNodes(mNumOctreeNodes);
|
---|
151 | #endif
|
---|
152 | TerrainSceneManager::_updateSceneGraph(cam);
|
---|
153 | }
|
---|
154 | //-----------------------------------------------------------------------
|
---|
155 | bool VisibilityTerrainSceneManager::setOption(const String & key, const void * val)
|
---|
156 | {
|
---|
157 | if (key == "UseVisibilityCulling")
|
---|
158 | {
|
---|
159 | mUseVisibilityCulling = (*static_cast<const bool *>(val));
|
---|
160 | return true;
|
---|
161 | }
|
---|
162 | if (key == "ShowVisualization")
|
---|
163 | {
|
---|
164 | mShowVisualization = (*static_cast<const bool *>(val));
|
---|
165 | return true;
|
---|
166 | }
|
---|
167 | if (key == "RenderNodesForViz")
|
---|
168 | {
|
---|
169 | mRenderNodesForViz = (*static_cast<const bool *>(val));
|
---|
170 | return true;
|
---|
171 | }
|
---|
172 | if (key == "SkyBoxEnabled")
|
---|
173 | {
|
---|
174 | mSkyBoxEnabled = (*static_cast<const bool *>(val));
|
---|
175 | return true;
|
---|
176 | }
|
---|
177 | if (key == "SkyPlaneEnabled")
|
---|
178 | {
|
---|
179 | mSkyPlaneEnabled = (*static_cast<const bool *>(val));
|
---|
180 | return true;
|
---|
181 | }
|
---|
182 | if (key == "SkyDomeEnabled")
|
---|
183 | {
|
---|
184 | mSkyDomeEnabled = (*static_cast<const bool *>(val));
|
---|
185 | return true;
|
---|
186 | }
|
---|
187 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
188 | setOption(key, val) || TerrainSceneManager::setOption(key, val);
|
---|
189 | }
|
---|
190 | //-----------------------------------------------------------------------
|
---|
191 | bool VisibilityTerrainSceneManager::getOption(const String & key, void *val)
|
---|
192 | {
|
---|
193 | if (key == "NumHierarchyNodes")
|
---|
194 | {
|
---|
195 | * static_cast<unsigned int *>(val) = (unsigned int)mNumOctreeNodes;
|
---|
196 | return true;
|
---|
197 | }
|
---|
198 |
|
---|
199 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
200 | getOption(key, val) && TerrainSceneManager::getOption(key, val);
|
---|
201 | }
|
---|
202 | //-----------------------------------------------------------------------
|
---|
203 | bool VisibilityTerrainSceneManager::getOptionValues(const String & key, StringVector &refValueList)
|
---|
204 | {
|
---|
205 | return TerrainSceneManager::getOptionValues( key, refValueList);
|
---|
206 | }
|
---|
207 | //-----------------------------------------------------------------------
|
---|
208 | bool VisibilityTerrainSceneManager::getOptionKeys(StringVector & refKeys)
|
---|
209 | {
|
---|
210 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
211 | getOptionKeys(refKeys) || TerrainSceneManager::getOptionKeys(refKeys);
|
---|
212 | }
|
---|
213 | //-----------------------------------------------------------------------
|
---|
214 | void VisibilityTerrainSceneManager::setVisibilityManager(GtpVisibility::VisibilityManager *visManager)
|
---|
215 | {
|
---|
216 | mVisibilityManager = visManager;
|
---|
217 | }
|
---|
218 | //-----------------------------------------------------------------------
|
---|
219 | GtpVisibility::VisibilityManager *VisibilityTerrainSceneManager::getVisibilityManager( void )
|
---|
220 | {
|
---|
221 | return mVisibilityManager;
|
---|
222 | }
|
---|
223 |
|
---|
224 | //-----------------------------------------------------------------------
|
---|
225 | void VisibilityTerrainSceneManager::WriteLog()
|
---|
226 | {
|
---|
227 | std::stringstream d;
|
---|
228 |
|
---|
229 | d << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << ", "
|
---|
230 | << "Hierarchy nodes: " << mNumOctreeNodes << ", "
|
---|
231 | << "Traversed nodes: " << mHierarchyInterface->GetNumTraversedNodes() << ", "
|
---|
232 | << "Rendered nodes: " << mHierarchyInterface->GetNumRenderedNodes() << ", "
|
---|
233 | << "Query culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumQueryCulledNodes() << ", "
|
---|
234 | << "Frustum culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumFrustumCulledNodes() << ", "
|
---|
235 | << "Queries issued: " << mVisibilityManager->GetCullingManager()->GetNumQueriesIssued() << "\n";
|
---|
236 |
|
---|
237 | LogManager::getSingleton().logMessage(d.str());
|
---|
238 | }
|
---|
239 |
|
---|
240 |
|
---|
241 | } // namespace Ogre
|
---|