[59] | 1 | #include "OgreVisibilityTerrainSceneManager.h"
|
---|
[74] | 2 | #include "OgreVisibilityOptionsManager.h"
|
---|
[59] | 3 | #include <OgreMath.h>
|
---|
| 4 | #include <OgreIteratorWrappers.h>
|
---|
| 5 | #include <OgreRenderSystem.h>
|
---|
| 6 | #include <OgreCamera.h>
|
---|
[93] | 7 | #include <OgreLogManager.h>
|
---|
[100] | 8 | #include <OgreStringConverter.h>
|
---|
[122] | 9 | #include <OgreEntity.h>
|
---|
| 10 | #include <OgreSubEntity.h>
|
---|
[59] | 11 |
|
---|
| 12 | namespace Ogre {
|
---|
[87] | 13 |
|
---|
[59] | 14 | //-----------------------------------------------------------------------
|
---|
[86] | 15 | VisibilityTerrainSceneManager::VisibilityTerrainSceneManager(
|
---|
[115] | 16 | GtpVisibility::VisibilityManager *visManager):
|
---|
| 17 | mVisibilityManager(visManager),
|
---|
[122] | 18 | mRenderDepthPass(false),
|
---|
[103] | 19 | mShowVisualization(false),
|
---|
[112] | 20 | mRenderNodesForViz(false),
|
---|
[113] | 21 | mRenderNodesContentForViz(false),
|
---|
[114] | 22 | mVisualizeCulledNodes(false),
|
---|
[115] | 23 | mSkipTransparents(false),
|
---|
[120] | 24 | mDelayRenderTransparents(true),
|
---|
[122] | 25 | mUseDepthPass(false),
|
---|
| 26 | mRenderItemBuffer(true),
|
---|
| 27 | mCurrentEntityId(0)
|
---|
[59] | 28 | {
|
---|
[120] | 29 | mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem);
|
---|
[59] | 30 |
|
---|
[120] | 31 | //mDisplayNodes = true;
|
---|
[85] | 32 | //mShowBoundingBoxes = true;
|
---|
[103] | 33 |
|
---|
| 34 | // TODO: set maxdepth to reasonable value
|
---|
[96] | 35 | mMaxDepth = 50;
|
---|
[59] | 36 | }
|
---|
| 37 | //-----------------------------------------------------------------------
|
---|
[119] | 38 | void VisibilityTerrainSceneManager::InitDepthPass()
|
---|
[115] | 39 | {
|
---|
| 40 | MaterialPtr depthMat = MaterialManager::getSingleton().getByName("Visibility/DepthPass");
|
---|
| 41 |
|
---|
| 42 | if (depthMat.isNull())
|
---|
| 43 | {
|
---|
| 44 | // Init
|
---|
| 45 | depthMat = MaterialManager::getSingleton().create(
|
---|
| 46 | "Visibility/DepthPass",
|
---|
| 47 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
| 48 | mDepthPass = depthMat->getTechnique(0)->getPass(0);
|
---|
| 49 | mDepthPass->setColourWriteEnabled(false);
|
---|
| 50 | mDepthPass->setDepthWriteEnabled(true);
|
---|
| 51 | mDepthPass->setLightingEnabled(false);
|
---|
| 52 | }
|
---|
| 53 | else
|
---|
| 54 | {
|
---|
| 55 | mDepthPass = depthMat->getTechnique(0)->getPass(0);
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 | //-----------------------------------------------------------------------
|
---|
[122] | 59 | void VisibilityTerrainSceneManager::InitItemBufferPass()
|
---|
| 60 | {
|
---|
| 61 | MaterialPtr itemBufferMat = MaterialManager::getSingleton().
|
---|
| 62 | getByName("Visibility/ItemBufferPass");
|
---|
| 63 |
|
---|
| 64 | if (itemBufferMat.isNull())
|
---|
| 65 | {
|
---|
| 66 | // Init
|
---|
| 67 | itemBufferMat = MaterialManager::getSingleton().create("Visibility/ItemBufferPass",
|
---|
| 68 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
| 69 |
|
---|
| 70 | mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0);
|
---|
| 71 | mItemBufferPass->setColourWriteEnabled(true);
|
---|
| 72 | mItemBufferPass->setDepthWriteEnabled(true);
|
---|
| 73 | mItemBufferPass->setLightingEnabled(true);
|
---|
| 74 | }
|
---|
| 75 | else
|
---|
| 76 | {
|
---|
| 77 | mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0);
|
---|
| 78 | }
|
---|
[129] | 79 | mItemBufferPass->setAmbient(1, 1, 0);
|
---|
[122] | 80 | }
|
---|
| 81 | //-----------------------------------------------------------------------
|
---|
[59] | 82 | VisibilityTerrainSceneManager::~VisibilityTerrainSceneManager()
|
---|
| 83 | {
|
---|
[120] | 84 | if (mHierarchyInterface)
|
---|
| 85 | {
|
---|
| 86 | delete mHierarchyInterface;
|
---|
| 87 | mHierarchyInterface = NULL;
|
---|
| 88 | }
|
---|
[59] | 89 | }
|
---|
| 90 | //-----------------------------------------------------------------------
|
---|
[115] | 91 | void VisibilityTerrainSceneManager::ShowVisualization(Camera *cam)
|
---|
| 92 | {
|
---|
[122] | 93 | LogManager::getSingleton().logMessage("***********VISUALIZATION************");
|
---|
[115] | 94 | // add player camera for visualization purpose
|
---|
[121] | 95 | try
|
---|
| 96 | {
|
---|
[115] | 97 | Camera *c;
|
---|
| 98 | if ((c = getCamera("PlayerCam")) != NULL)
|
---|
| 99 | {
|
---|
| 100 | getRenderQueue()->addRenderable(c);
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
[121] | 103 | catch (...)
|
---|
[115] | 104 | {
|
---|
| 105 | // ignore
|
---|
| 106 | }
|
---|
[118] | 107 | for (BoxList::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it)
|
---|
| 108 | {
|
---|
| 109 | getRenderQueue()->addRenderable(*it);
|
---|
| 110 | }
|
---|
[115] | 111 | if (mRenderNodesForViz || mRenderNodesContentForViz)
|
---|
| 112 | {
|
---|
[118] | 113 | // change node material so it is better suited for visualization
|
---|
| 114 | MaterialPtr nodeMat = MaterialManager::getSingleton().getByName("Core/NodeMaterial");
|
---|
| 115 | nodeMat->setAmbient(1, 1, 0);
|
---|
| 116 | nodeMat->setLightingEnabled(true);
|
---|
| 117 | nodeMat->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();
|
---|
| 118 |
|
---|
[115] | 119 | for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
|
---|
| 120 | {
|
---|
| 121 | if (mRenderNodesForViz)
|
---|
| 122 | {
|
---|
[118] | 123 | getRenderQueue()->addRenderable(*it);
|
---|
[121] | 124 |
|
---|
[115] | 125 | // addbounding boxes instead of node itself
|
---|
[118] | 126 | //(*it)->_addBoundingBoxToQueue(getRenderQueue());
|
---|
[115] | 127 | }
|
---|
| 128 | if (mRenderNodesContentForViz)
|
---|
| 129 | {
|
---|
[122] | 130 | (*it)->_addToRenderQueue(cam, getRenderQueue(), false);
|
---|
[115] | 131 | }
|
---|
| 132 | }
|
---|
[121] | 133 | }
|
---|
[103] | 134 | }
|
---|
| 135 | //-----------------------------------------------------------------------
|
---|
[120] | 136 | Pass *VisibilityTerrainSceneManager::setPass(Pass* pass)
|
---|
| 137 | {
|
---|
[122] | 138 | //Pass *usedPass = ((mRenderDepthPass && !pass->hasVertexProgram()) ? mDepthPass : pass); // setting vertex program is not efficient
|
---|
[121] | 139 |
|
---|
[120] | 140 | // set depth fill pass only if depth write enabled
|
---|
[122] | 141 | Pass *usedPass = (mRenderDepthPass && !mHierarchyInterface->IsBoundingBoxQuery() ? mDepthPass : pass);
|
---|
[121] | 142 |
|
---|
| 143 | IlluminationRenderStage savedStage = mIlluminationStage;
|
---|
[120] | 144 |
|
---|
[121] | 145 | // set illumination stage to NONE so no shadow material is used
|
---|
| 146 | // for depth pass or for occlusion query
|
---|
[122] | 147 | if (mRenderDepthPass || mHierarchyInterface->IsBoundingBoxQuery())
|
---|
[121] | 148 | {
|
---|
| 149 | mIlluminationStage = IRS_NONE;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
[122] | 152 | if (mRenderDepthPass)
|
---|
[120] | 153 | {
|
---|
| 154 | // set vertex program of current pass
|
---|
| 155 | if (pass->hasVertexProgram())
|
---|
| 156 | {
|
---|
| 157 | mDepthPass->setVertexProgram(pass->getVertexProgramName());
|
---|
| 158 |
|
---|
| 159 | if (mDepthPass->hasVertexProgram())
|
---|
| 160 | {
|
---|
| 161 | const GpuProgramPtr& prg = mDepthPass->getVertexProgram();
|
---|
| 162 | // Load this program if not done already
|
---|
| 163 | if (!prg->isLoaded())
|
---|
| 164 | prg->load();
|
---|
| 165 | // Copy params
|
---|
| 166 | mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters());
|
---|
| 167 | }
|
---|
| 168 | }
|
---|
| 169 | else if (mDepthPass->hasVertexProgram())
|
---|
| 170 | {
|
---|
| 171 | mDepthPass->setVertexProgram("");
|
---|
| 172 | }
|
---|
| 173 | }
|
---|
[121] | 174 | //else if (mIsItemBufferPass) {usedPass = mItemBufferPass;}
|
---|
| 175 |
|
---|
| 176 | Pass *result = SceneManager::setPass(usedPass);
|
---|
[120] | 177 |
|
---|
[121] | 178 | // reset illumination stage
|
---|
| 179 | mIlluminationStage = savedStage;
|
---|
| 180 |
|
---|
| 181 | return result;
|
---|
[120] | 182 | }
|
---|
| 183 | //-----------------------------------------------------------------------
|
---|
[115] | 184 | void VisibilityTerrainSceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters)
|
---|
[103] | 185 | {
|
---|
[122] | 186 | // needs full ambient lighting for item colors to be exact
|
---|
| 187 | if (mRenderItemBuffer)
|
---|
| 188 | {
|
---|
| 189 | setAmbientLight(ColourValue(1,1,1,1));
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | LogManager::getSingleton().logMessage("***********FIND OBJECTS************");
|
---|
| 193 | getRenderQueue()->clear();
|
---|
| 194 |
|
---|
[115] | 195 | //-- show visible scene nodes and octree bounding boxes from last frame
|
---|
| 196 | if (mShowVisualization)
|
---|
| 197 | {
|
---|
| 198 | ShowVisualization(cam);
|
---|
| 199 | }
|
---|
[121] | 200 |
|
---|
[122] | 201 | //TerrainSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
|
---|
| 202 |
|
---|
[121] | 203 | mVisible.clear();
|
---|
| 204 | mBoxes.clear();
|
---|
| 205 |
|
---|
| 206 | // if there is no depth pass =>
|
---|
| 207 | // we interleave identification and rendering of objects
|
---|
| 208 | // in _renderVisibibleObjects
|
---|
| 209 |
|
---|
| 210 | // only shadow casters will be rendered in shadow texture pass
|
---|
| 211 | mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters);
|
---|
| 212 |
|
---|
| 213 | bool leaveTransparentsInQueue = mDelayRenderTransparents && !mUseDepthPass;
|
---|
| 214 |
|
---|
| 215 | // possible two cameras (one for culling, one for rendering)
|
---|
| 216 | mHierarchyInterface->InitFrame(mOctree, cam, //mCameraInProgress,
|
---|
| 217 | mCullCamera ? getCamera("CullCamera") : NULL,
|
---|
| 218 | leaveTransparentsInQueue);
|
---|
[115] | 219 | }
|
---|
| 220 | //-----------------------------------------------------------------------
|
---|
| 221 | void VisibilityTerrainSceneManager::_renderVisibleObjects()
|
---|
| 222 | {
|
---|
[129] | 223 | /*
|
---|
| 224 | std::stringstream d;
|
---|
[122] | 225 | d << "Terrain render level: " << TerrainRenderable::getCurrentRenderLevelIndex();
|
---|
| 226 | LogManager::getSingleton().logMessage(d.str());
|
---|
| 227 |
|
---|
| 228 | // increase terrain renderlevel
|
---|
| 229 | int renderLevel = TerrainRenderable::getCurrentRenderLevelIndex() + 1;
|
---|
| 230 |
|
---|
| 231 | if (TerrainRenderable::getCurrentRenderLevelIndex() >= 10)
|
---|
| 232 | { // max. 10 different renderlevels
|
---|
| 233 | renderLevel = 0;
|
---|
| 234 | }
|
---|
[129] | 235 | */
|
---|
[115] | 236 | // visualization: apply standard rendering
|
---|
| 237 | if (mShowVisualization)
|
---|
[87] | 238 | {
|
---|
[101] | 239 | TerrainSceneManager::_renderVisibleObjects();
|
---|
[129] | 240 | // TerrainRenderable::setCurrentRenderLevelIndex(renderLevel);
|
---|
[87] | 241 | return;
|
---|
[115] | 242 | }
|
---|
| 243 |
|
---|
[122] | 244 | LogManager::getSingleton().logMessage("***********RENDER OBJECTS************");
|
---|
| 245 |
|
---|
| 246 | InitDepthPass(); // create material for depth pass
|
---|
| 247 | InitItemBufferPass(); // create material for item buffer pass
|
---|
| 248 |
|
---|
[87] | 249 | //-- hierarchical culling
|
---|
| 250 | // the objects of different layers (e.g., background, scene,
|
---|
| 251 | // overlay) must be identified and rendered one after another
|
---|
| 252 |
|
---|
[121] | 253 | // frame initialisation to reset culling manager stats
|
---|
[115] | 254 | mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes);
|
---|
| 255 |
|
---|
| 256 | mSkipTransparents = false;
|
---|
| 257 |
|
---|
| 258 | //-- render background, in case there is one
|
---|
[59] | 259 | clearSpecialCaseRenderQueues();
|
---|
| 260 | addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND);
|
---|
| 261 | addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY);
|
---|
[115] | 262 | setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);
|
---|
[59] | 263 |
|
---|
[121] | 264 | TerrainSceneManager::_renderVisibleObjects();
|
---|
[100] | 265 |
|
---|
[115] | 266 |
|
---|
[59] | 267 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
[115] | 268 | _deleteRenderedQueueGroups(false);
|
---|
[59] | 269 | #endif
|
---|
| 270 |
|
---|
[115] | 271 | //-- render visible objects (i.e., all but overlay and skies late)
|
---|
[59] | 272 | clearSpecialCaseRenderQueues();
|
---|
[115] | 273 | addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_LATE);
|
---|
[59] | 274 | addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
|
---|
| 275 | setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
|
---|
| 276 |
|
---|
[115] | 277 | // transparents are skipped from hierarchical rendering
|
---|
| 278 | // => they need sorting, thus we render them afterwards
|
---|
| 279 | mSkipTransparents = mDelayRenderTransparents;
|
---|
[100] | 280 |
|
---|
[115] | 281 | // set state for depth pass
|
---|
[122] | 282 | mRenderDepthPass = mUseDepthPass;
|
---|
[115] | 283 |
|
---|
[100] | 284 | /**
|
---|
[115] | 285 | * the hierarchical culling algorithm
|
---|
| 286 | * for depth pass: will just find objects and update depth buffer
|
---|
| 287 | * for delayed rendering: will render all but transparents
|
---|
[100] | 288 | **/
|
---|
[115] | 289 |
|
---|
[74] | 290 | mVisibilityManager->ApplyVisibilityCulling();
|
---|
[59] | 291 |
|
---|
[100] | 292 |
|
---|
[115] | 293 | // for depth pass: add visible nodes found with the visibility culling
|
---|
| 294 | if (mUseDepthPass)
|
---|
| 295 | {
|
---|
[122] | 296 | for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
|
---|
[115] | 297 | {
|
---|
| 298 | (*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false);
|
---|
[122] | 299 | }
|
---|
| 300 | mRenderDepthPass = false;
|
---|
[115] | 301 | }
|
---|
[120] | 302 |
|
---|
[115] | 303 | mSkipTransparents = false;
|
---|
[59] | 304 |
|
---|
[115] | 305 | //-- now we can render all remaining queue objects
|
---|
| 306 | // for depth pass: all
|
---|
| 307 | // for delayed rendering: transparents, overlay
|
---|
[59] | 308 | clearSpecialCaseRenderQueues();
|
---|
[121] | 309 | TerrainSceneManager::_renderVisibleObjects();
|
---|
[99] | 310 |
|
---|
[129] | 311 | //TerrainRenderable::setCurrentRenderLevelIndex(renderLevel);
|
---|
[99] | 312 | //WriteLog(); // write out stats
|
---|
[59] | 313 | }
|
---|
[122] | 314 |
|
---|
[59] | 315 | //-----------------------------------------------------------------------
|
---|
| 316 | void VisibilityTerrainSceneManager::_updateSceneGraph(Camera* cam)
|
---|
| 317 | {
|
---|
| 318 | mVisibilityManager->GetCullingManager()->SetHierarchyInterface(mHierarchyInterface);
|
---|
| 319 | mHierarchyInterface->SetRenderSystem(mDestRenderSystem);
|
---|
[74] | 320 |
|
---|
[59] | 321 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
| 322 | mHierarchyInterface->SetNumOctreeNodes(mNumOctreeNodes);
|
---|
| 323 | #endif
|
---|
| 324 | TerrainSceneManager::_updateSceneGraph(cam);
|
---|
| 325 | }
|
---|
| 326 | //-----------------------------------------------------------------------
|
---|
| 327 | bool VisibilityTerrainSceneManager::setOption(const String & key, const void * val)
|
---|
| 328 | {
|
---|
[115] | 329 | if (key == "UseDepthPass")
|
---|
[87] | 330 | {
|
---|
[115] | 331 | mUseDepthPass = (*static_cast<const bool *>(val));
|
---|
[87] | 332 | return true;
|
---|
| 333 | }
|
---|
[99] | 334 | if (key == "ShowVisualization")
|
---|
| 335 | {
|
---|
| 336 | mShowVisualization = (*static_cast<const bool *>(val));
|
---|
| 337 | return true;
|
---|
| 338 | }
|
---|
[103] | 339 | if (key == "RenderNodesForViz")
|
---|
| 340 | {
|
---|
| 341 | mRenderNodesForViz = (*static_cast<const bool *>(val));
|
---|
| 342 | return true;
|
---|
| 343 | }
|
---|
[113] | 344 | if (key == "RenderNodesContentForViz")
|
---|
| 345 | {
|
---|
| 346 | mRenderNodesContentForViz = (*static_cast<const bool *>(val));
|
---|
| 347 | return true;
|
---|
| 348 | }
|
---|
[100] | 349 | if (key == "SkyBoxEnabled")
|
---|
| 350 | {
|
---|
| 351 | mSkyBoxEnabled = (*static_cast<const bool *>(val));
|
---|
| 352 | return true;
|
---|
| 353 | }
|
---|
| 354 | if (key == "SkyPlaneEnabled")
|
---|
| 355 | {
|
---|
| 356 | mSkyPlaneEnabled = (*static_cast<const bool *>(val));
|
---|
| 357 | return true;
|
---|
| 358 | }
|
---|
| 359 | if (key == "SkyDomeEnabled")
|
---|
| 360 | {
|
---|
| 361 | mSkyDomeEnabled = (*static_cast<const bool *>(val));
|
---|
| 362 | return true;
|
---|
| 363 | }
|
---|
[112] | 364 | if (key == "VisualizeCulledNodes")
|
---|
| 365 | {
|
---|
| 366 | mVisualizeCulledNodes = (*static_cast<const bool *>(val));
|
---|
| 367 | return true;
|
---|
| 368 | }
|
---|
[115] | 369 | if (key == "DelayRenderTransparents")
|
---|
| 370 | {
|
---|
| 371 | mDelayRenderTransparents = (*static_cast<const bool *>(val));
|
---|
| 372 | return true;
|
---|
| 373 | }
|
---|
[122] | 374 | // notifiy that frame has ended so terrain render level can be reset for correct
|
---|
| 375 | // terrain rendering
|
---|
[129] | 376 | /* if (key == "TerrainLevelIdx")
|
---|
[122] | 377 | {
|
---|
| 378 | TerrainRenderable::setCurrentRenderLevelIndex((*static_cast<const int *>(val)));
|
---|
[129] | 379 | return true;
|
---|
| 380 | }*/
|
---|
[74] | 381 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
| 382 | setOption(key, val) || TerrainSceneManager::setOption(key, val);
|
---|
[59] | 383 | }
|
---|
| 384 | //-----------------------------------------------------------------------
|
---|
| 385 | bool VisibilityTerrainSceneManager::getOption(const String & key, void *val)
|
---|
| 386 | {
|
---|
[74] | 387 | if (key == "NumHierarchyNodes")
|
---|
| 388 | {
|
---|
| 389 | * static_cast<unsigned int *>(val) = (unsigned int)mNumOctreeNodes;
|
---|
| 390 | return true;
|
---|
| 391 | }
|
---|
| 392 |
|
---|
| 393 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
| 394 | getOption(key, val) && TerrainSceneManager::getOption(key, val);
|
---|
[59] | 395 | }
|
---|
| 396 | //-----------------------------------------------------------------------
|
---|
[103] | 397 | bool VisibilityTerrainSceneManager::getOptionValues(const String & key, StringVector &refValueList)
|
---|
[59] | 398 | {
|
---|
[74] | 399 | return TerrainSceneManager::getOptionValues( key, refValueList);
|
---|
[59] | 400 | }
|
---|
| 401 | //-----------------------------------------------------------------------
|
---|
| 402 | bool VisibilityTerrainSceneManager::getOptionKeys(StringVector & refKeys)
|
---|
| 403 | {
|
---|
[74] | 404 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
| 405 | getOptionKeys(refKeys) || TerrainSceneManager::getOptionKeys(refKeys);
|
---|
[59] | 406 | }
|
---|
| 407 | //-----------------------------------------------------------------------
|
---|
| 408 | void VisibilityTerrainSceneManager::setVisibilityManager(GtpVisibility::VisibilityManager *visManager)
|
---|
| 409 | {
|
---|
| 410 | mVisibilityManager = visManager;
|
---|
| 411 | }
|
---|
| 412 | //-----------------------------------------------------------------------
|
---|
| 413 | GtpVisibility::VisibilityManager *VisibilityTerrainSceneManager::getVisibilityManager( void )
|
---|
| 414 | {
|
---|
| 415 | return mVisibilityManager;
|
---|
| 416 | }
|
---|
[93] | 417 | //-----------------------------------------------------------------------
|
---|
| 418 | void VisibilityTerrainSceneManager::WriteLog()
|
---|
| 419 | {
|
---|
| 420 | std::stringstream d;
|
---|
| 421 |
|
---|
[120] | 422 | d << "Depth pass: " << StringConverter::toString(mUseDepthPass) << ", "
|
---|
| 423 | << "Delay transparents: " << StringConverter::toString(mDelayRenderTransparents) << ", "
|
---|
| 424 | << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetUseOptimization()) << ", "
|
---|
| 425 | << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << ", "
|
---|
[101] | 426 | << "Hierarchy nodes: " << mNumOctreeNodes << ", "
|
---|
| 427 | << "Traversed nodes: " << mHierarchyInterface->GetNumTraversedNodes() << ", "
|
---|
[93] | 428 | << "Rendered nodes: " << mHierarchyInterface->GetNumRenderedNodes() << ", "
|
---|
| 429 | << "Query culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumQueryCulledNodes() << ", "
|
---|
| 430 | << "Frustum culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumFrustumCulledNodes() << ", "
|
---|
| 431 | << "Queries issued: " << mVisibilityManager->GetCullingManager()->GetNumQueriesIssued() << "\n";
|
---|
| 432 |
|
---|
| 433 | LogManager::getSingleton().logMessage(d.str());
|
---|
| 434 | }
|
---|
[114] | 435 | //-----------------------------------------------------------------------
|
---|
| 436 | void VisibilityTerrainSceneManager::renderObjects(const RenderPriorityGroup::TransparentRenderablePassList& objs,
|
---|
| 437 | bool doLightIteration, const LightList* manualLightList)
|
---|
| 438 | {
|
---|
[121] | 439 | // for correct rendering, transparents must be rendered after hierarchical culling
|
---|
[115] | 440 | if (!mSkipTransparents)
|
---|
[114] | 441 | {
|
---|
| 442 | OctreeSceneManager::renderObjects(objs, doLightIteration, manualLightList);
|
---|
| 443 | }
|
---|
| 444 | }
|
---|
[121] | 445 | //-----------------------------------------------------------------------
|
---|
| 446 | bool VisibilityTerrainSceneManager::validatePassForRendering(Pass* pass)
|
---|
| 447 | {
|
---|
| 448 | // skip all but first pass if we are doing the depth pass
|
---|
[122] | 449 | if ((mRenderDepthPass || mRenderItemBuffer) && pass->getIndex() > 0)
|
---|
[121] | 450 | {
|
---|
| 451 | return false;
|
---|
| 452 | }
|
---|
| 453 | return SceneManager::validatePassForRendering(pass);
|
---|
| 454 | }
|
---|
[122] | 455 | //-----------------------------------------------------------------------
|
---|
| 456 | void VisibilityTerrainSceneManager::renderQueueGroupObjects(RenderQueueGroup* pGroup)
|
---|
| 457 | {
|
---|
| 458 | if (!mRenderItemBuffer)
|
---|
| 459 | {
|
---|
| 460 | TerrainSceneManager::renderQueueGroupObjects(pGroup);
|
---|
| 461 | return;
|
---|
| 462 | }
|
---|
[103] | 463 |
|
---|
[122] | 464 | //--- item buffer
|
---|
| 465 | // Iterate through priorities
|
---|
| 466 | RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
|
---|
| 467 |
|
---|
| 468 | while (groupIt.hasMoreElements())
|
---|
| 469 | {
|
---|
| 470 | RenderItemBuffer(groupIt.getNext());
|
---|
| 471 | }
|
---|
| 472 | }
|
---|
| 473 | //-----------------------------------------------------------------------
|
---|
| 474 | void VisibilityTerrainSceneManager::RenderItemBuffer(RenderPriorityGroup* pGroup)
|
---|
| 475 | {
|
---|
| 476 | // Do solids
|
---|
| 477 | RenderPriorityGroup::SolidRenderablePassMap solidObjs = pGroup->_getSolidPasses();
|
---|
| 478 |
|
---|
| 479 | // ----- SOLIDS LOOP -----
|
---|
| 480 | RenderPriorityGroup::SolidRenderablePassMap::const_iterator ipass, ipassend;
|
---|
| 481 | ipassend = solidObjs.end();
|
---|
| 482 |
|
---|
| 483 | for (ipass = solidObjs.begin(); ipass != ipassend; ++ipass)
|
---|
| 484 | {
|
---|
| 485 | // Fast bypass if this group is now empty
|
---|
| 486 | if (ipass->second->empty())
|
---|
| 487 | continue;
|
---|
| 488 |
|
---|
| 489 | // Render only first pass
|
---|
| 490 | if (ipass->first->getIndex() > 0)
|
---|
| 491 | continue;
|
---|
| 492 |
|
---|
| 493 | RenderPriorityGroup::RenderableList* rendList = ipass->second;
|
---|
| 494 |
|
---|
| 495 | RenderPriorityGroup::RenderableList::const_iterator irend, irendend;
|
---|
| 496 | irendend = rendList->end();
|
---|
| 497 |
|
---|
| 498 | for (irend = rendList->begin(); irend != irendend; ++irend)
|
---|
| 499 | {
|
---|
[129] | 500 | std::stringstream d; d << "itembuffer, pass name: " <<
|
---|
| 501 | ipass->first->getParent()->getParent()->getName();
|
---|
| 502 | //<< ", renderable name: " << irend->
|
---|
| 503 |
|
---|
| 504 | LogManager::getSingleton().logMessage(d.str());
|
---|
| 505 |
|
---|
| 506 | //if(ipass->first->getParent()->getParent()->getName() == "Examples/Athene")
|
---|
| 507 | //<< ", renderable name: " << irend->
|
---|
| 508 | RenderSingleObjectForItemBuffer(*irend, ipass->first);
|
---|
| 509 | RenderSingleObjectForOcclusionQuery(
|
---|
[122] | 510 | }
|
---|
| 511 | }
|
---|
| 512 |
|
---|
[129] | 513 | // ----- TRANSPARENT LOOP: must be handlet differently altough we don't really
|
---|
| 514 | // care about transparents for the item buffer
|
---|
| 515 | // TODO: HOW TO HANDLE OCCLUDED OBJECTS ????
|
---|
[122] | 516 | RenderPriorityGroup::TransparentRenderablePassList
|
---|
| 517 | transpObjs = pGroup->_getTransparentPasses();
|
---|
| 518 | RenderPriorityGroup::TransparentRenderablePassList::const_iterator itrans, itransend;
|
---|
| 519 |
|
---|
| 520 | itransend = transpObjs.end();
|
---|
| 521 | for (itrans = transpObjs.begin(); itrans != itransend; ++itrans)
|
---|
| 522 | {
|
---|
[129] | 523 | // like for solids, render only first pass
|
---|
[122] | 524 | if (itrans->pass->getIndex() == 0)
|
---|
[129] | 525 | {
|
---|
| 526 | RenderSingleObjectForItemBuffer(itrans->renderable, itrans->pass);
|
---|
[122] | 527 | }
|
---|
| 528 | }
|
---|
| 529 | }
|
---|
| 530 | //-----------------------------------------------------------------------
|
---|
[129] | 531 | void VisibilityTerrainSceneManager::RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass)
|
---|
[122] | 532 | {
|
---|
| 533 | static LightList nullLightList;
|
---|
[129] | 534 |
|
---|
[122] | 535 | Real col = (Real)rend->getId() / (Real)mCurrentEntityId;
|
---|
| 536 |
|
---|
[129] | 537 | mItemBufferPass->setAmbient(ColourValue(0, 1, 1));
|
---|
| 538 | //mItemBufferPass->setDiffuse(ColourValue(0, col, 0));
|
---|
| 539 | // mItemBufferPass->setSpecular(ColourValue(0, col, 0));
|
---|
| 540 | // mItemBufferPass->_load();
|
---|
[122] | 541 |
|
---|
[129] | 542 | // set vertex program of current pass
|
---|
| 543 | if (pass->hasVertexProgram())
|
---|
| 544 | {
|
---|
| 545 | mItemBufferPass->setVertexProgram(pass->getVertexProgramName());
|
---|
| 546 |
|
---|
| 547 | if (mItemBufferPass->hasVertexProgram())
|
---|
| 548 | {
|
---|
| 549 | const GpuProgramPtr& prg = mItemBufferPass->getVertexProgram();
|
---|
| 550 | // Load this program if not done already
|
---|
| 551 | if (!prg->isLoaded())
|
---|
| 552 | prg->load();
|
---|
| 553 | // Copy params
|
---|
| 554 | mItemBufferPass->setVertexProgramParameters(pass->getVertexProgramParameters());
|
---|
| 555 | }
|
---|
| 556 | }
|
---|
| 557 | else if (mItemBufferPass->hasVertexProgram())
|
---|
| 558 | {
|
---|
| 559 | mItemBufferPass->setVertexProgram("");
|
---|
| 560 | }
|
---|
| 561 |
|
---|
| 562 | //LogManager::getSingleton().logMessage("has vertex program");
|
---|
| 563 | Pass *usedPass = setPass(mItemBufferPass);
|
---|
| 564 | //Pass *usedPass = setPass(pass);
|
---|
[122] | 565 | std::stringstream d;
|
---|
| 566 | d << "item buffer id: " << rend->getId() << ", col: " << col;
|
---|
| 567 | LogManager::getSingleton().logMessage(d.str());
|
---|
[129] | 568 |
|
---|
[122] | 569 | // Render a single object, this will set up auto params if required
|
---|
[129] | 570 | renderSingleObject(rend, usedPass, false, &nullLightList);
|
---|
[122] | 571 | }
|
---|
| 572 | //-----------------------------------------------------------------------
|
---|
| 573 | Entity* VisibilityTerrainSceneManager::createEntity(const String& entityName, const String& meshName)
|
---|
| 574 | {
|
---|
| 575 | Entity *ent = SceneManager::createEntity(entityName, meshName);
|
---|
| 576 |
|
---|
| 577 | for (int i = 0; i < ent->getNumSubEntities(); ++i)
|
---|
| 578 | {
|
---|
| 579 | ent->getSubEntity(i)->setId(mCurrentEntityId ++);
|
---|
| 580 | }
|
---|
| 581 |
|
---|
| 582 | return ent;
|
---|
| 583 | }
|
---|
| 584 |
|
---|
[59] | 585 | } // namespace Ogre
|
---|