[720] | 1 | #include "OgreOcclusionCullingSceneManager.h"
|
---|
[675] | 2 | #include "OgreVisibilityOptionsManager.h"
|
---|
| 3 | #include <OgreMath.h>
|
---|
| 4 | #include <OgreIteratorWrappers.h>
|
---|
| 5 | #include <OgreRenderSystem.h>
|
---|
| 6 | #include <OgreCamera.h>
|
---|
| 7 | #include <OgreLogManager.h>
|
---|
| 8 | #include <OgreStringConverter.h>
|
---|
| 9 | #include <OgreEntity.h>
|
---|
| 10 | #include <OgreSubEntity.h>
|
---|
[897] | 11 | #include <OgreMaterialManager.h>
|
---|
[863] | 12 | #include <OgreIteratorWrappers.h>
|
---|
[925] | 13 | #include <OgreHeightmapTerrainPageSource.h>
|
---|
[828] | 14 | #include "VspBspTree.h"
|
---|
[863] | 15 | #include "Containers.h"
|
---|
| 16 | #include "ViewCellsManager.h"
|
---|
[903] | 17 | #include <OgreConfigFile.h>
|
---|
| 18 | #include "OgreTypeConverter.h"
|
---|
| 19 | #include "OgreMeshInstance.h"
|
---|
| 20 | #include "common.h"
|
---|
[931] | 21 | #include "OgreBoundingBoxConverter.h"
|
---|
[1593] | 22 | #include <OgreManualObject.h>
|
---|
[1616] | 23 | #include "IntersectableWrapper.h"
|
---|
[1816] | 24 | #include "IVReader.h"
|
---|
[675] | 25 |
|
---|
[1816] | 26 |
|
---|
[675] | 27 | namespace Ogre {
|
---|
| 28 |
|
---|
| 29 | //-----------------------------------------------------------------------
|
---|
[2066] | 30 | OcclusionCullingSceneManager::OcclusionCullingSceneManager(
|
---|
| 31 | const String& name,
|
---|
| 32 | GtpVisibility::VisibilityManager *visManager):
|
---|
[897] | 33 | TerrainSceneManager(name),
|
---|
[675] | 34 | mVisibilityManager(visManager),
|
---|
| 35 | mShowVisualization(false),
|
---|
| 36 | mRenderNodesForViz(false),
|
---|
| 37 | mRenderNodesContentForViz(false),
|
---|
| 38 | mVisualizeCulledNodes(false),
|
---|
| 39 | mLeavePassesInQueue(0),
|
---|
| 40 | mDelayRenderTransparents(true),
|
---|
| 41 | mUseDepthPass(false),
|
---|
| 42 | mIsDepthPassPhase(false),
|
---|
| 43 | mUseItemBuffer(false),
|
---|
| 44 | mIsItemBufferPhase(false),
|
---|
| 45 | mCurrentEntityId(1),
|
---|
| 46 | mEnableDepthWrite(true),
|
---|
| 47 | mSkipTransparents(false),
|
---|
| 48 | mRenderTransparentsForItemBuffer(true),
|
---|
[925] | 49 | mExecuteVertexProgramForAllPasses(false),
|
---|
[903] | 50 | mIsHierarchicalCulling(false),
|
---|
| 51 | mViewCellsLoaded(false),
|
---|
| 52 | mUseViewCells(false),
|
---|
| 53 | mUseVisibilityFilter(false),
|
---|
| 54 | mCurrentViewCell(NULL),
|
---|
[1251] | 55 | mElementaryViewCell(NULL),
|
---|
[1276] | 56 | mDeleteQueueAfterRendering(true),
|
---|
[1606] | 57 | mNormalExecution(false),
|
---|
[1616] | 58 | mShowViewCells(false),
|
---|
[1816] | 59 | mViewCellsGeometryLoaded(false),
|
---|
[1823] | 60 | mShowTerrain(false),
|
---|
| 61 | mViewCellsFilename(""),
|
---|
| 62 | mFilename("terrain")
|
---|
[675] | 63 | {
|
---|
[1816] | 64 | Ogre::LogManager::getSingleton().
|
---|
| 65 | logMessage("creating occlusion culling scene manager");
|
---|
[1264] | 66 |
|
---|
[675] | 67 | mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem);
|
---|
| 68 |
|
---|
[868] | 69 | if (0)
|
---|
| 70 | {
|
---|
[925] | 71 | mDisplayNodes = true;
|
---|
| 72 | mShowBoundingBoxes = true;
|
---|
| 73 | mShowBoxes = true;
|
---|
[868] | 74 | }
|
---|
| 75 |
|
---|
[675] | 76 | // TODO: set maxdepth to reasonable value
|
---|
| 77 | mMaxDepth = 50;
|
---|
| 78 | }
|
---|
| 79 | //-----------------------------------------------------------------------
|
---|
[720] | 80 | void OcclusionCullingSceneManager::InitDepthPass()
|
---|
[675] | 81 | {
|
---|
[1610] | 82 | MaterialPtr depthMat =
|
---|
| 83 | MaterialManager::getSingleton().getByName("Visibility/DepthPass");
|
---|
[675] | 84 |
|
---|
| 85 | if (depthMat.isNull())
|
---|
| 86 | {
|
---|
| 87 | depthMat = MaterialManager::getSingleton().create(
|
---|
| 88 | "Visibility/DepthPass",
|
---|
| 89 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
| 90 |
|
---|
| 91 | mDepthPass = depthMat->getTechnique(0)->getPass(0);
|
---|
| 92 | mDepthPass->setColourWriteEnabled(false);
|
---|
| 93 | mDepthPass->setDepthWriteEnabled(true);
|
---|
| 94 | mDepthPass->setLightingEnabled(false);
|
---|
| 95 | }
|
---|
| 96 | else
|
---|
| 97 | {
|
---|
| 98 | mDepthPass = depthMat->getTechnique(0)->getPass(0);
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 | //-----------------------------------------------------------------------
|
---|
[720] | 102 | OcclusionCullingSceneManager::~OcclusionCullingSceneManager()
|
---|
[675] | 103 | {
|
---|
| 104 | OGRE_DELETE(mHierarchyInterface);
|
---|
[903] | 105 | CLEAR_CONTAINER(mObjects);
|
---|
| 106 | OGRE_DELETE(mCurrentViewCell);
|
---|
[675] | 107 | }
|
---|
| 108 | //-----------------------------------------------------------------------
|
---|
[720] | 109 | void OcclusionCullingSceneManager::InitItemBufferPass()
|
---|
[675] | 110 | {
|
---|
| 111 | MaterialPtr itemBufferMat = MaterialManager::getSingleton().
|
---|
| 112 | getByName("Visibility/ItemBufferPass");
|
---|
| 113 |
|
---|
| 114 | if (itemBufferMat.isNull())
|
---|
| 115 | {
|
---|
| 116 | // Init
|
---|
[1610] | 117 | itemBufferMat =
|
---|
| 118 | MaterialManager::getSingleton().create("Visibility/ItemBufferPass",
|
---|
[675] | 119 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
| 120 |
|
---|
| 121 | mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0);
|
---|
| 122 | mItemBufferPass->setColourWriteEnabled(true);
|
---|
| 123 | mItemBufferPass->setDepthWriteEnabled(true);
|
---|
| 124 | mItemBufferPass->setLightingEnabled(true);
|
---|
| 125 | //mItemBufferPass->setLightingEnabled(false);
|
---|
| 126 | }
|
---|
| 127 | else
|
---|
| 128 | {
|
---|
| 129 | mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0);
|
---|
| 130 | }
|
---|
| 131 | //mItemBufferPass->setAmbient(1, 1, 0);
|
---|
| 132 | }
|
---|
[897] | 133 | //-------------------------------------------------------------------------
|
---|
[925] | 134 | #if 1
|
---|
[1816] | 135 | void OcclusionCullingSceneManager::setWorldGeometry(DataStreamPtr& stream,
|
---|
| 136 | const String& typeName)
|
---|
[897] | 137 | {
|
---|
[2097] | 138 | // Clear out any existing world resources (if not default)
|
---|
[897] | 139 | if (ResourceGroupManager::getSingleton().getWorldResourceGroupName() !=
|
---|
| 140 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)
|
---|
| 141 | {
|
---|
| 142 | ResourceGroupManager::getSingleton().clearResourceGroup(
|
---|
| 143 | ResourceGroupManager::getSingleton().getWorldResourceGroupName());
|
---|
| 144 | }
|
---|
[1610] | 145 |
|
---|
[897] | 146 | destroyLevelIndexes();
|
---|
| 147 | mTerrainPages.clear();
|
---|
[1610] | 148 |
|
---|
[897] | 149 | // Load the configuration
|
---|
[938] | 150 | loadConfig(stream);
|
---|
[897] | 151 |
|
---|
[2097] | 152 | //////////////
|
---|
| 153 | // file loading
|
---|
[1823] | 154 |
|
---|
[2097] | 155 | // load the scene
|
---|
[1823] | 156 | LoadScene(mFilename);
|
---|
[2097] | 157 |
|
---|
[1823] | 158 | // load view cells
|
---|
[2097] | 159 | //mViewCellsLoaded = LoadViewCells(mViewCellsFilename);
|
---|
[1823] | 160 |
|
---|
[1816] | 161 | if (mShowTerrain)
|
---|
[1823] | 162 | {
|
---|
[1816] | 163 | initLevelIndexes();
|
---|
[897] | 164 |
|
---|
[1816] | 165 | // Resize the octree, allow for 1 page for now
|
---|
| 166 | float max_x = mOptions.scale.x * mOptions.pageSize;
|
---|
[1823] | 167 | float max_y = mOptions.scale.y;// * mOptions.pageSize;
|
---|
[1816] | 168 | float max_z = mOptions.scale.z * mOptions.pageSize;
|
---|
| 169 |
|
---|
| 170 | float maxAxis = std::max(max_x, max_y);
|
---|
| 171 | maxAxis = std::max(maxAxis, max_z);
|
---|
[1823] | 172 | //resize(AxisAlignedBox( 0, 0, 0, maxAxis, maxAxis, maxAxis));
|
---|
[2097] | 173 | resize(AxisAlignedBox( 0, 0, 0, max_x, max_y, max_z ));
|
---|
[1823] | 174 |
|
---|
[1816] | 175 | setupTerrainMaterial();
|
---|
| 176 | setupTerrainPages();
|
---|
[1823] | 177 | }
|
---|
[897] | 178 | }
|
---|
[925] | 179 | #endif
|
---|
[2097] | 180 |
|
---|
[1816] | 181 | //-------------------------------------------------------------------------
|
---|
| 182 | void OcclusionCullingSceneManager::loadConfig(DataStreamPtr& stream)
|
---|
| 183 | {
|
---|
[1823] | 184 | // Set up the options
|
---|
[1816] | 185 | ConfigFile config;
|
---|
| 186 | String val;
|
---|
| 187 |
|
---|
| 188 | config.load(stream);
|
---|
| 189 |
|
---|
| 190 | std::stringstream d;
|
---|
[1823] | 191 |
|
---|
| 192 | val = config.getSetting("DepthPass");
|
---|
[1816] | 193 |
|
---|
| 194 | if (!val.empty())
|
---|
| 195 | {
|
---|
[1823] | 196 | mUseDepthPass = atoi(val.c_str());
|
---|
[1816] | 197 | }
|
---|
| 198 |
|
---|
[1823] | 199 | val = config.getSetting("FlushQueue");
|
---|
| 200 |
|
---|
[1816] | 201 | if (!val.empty())
|
---|
| 202 | {
|
---|
[1823] | 203 | mDeleteQueueAfterRendering = atoi(val.c_str());
|
---|
| 204 | }
|
---|
[1816] | 205 |
|
---|
[1823] | 206 | val = config.getSetting("Scene");
|
---|
| 207 |
|
---|
| 208 | if (!val.empty())
|
---|
| 209 | {
|
---|
| 210 | mFilename = val.c_str();
|
---|
| 211 |
|
---|
| 212 | if (mFilename == "terrain")
|
---|
| 213 | {
|
---|
| 214 | mShowTerrain = true;
|
---|
[2097] | 215 | LogManager::getSingleton().logMessage("loading terrain");
|
---|
[1823] | 216 | }
|
---|
[1816] | 217 | }
|
---|
[1823] | 218 |
|
---|
| 219 | if (!mShowTerrain)
|
---|
| 220 | {
|
---|
| 221 | val = config.getSetting("ViewCells");
|
---|
| 222 |
|
---|
| 223 | if (!val.empty())
|
---|
| 224 | {
|
---|
[2097] | 225 | mViewCellsFilename = val;
|
---|
[1823] | 226 | }
|
---|
| 227 | }
|
---|
[2097] | 228 |
|
---|
[1816] | 229 | val = config.getSetting("OnlineCullingAlgorithm");
|
---|
| 230 |
|
---|
| 231 | if (!val.empty())
|
---|
| 232 | {
|
---|
| 233 | GtpVisibility::VisibilityEnvironment::CullingManagerType algorithm;
|
---|
| 234 |
|
---|
| 235 | if (val == "CHC")
|
---|
| 236 | {
|
---|
| 237 | algorithm =
|
---|
| 238 | GtpVisibility::VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING;
|
---|
| 239 | }
|
---|
| 240 | else if (val == "SWC")
|
---|
| 241 | {
|
---|
| 242 | algorithm =
|
---|
| 243 | GtpVisibility::VisibilityEnvironment::STOP_AND_WAIT_CULLING;
|
---|
| 244 | }
|
---|
| 245 | else if (val == "VFC")
|
---|
| 246 | {
|
---|
| 247 | algorithm =
|
---|
| 248 | GtpVisibility::VisibilityEnvironment::FRUSTUM_CULLING;
|
---|
| 249 | }
|
---|
| 250 | else // default rendering
|
---|
| 251 | {
|
---|
| 252 | algorithm =
|
---|
| 253 | GtpVisibility::VisibilityEnvironment::NUM_CULLING_MANAGERS;
|
---|
[1823] | 254 |
|
---|
| 255 | mNormalExecution = true;
|
---|
[1816] | 256 | }
|
---|
| 257 |
|
---|
| 258 | mVisibilityManager->SetCullingManager(algorithm);
|
---|
[1823] | 259 |
|
---|
| 260 | d << "setting algorithm to: " << algorithm;
|
---|
| 261 | LogManager::getSingleton().logMessage(d.str());
|
---|
[1816] | 262 | }
|
---|
| 263 |
|
---|
[2097] | 264 | /////////////
|
---|
[1823] | 265 | // terrain options
|
---|
| 266 |
|
---|
| 267 | if (!mShowTerrain)
|
---|
| 268 | return;
|
---|
| 269 |
|
---|
[2097] | 270 | val = config.getSetting("DetailTile");
|
---|
| 271 | if (!val.empty())
|
---|
[1823] | 272 | setDetailTextureRepeat(atoi(val.c_str()));
|
---|
| 273 |
|
---|
[2097] | 274 | val = config.getSetting("MaxMipMapLevel");
|
---|
| 275 | if (!val.empty())
|
---|
| 276 | setMaxGeoMipMapLevel(atoi(val.c_str()));
|
---|
[1823] | 277 |
|
---|
| 278 |
|
---|
[2097] | 279 | val = config.getSetting("PageSize");
|
---|
| 280 | if (!val.empty())
|
---|
| 281 | setPageSize(atoi(val.c_str()));
|
---|
[1823] | 282 | else
|
---|
| 283 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Missing option 'PageSize'",
|
---|
| 284 | "TerrainSceneManager::loadConfig");
|
---|
| 285 |
|
---|
| 286 |
|
---|
[2097] | 287 | val = config.getSetting("TileSize");
|
---|
| 288 | if (!val.empty())
|
---|
| 289 | setTileSize(atoi(val.c_str()));
|
---|
[1823] | 290 | else
|
---|
| 291 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Missing option 'TileSize'",
|
---|
| 292 | "TerrainSceneManager::loadConfig");
|
---|
| 293 |
|
---|
| 294 | Vector3 v = Vector3::UNIT_SCALE;
|
---|
| 295 |
|
---|
| 296 | val = config.getSetting( "PageWorldX" );
|
---|
| 297 | if ( !val.empty() )
|
---|
| 298 | v.x = atof( val.c_str() );
|
---|
| 299 |
|
---|
| 300 | val = config.getSetting( "MaxHeight" );
|
---|
| 301 | if ( !val.empty() )
|
---|
| 302 | v.y = atof( val.c_str() );
|
---|
| 303 |
|
---|
| 304 | val = config.getSetting( "PageWorldZ" );
|
---|
| 305 | if ( !val.empty() )
|
---|
| 306 | v.z = atof( val.c_str() );
|
---|
| 307 |
|
---|
| 308 | // Scale x/z relative to pagesize
|
---|
| 309 | v.x /= mOptions.pageSize;
|
---|
| 310 | v.z /= mOptions.pageSize;
|
---|
| 311 | setScale(v);
|
---|
| 312 |
|
---|
| 313 | val = config.getSetting( "MaxPixelError" );
|
---|
| 314 | if ( !val.empty() )
|
---|
| 315 | setMaxPixelError(atoi( val.c_str() ));
|
---|
| 316 |
|
---|
| 317 | mDetailTextureName = config.getSetting( "DetailTexture" );
|
---|
| 318 |
|
---|
| 319 | mWorldTextureName = config.getSetting( "WorldTexture" );
|
---|
| 320 |
|
---|
| 321 | if ( config.getSetting( "VertexColours" ) == "yes" )
|
---|
| 322 | mOptions.coloured = true;
|
---|
| 323 |
|
---|
| 324 | if ( config.getSetting( "VertexNormals" ) == "yes" )
|
---|
| 325 | mOptions.lit = true;
|
---|
| 326 |
|
---|
| 327 | if ( config.getSetting( "UseTriStrips" ) == "yes" )
|
---|
| 328 | setUseTriStrips(true);
|
---|
| 329 |
|
---|
| 330 | if ( config.getSetting( "VertexProgramMorph" ) == "yes" )
|
---|
| 331 | setUseLODMorph(true);
|
---|
| 332 |
|
---|
| 333 | val = config.getSetting( "LODMorphStart");
|
---|
| 334 | if ( !val.empty() )
|
---|
| 335 | setLODMorphStart(atof(val.c_str()));
|
---|
| 336 |
|
---|
| 337 | val = config.getSetting( "CustomMaterialName" );
|
---|
| 338 | if ( !val.empty() )
|
---|
| 339 | setCustomMaterial(val);
|
---|
| 340 |
|
---|
| 341 | val = config.getSetting( "MorphLODFactorParamName" );
|
---|
| 342 | if ( !val.empty() )
|
---|
| 343 | setCustomMaterialMorphFactorParam(val);
|
---|
| 344 |
|
---|
| 345 | val = config.getSetting( "MorphLODFactorParamIndex" );
|
---|
| 346 | if ( !val.empty() )
|
---|
| 347 | setCustomMaterialMorphFactorParam(atoi(val.c_str()));
|
---|
| 348 |
|
---|
| 349 | // Now scan through the remaining settings, looking for any PageSource
|
---|
| 350 | // prefixed items
|
---|
| 351 | String pageSourceName = config.getSetting("PageSource");
|
---|
| 352 | if (pageSourceName == "")
|
---|
[1816] | 353 | {
|
---|
[1823] | 354 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Missing option 'PageSource'",
|
---|
| 355 | "TerrainSceneManager::loadConfig");
|
---|
[1816] | 356 | }
|
---|
[1823] | 357 | TerrainPageSourceOptionList optlist;
|
---|
| 358 | ConfigFile::SettingsIterator setIt = config.getSettingsIterator();
|
---|
| 359 | while (setIt.hasMoreElements())
|
---|
| 360 | {
|
---|
| 361 | String name = setIt.peekNextKey();
|
---|
| 362 | String value = setIt.getNext();
|
---|
| 363 | if (StringUtil::startsWith(name, pageSourceName, false))
|
---|
| 364 | {
|
---|
| 365 | optlist.push_back(TerrainPageSourceOption(name, value));
|
---|
| 366 | }
|
---|
| 367 | }
|
---|
| 368 | // set the page source
|
---|
| 369 | selectPageSource(pageSourceName, optlist);
|
---|
[1816] | 370 | }
|
---|
[675] | 371 | //-----------------------------------------------------------------------
|
---|
[720] | 372 | void OcclusionCullingSceneManager::PrepareVisualization(Camera *cam)
|
---|
[1620] | 373 | {
|
---|
[675] | 374 | // add player camera for visualization purpose
|
---|
| 375 | try
|
---|
| 376 | {
|
---|
| 377 | Camera *c;
|
---|
| 378 | if ((c = getCamera("PlayerCam")) != NULL)
|
---|
| 379 | {
|
---|
| 380 | getRenderQueue()->addRenderable(c);
|
---|
| 381 | }
|
---|
| 382 | }
|
---|
| 383 | catch (...)
|
---|
| 384 | {
|
---|
| 385 | // ignore
|
---|
| 386 | }
|
---|
[1597] | 387 |
|
---|
[868] | 388 | // add bounding boxes of rendered objects
|
---|
[944] | 389 | if (0)
|
---|
[675] | 390 | for (BoxList::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it)
|
---|
| 391 | {
|
---|
| 392 | getRenderQueue()->addRenderable(*it);
|
---|
| 393 | }
|
---|
[1618] | 394 |
|
---|
[1597] | 395 | // set old view cell geometry to invisible
|
---|
[1618] | 396 | if (mCurrentViewCell && mCurrentViewCell->GetMesh())
|
---|
[1593] | 397 | {
|
---|
[1606] | 398 | //const bool showSingleViewCell = true;
|
---|
[1616] | 399 | if (mViewCellsGeometryLoaded)
|
---|
[1602] | 400 | {
|
---|
[1616] | 401 | if (!mShowViewCells)
|
---|
[1602] | 402 | {
|
---|
[1616] | 403 | const int id = mCurrentViewCell->GetId();
|
---|
| 404 |
|
---|
| 405 | MovableMap::iterator fit = mViewCellsGeometry.find(id);
|
---|
[1816] | 406 |
|
---|
[1616] | 407 | if ((fit != mViewCellsGeometry.end()) && (*fit).second)
|
---|
| 408 | (*fit).second->_updateRenderQueue(getRenderQueue());
|
---|
| 409 | }
|
---|
| 410 | else
|
---|
| 411 | {
|
---|
| 412 | MovableMap::const_iterator mit, mit_end = mViewCellsGeometry.end();
|
---|
| 413 |
|
---|
| 414 | for (mit = mViewCellsGeometry.begin(); mit != mit_end; ++ mit)
|
---|
| 415 | {
|
---|
| 416 | if ((*mit).second)
|
---|
| 417 | (*mit).second->_updateRenderQueue(getRenderQueue());
|
---|
| 418 | }
|
---|
| 419 | }
|
---|
[1602] | 420 | }
|
---|
[1616] | 421 |
|
---|
| 422 |
|
---|
[1816] | 423 | //////////
|
---|
| 424 | //-- set PVS of view cell visible
|
---|
| 425 |
|
---|
| 426 | GtpVisibilityPreprocessor::ObjectPvsIterator pit =
|
---|
| 427 | mCurrentViewCell->GetPvs().GetIterator();
|
---|
| 428 |
|
---|
| 429 | while (pit.HasMoreEntries())
|
---|
| 430 | {
|
---|
| 431 | GtpVisibilityPreprocessor::ObjectPvsEntry entry = pit.Next();
|
---|
| 432 | GtpVisibilityPreprocessor::Intersectable *obj = entry.mObject;
|
---|
| 433 |
|
---|
[2067] | 434 | if (obj->Type() !=
|
---|
[2066] | 435 | GtpVisibilityPreprocessor::Intersectable::ENGINE_INTERSECTABLE)
|
---|
[2067] | 436 | continue;
|
---|
| 437 |
|
---|
| 438 | EngineIntersectable *oi = static_cast<EngineIntersectable *>(obj);
|
---|
[1816] | 439 |
|
---|
[2067] | 440 | EntityContainer *entries = oi->GetItem();
|
---|
| 441 | EntityContainer::const_iterator eit, eit_end = entries->end();
|
---|
[1816] | 442 |
|
---|
[2067] | 443 | for (eit = entries->begin(); eit != eit_end; ++ eit)
|
---|
| 444 | {
|
---|
| 445 | (*eit)->setUserAny(Any((int)0));
|
---|
[1616] | 446 | }
|
---|
| 447 | }
|
---|
| 448 |
|
---|
[1816] | 449 | pit = mCurrentViewCell->GetPvs().GetIterator();
|
---|
| 450 |
|
---|
| 451 | while (pit.HasMoreEntries())
|
---|
| 452 | {
|
---|
| 453 | GtpVisibilityPreprocessor::ObjectPvsEntry entry = pit.Next();
|
---|
| 454 | GtpVisibilityPreprocessor::Intersectable *obj = entry.mObject;
|
---|
| 455 |
|
---|
| 456 | switch (obj->Type())
|
---|
[1616] | 457 | {
|
---|
[1816] | 458 | case GtpVisibilityPreprocessor::Intersectable::OGRE_MESH_INSTANCE:
|
---|
| 459 | {
|
---|
[2066] | 460 | OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(obj);
|
---|
[1816] | 461 | omi->GetEntity()->_updateRenderQueue(getRenderQueue());
|
---|
| 462 | }
|
---|
| 463 | break;
|
---|
| 464 |
|
---|
[2066] | 465 | case GtpVisibilityPreprocessor::Intersectable::ENGINE_INTERSECTABLE:
|
---|
[1816] | 466 | {
|
---|
[2066] | 467 | EngineIntersectable *oi = static_cast<EngineIntersectable *>(obj);
|
---|
[1816] | 468 |
|
---|
| 469 | EntityContainer *entries = oi->GetItem();
|
---|
| 470 | EntityContainer::const_iterator eit, eit_end = entries->end();
|
---|
| 471 |
|
---|
| 472 | for (eit = entries->begin(); eit != eit_end; ++ eit)
|
---|
[1616] | 473 | {
|
---|
[2097] | 474 |
|
---|
[1816] | 475 | Entity *ent = *eit;
|
---|
| 476 | Any newAny = ent->getUserAny();
|
---|
| 477 |
|
---|
| 478 | int flt = any_cast<int>(newAny);
|
---|
[2097] | 479 |
|
---|
[1816] | 480 | if (any_cast<int>(newAny) == 0)
|
---|
[1616] | 481 | {
|
---|
[1816] | 482 | ent->setUserAny(Any((int)1));
|
---|
| 483 | ent->_updateRenderQueue(getRenderQueue());
|
---|
| 484 | }
|
---|
[1616] | 485 |
|
---|
| 486 | }
|
---|
[1816] | 487 | }
|
---|
| 488 | break;
|
---|
| 489 | default:
|
---|
| 490 | break;
|
---|
[1616] | 491 | }
|
---|
[1606] | 492 | }
|
---|
[1593] | 493 | }
|
---|
[1620] | 494 | /*
|
---|
[1618] | 495 | if (mRenderNodesForViz || mRenderNodesContentForViz)
|
---|
[675] | 496 | {
|
---|
| 497 | // HACK: change node material so it is better suited for visualization
|
---|
| 498 | MaterialPtr nodeMat = MaterialManager::getSingleton().getByName("Core/NodeMaterial");
|
---|
| 499 | nodeMat->setAmbient(1, 1, 0);
|
---|
| 500 | nodeMat->setLightingEnabled(true);
|
---|
| 501 | nodeMat->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();
|
---|
| 502 |
|
---|
| 503 | for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
|
---|
| 504 | {
|
---|
| 505 | if (mRenderNodesForViz)
|
---|
| 506 | {
|
---|
[1597] | 507 | // render the visible leaf nodes
|
---|
[925] | 508 | if ((*it)->numAttachedObjects() &&
|
---|
| 509 | !(*it)->numChildren() &&
|
---|
| 510 | ((*it)->getAttachedObject(0)->getMovableType() == "Entity") &&
|
---|
| 511 | (*it)->getAttachedObject(0)->isVisible())
|
---|
[675] | 512 | {
|
---|
[1597] | 513 | //getRenderQueue()->addRenderable((*it));
|
---|
| 514 | (*it)->_addToRenderQueue(cam, getRenderQueue(), false);
|
---|
[675] | 515 | }
|
---|
| 516 |
|
---|
[1597] | 517 | // add bounding boxes instead of node itself
|
---|
[1602] | 518 | if (0)
|
---|
| 519 | (*it)->_addBoundingBoxToQueue(getRenderQueue());
|
---|
[675] | 520 | }
|
---|
[1593] | 521 |
|
---|
[903] | 522 | // add renderables itself
|
---|
[1602] | 523 | if (mRenderNodesContentForViz)
|
---|
[675] | 524 | {
|
---|
| 525 | (*it)->_addToRenderQueue(cam, getRenderQueue(), false);
|
---|
| 526 | }
|
---|
| 527 | }
|
---|
[1618] | 528 | }*/
|
---|
[675] | 529 | }
|
---|
| 530 | //-----------------------------------------------------------------------
|
---|
[1232] | 531 | const Pass *OcclusionCullingSceneManager::_setPass(const Pass* pass, bool evenIfSuppressed)
|
---|
[675] | 532 | {
|
---|
[1276] | 533 | if (mNormalExecution)
|
---|
[868] | 534 | {
|
---|
[897] | 535 | return SceneManager::_setPass(pass);
|
---|
[868] | 536 | }
|
---|
| 537 |
|
---|
[675] | 538 | // TODO: setting vertex program is not efficient
|
---|
| 539 | //Pass *usedPass = ((mIsDepthPassPhase && !pass->hasVertexProgram()) ? mDepthPass : pass);
|
---|
| 540 |
|
---|
| 541 | // set depth fill pass if we currently do not make an aabb occlusion query
|
---|
[868] | 542 | const bool useDepthPass =
|
---|
| 543 | (mIsDepthPassPhase && !mHierarchyInterface->IsBoundingBoxQuery());
|
---|
| 544 |
|
---|
[925] | 545 | const IlluminationRenderStage savedStage = mIlluminationStage;
|
---|
[675] | 546 |
|
---|
| 547 | // set illumination stage to NONE so no shadow material is used
|
---|
| 548 | // for depth pass or for occlusion query
|
---|
| 549 | if (mIsDepthPassPhase || mHierarchyInterface->IsBoundingBoxQuery())
|
---|
| 550 | {
|
---|
| 551 | mIlluminationStage = IRS_NONE;
|
---|
| 552 | }
|
---|
| 553 |
|
---|
| 554 | // --- set vertex program of current pass in order to set correct depth
|
---|
[868] | 555 | if (mExecuteVertexProgramForAllPasses &&
|
---|
| 556 | mIsDepthPassPhase &&
|
---|
| 557 | pass->hasVertexProgram())
|
---|
[675] | 558 | {
|
---|
| 559 | // add vertex program of current pass to depth pass
|
---|
| 560 | mDepthPass->setVertexProgram(pass->getVertexProgramName());
|
---|
| 561 |
|
---|
| 562 | if (mDepthPass->hasVertexProgram())
|
---|
| 563 | {
|
---|
| 564 | const GpuProgramPtr& prg = mDepthPass->getVertexProgram();
|
---|
| 565 | // Load this program if not done already
|
---|
| 566 | if (!prg->isLoaded())
|
---|
| 567 | prg->load();
|
---|
| 568 | // Copy params
|
---|
| 569 | mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters());
|
---|
| 570 | }
|
---|
| 571 | }
|
---|
[868] | 572 | else if (mDepthPass->hasVertexProgram()) // reset vertex program
|
---|
[675] | 573 | {
|
---|
| 574 | mDepthPass->setVertexProgram("");
|
---|
| 575 | }
|
---|
| 576 |
|
---|
[1232] | 577 | const Pass *usedPass = useDepthPass ? mDepthPass : pass;
|
---|
| 578 |
|
---|
[868] | 579 | // save old depth write: needed for item buffer
|
---|
| 580 | const bool IsDepthWrite = usedPass->getDepthWriteEnabled();
|
---|
[675] | 581 |
|
---|
| 582 | // global option which enables / disables depth writes
|
---|
| 583 | if (!mEnableDepthWrite)
|
---|
| 584 | {
|
---|
[1232] | 585 | //usedPass->setDepthWriteEnabled(false);
|
---|
[675] | 586 | }
|
---|
| 587 | //else if (mIsItemBufferPass) {usedPass = mItemBufferPass;}
|
---|
[868] | 588 |
|
---|
| 589 | //-- set actual pass here
|
---|
[897] | 590 | const Pass *result = SceneManager::_setPass(usedPass);
|
---|
[675] | 591 |
|
---|
[868] | 592 |
|
---|
[675] | 593 | // reset depth write
|
---|
| 594 | if (!mEnableDepthWrite)
|
---|
| 595 | {
|
---|
[1232] | 596 | //usedPass->setDepthWriteEnabled(IsDepthWrite);
|
---|
[675] | 597 | }
|
---|
| 598 |
|
---|
| 599 | // reset illumination stage
|
---|
| 600 | mIlluminationStage = savedStage;
|
---|
| 601 |
|
---|
| 602 | return result;
|
---|
| 603 | }
|
---|
| 604 | //-----------------------------------------------------------------------
|
---|
[897] | 605 | void OcclusionCullingSceneManager::_findVisibleObjects(Camera* cam,
|
---|
| 606 | bool onlyShadowCasters)
|
---|
[675] | 607 | {
|
---|
| 608 | if (mShowVisualization)
|
---|
| 609 | {
|
---|
[1593] | 610 | //////////////
|
---|
| 611 | //-- show visible scene nodes and octree bounding boxes from last frame
|
---|
[675] | 612 | PrepareVisualization(cam);
|
---|
| 613 | }
|
---|
| 614 | else
|
---|
| 615 | {
|
---|
[1597] | 616 | // hierarchical culling interleaves identification
|
---|
[675] | 617 | // and rendering of objects in _renderVisibibleObjects
|
---|
| 618 |
|
---|
| 619 | // for the shadow pass we use only standard rendering
|
---|
[1597] | 620 | // because shadows have low occlusion snyway
|
---|
[675] | 621 | if (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE &&
|
---|
| 622 | mIlluminationStage == IRS_RENDER_TO_TEXTURE)
|
---|
| 623 | {
|
---|
[868] | 624 | OctreeSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
|
---|
[675] | 625 | }
|
---|
[903] | 626 |
|
---|
[675] | 627 | // only shadow casters will be rendered in shadow texture pass
|
---|
[868] | 628 | if (0) mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters);
|
---|
[1602] | 629 |
|
---|
| 630 | ///////////
|
---|
| 631 | //-- set visibility according to pvs of current view cell
|
---|
| 632 |
|
---|
| 633 | UpdatePvs(cam);
|
---|
| 634 |
|
---|
| 635 | if (mNormalExecution)
|
---|
| 636 | {
|
---|
| 637 | OctreeSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
|
---|
| 638 | //return;
|
---|
| 639 | }
|
---|
[675] | 640 | }
|
---|
[1593] | 641 |
|
---|
[1264] | 642 | // lists only used for visualization
|
---|
[675] | 643 | mVisible.clear();
|
---|
| 644 | mBoxes.clear();
|
---|
| 645 | }
|
---|
| 646 | //-----------------------------------------------------------------------
|
---|
[720] | 647 | void OcclusionCullingSceneManager::_renderVisibleObjects()
|
---|
[675] | 648 | {
|
---|
[1276] | 649 | if (mNormalExecution)
|
---|
[868] | 650 | {
|
---|
[1593] | 651 | // the standard octree rendering mode
|
---|
[1602] | 652 | TerrainSceneManager::_renderVisibleObjects();
|
---|
[1610] | 653 | getRenderQueue()->clear(mDeleteQueueAfterRendering);
|
---|
[868] | 654 | return;
|
---|
| 655 | }
|
---|
| 656 |
|
---|
[675] | 657 | InitDepthPass(); // create material for depth pass
|
---|
| 658 | InitItemBufferPass(); // create material for item buffer pass
|
---|
| 659 |
|
---|
| 660 | // save ambient light to reset later
|
---|
| 661 | ColourValue savedAmbient = mAmbientLight;
|
---|
| 662 |
|
---|
[1593] | 663 | ////////////////////
|
---|
| 664 | //-- apply standard rendering for some modes
|
---|
| 665 | //-- (e.g., the visualization mode, the shadow pass)
|
---|
[675] | 666 |
|
---|
[1823] | 667 | if (mShowVisualization ||
|
---|
| 668 | (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE &&
|
---|
| 669 | mIlluminationStage == IRS_RENDER_TO_TEXTURE))
|
---|
[675] | 670 | {
|
---|
| 671 | IlluminationRenderStage savedStage = mIlluminationStage;
|
---|
| 672 |
|
---|
| 673 | if (mShowVisualization)
|
---|
[868] | 674 | {
|
---|
[675] | 675 | // disable illumination stage to prevent rendering shadows
|
---|
| 676 | mIlluminationStage = IRS_NONE;
|
---|
[868] | 677 | }
|
---|
[675] | 678 |
|
---|
| 679 | // standard rendering for shadow maps because of performance
|
---|
| 680 | TerrainSceneManager::_renderVisibleObjects();
|
---|
| 681 |
|
---|
| 682 | mIlluminationStage = savedStage;
|
---|
| 683 | }
|
---|
| 684 | else //-- the hierarchical culling algorithm
|
---|
| 685 | {
|
---|
[1251] | 686 | // note matt: this is also called in TerrainSceneManager: really necessary?
|
---|
[868] | 687 | mDestRenderSystem -> setLightingEnabled(false);
|
---|
| 688 |
|
---|
[675] | 689 | if (mUseItemBuffer)
|
---|
| 690 | {
|
---|
[1593] | 691 | // don't render backgrounds for item buffer
|
---|
[675] | 692 | clearSpecialCaseRenderQueues();
|
---|
| 693 | getRenderQueue()->clear();
|
---|
| 694 | }
|
---|
| 695 |
|
---|
[1593] | 696 | ////////////////////
|
---|
[675] | 697 | //-- hierarchical culling
|
---|
[1593] | 698 |
|
---|
[675] | 699 | // the objects of different layers (e.g., background, scene,
|
---|
| 700 | // overlay) must be identified and rendered one after another
|
---|
| 701 |
|
---|
[1593] | 702 | // first render all early skies
|
---|
[675] | 703 | clearSpecialCaseRenderQueues();
|
---|
| 704 | addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND);
|
---|
| 705 | addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY);
|
---|
| 706 | setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);
|
---|
| 707 |
|
---|
| 708 | TerrainSceneManager::_renderVisibleObjects();
|
---|
| 709 |
|
---|
| 710 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
| 711 | // delete previously rendered content
|
---|
| 712 | _deleteRenderedQueueGroups();
|
---|
| 713 | #endif
|
---|
| 714 |
|
---|
[1593] | 715 | ///////////////////
|
---|
[675] | 716 | //-- prepare queue for visible objects (i.e., all but overlay and skies late)
|
---|
[1593] | 717 |
|
---|
[675] | 718 | clearSpecialCaseRenderQueues();
|
---|
| 719 | addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_LATE);
|
---|
| 720 | addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
|
---|
[897] | 721 |
|
---|
[675] | 722 | // exclude this queues from hierarchical rendering
|
---|
| 723 | setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
|
---|
| 724 |
|
---|
| 725 | // set all necessary parameters for
|
---|
| 726 | // hierarchical visibility culling and rendering
|
---|
| 727 | InitVisibilityCulling(mCameraInProgress);
|
---|
| 728 |
|
---|
[897] | 729 |
|
---|
[675] | 730 | /**
|
---|
| 731 | * the hierarchical culling algorithm
|
---|
| 732 | * for depth pass: we just find objects and update depth buffer
|
---|
| 733 | * for "delayed" rendering: we render some passes afterwards
|
---|
| 734 | * e.g., transparents, because they need front-to-back sorting
|
---|
| 735 | **/
|
---|
| 736 |
|
---|
| 737 | mVisibilityManager->ApplyVisibilityCulling();
|
---|
| 738 |
|
---|
[868] | 739 | // delete remaining renderables from queue:
|
---|
| 740 | // all which are not in mLeavePassesInQueue)
|
---|
[675] | 741 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
| 742 | _deleteRenderedQueueGroups(mLeavePassesInQueue);
|
---|
| 743 | #endif
|
---|
| 744 |
|
---|
[1593] | 745 | /////////////
|
---|
[1251] | 746 | //-- reset parameters needed for special rendering
|
---|
| 747 |
|
---|
[675] | 748 | mIsDepthPassPhase = false;
|
---|
| 749 | mIsItemBufferPhase = false;
|
---|
| 750 | mSkipTransparents = false;
|
---|
[868] | 751 | mIsHierarchicalCulling = false;
|
---|
| 752 |
|
---|
[675] | 753 | mLeavePassesInQueue = 0;
|
---|
[897] | 754 |
|
---|
[1823] | 755 | // the shaded geometry is rendered in a second pass
|
---|
| 756 | if (mUseDepthPass)
|
---|
[675] | 757 | {
|
---|
[1593] | 758 | // add visible nodes found by the visibility culling algorithm
|
---|
[868] | 759 | NodeList::const_iterator it, it_end = mVisible.end();
|
---|
| 760 |
|
---|
| 761 | //getRenderQueue()->clear();
|
---|
| 762 | for (it = mVisible.begin(); it != it_end; ++ it)
|
---|
[675] | 763 | {
|
---|
| 764 | (*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false);
|
---|
| 765 | }
|
---|
| 766 | }
|
---|
[1602] | 767 |
|
---|
[1593] | 768 | /////////////
|
---|
[675] | 769 | //-- now we can render all remaining queue objects
|
---|
[868] | 770 | //-- used for depth pass, transparents, overlay
|
---|
[675] | 771 |
|
---|
[1597] | 772 | clearSpecialCaseRenderQueues();
|
---|
| 773 |
|
---|
[675] | 774 | TerrainSceneManager::_renderVisibleObjects();
|
---|
[1251] | 775 | } // end hierarchical culling
|
---|
[675] | 776 |
|
---|
| 777 | // HACK: set the new render level index, important to avoid cracks
|
---|
| 778 | // in terrain caused by LOD
|
---|
| 779 | TerrainRenderable::NextRenderLevelIndex();
|
---|
| 780 |
|
---|
| 781 | // reset ambient light
|
---|
| 782 | setAmbientLight(savedAmbient);
|
---|
| 783 |
|
---|
[1304] | 784 | // almost same effect as below
|
---|
| 785 | getRenderQueue()->clear(mDeleteQueueAfterRendering);
|
---|
[1251] | 786 |
|
---|
[1267] | 787 | if (0) WriteLog(); // write out stats
|
---|
[675] | 788 | }
|
---|
| 789 |
|
---|
| 790 | //-----------------------------------------------------------------------
|
---|
[720] | 791 | void OcclusionCullingSceneManager::_updateSceneGraph(Camera* cam)
|
---|
[675] | 792 | {
|
---|
[1276] | 793 | if (mNormalExecution)
|
---|
[868] | 794 | {
|
---|
| 795 | OctreeSceneManager::_updateSceneGraph(cam);
|
---|
| 796 | return;
|
---|
| 797 | }
|
---|
| 798 |
|
---|
[675] | 799 | mVisibilityManager->GetCullingManager()->SetHierarchyInterface(mHierarchyInterface);
|
---|
| 800 | mHierarchyInterface->SetRenderSystem(mDestRenderSystem);
|
---|
| 801 |
|
---|
| 802 | TerrainSceneManager::_updateSceneGraph(cam);
|
---|
| 803 | }
|
---|
| 804 | //-----------------------------------------------------------------------
|
---|
[720] | 805 | bool OcclusionCullingSceneManager::setOption(const String & key, const void * val)
|
---|
[675] | 806 | {
|
---|
| 807 | if (key == "UseDepthPass")
|
---|
| 808 | {
|
---|
| 809 | mUseDepthPass = (*static_cast<const bool *>(val));
|
---|
| 810 | return true;
|
---|
| 811 | }
|
---|
| 812 | if (key == "PrepareVisualization")
|
---|
| 813 | {
|
---|
| 814 | mShowVisualization = (*static_cast<const bool *>(val));
|
---|
| 815 | return true;
|
---|
| 816 | }
|
---|
| 817 | if (key == "RenderNodesForViz")
|
---|
| 818 | {
|
---|
| 819 | mRenderNodesForViz = (*static_cast<const bool *>(val));
|
---|
| 820 | return true;
|
---|
| 821 | }
|
---|
| 822 | if (key == "RenderNodesContentForViz")
|
---|
| 823 | {
|
---|
| 824 | mRenderNodesContentForViz = (*static_cast<const bool *>(val));
|
---|
| 825 | return true;
|
---|
| 826 | }
|
---|
| 827 | if (key == "SkyBoxEnabled")
|
---|
| 828 | {
|
---|
| 829 | mSkyBoxEnabled = (*static_cast<const bool *>(val));
|
---|
| 830 | return true;
|
---|
| 831 | }
|
---|
| 832 | if (key == "SkyPlaneEnabled")
|
---|
| 833 | {
|
---|
| 834 | mSkyPlaneEnabled = (*static_cast<const bool *>(val));
|
---|
| 835 | return true;
|
---|
| 836 | }
|
---|
| 837 | if (key == "SkyDomeEnabled")
|
---|
| 838 | {
|
---|
| 839 | mSkyDomeEnabled = (*static_cast<const bool *>(val));
|
---|
| 840 | return true;
|
---|
| 841 | }
|
---|
| 842 | if (key == "VisualizeCulledNodes")
|
---|
| 843 | {
|
---|
| 844 | mVisualizeCulledNodes = (*static_cast<const bool *>(val));
|
---|
| 845 | return true;
|
---|
| 846 | }
|
---|
| 847 | if (key == "DelayRenderTransparents")
|
---|
| 848 | {
|
---|
| 849 | mDelayRenderTransparents = (*static_cast<const bool *>(val));
|
---|
| 850 | return true;
|
---|
| 851 | }
|
---|
| 852 | if (key == "DepthWrite")
|
---|
| 853 | {
|
---|
| 854 | mEnableDepthWrite = (*static_cast<const bool *>(val));
|
---|
| 855 | return true;
|
---|
| 856 | }
|
---|
| 857 | if (key == "UseItemBuffer")
|
---|
| 858 | {
|
---|
| 859 | mUseItemBuffer = (*static_cast<const bool *>(val));
|
---|
| 860 | return true;
|
---|
| 861 | }
|
---|
| 862 | if (key == "ExecuteVertexProgramForAllPasses")
|
---|
| 863 | {
|
---|
| 864 | mExecuteVertexProgramForAllPasses = (*static_cast<const bool *>(val));
|
---|
| 865 | return true;
|
---|
| 866 | }
|
---|
| 867 | if (key == "RenderTransparentsForItemBuffer")
|
---|
| 868 | {
|
---|
| 869 | mRenderTransparentsForItemBuffer = (*static_cast<const bool *>(val));
|
---|
| 870 | return true;
|
---|
| 871 | }
|
---|
[1296] | 872 | else if (key == "DeleteRenderQueue")
|
---|
| 873 | {
|
---|
| 874 | mDeleteQueueAfterRendering = (*static_cast<const bool *>(val));
|
---|
| 875 | return true;
|
---|
| 876 | }
|
---|
[675] | 877 | if (key == "NodeVizScale")
|
---|
| 878 | {
|
---|
| 879 | OctreeNode::setVizScale(*static_cast<const float *>(val));
|
---|
| 880 | return true;
|
---|
| 881 | }
|
---|
[903] | 882 | if (key == "UseViewCells")
|
---|
[2097] | 883 | {
|
---|
| 884 | if (!mViewCellsLoaded)
|
---|
[938] | 885 | {
|
---|
[2097] | 886 | // try ro loaded view cells
|
---|
| 887 | mViewCellsLoaded = LoadViewCells(mViewCellsFilename);
|
---|
| 888 | }
|
---|
[903] | 889 |
|
---|
[2097] | 890 | if (!mViewCellsLoaded)
|
---|
| 891 | return false;
|
---|
| 892 |
|
---|
| 893 | // only use this option if view cells are available
|
---|
| 894 |
|
---|
| 895 | mUseViewCells = *static_cast<const bool *>(val);
|
---|
| 896 |
|
---|
| 897 | // reset view cell
|
---|
| 898 | OGRE_DELETE(mCurrentViewCell);
|
---|
[1595] | 899 |
|
---|
[2097] | 900 | if (mUseViewCells)
|
---|
| 901 | {
|
---|
| 902 | mCurrentViewCell = mViewCellsManager->GenerateViewCell();
|
---|
| 903 | }
|
---|
| 904 |
|
---|
| 905 | // view cell corresponding to leaf in the view cell hierarchy
|
---|
| 906 | mElementaryViewCell = NULL;
|
---|
[938] | 907 |
|
---|
[2097] | 908 | // with view cells all objects are set to invisible per default
|
---|
| 909 | SetObjectsVisible(!mUseViewCells);
|
---|
[1616] | 910 |
|
---|
[2097] | 911 | MovableObjectIterator movit = getMovableObjectIterator("Entity");
|
---|
| 912 | while (movit.hasMoreElements())
|
---|
| 913 | {
|
---|
| 914 | Entity *ent = static_cast<Entity *>(movit.getNext());
|
---|
| 915 | ent->setVisible(!mUseViewCells);
|
---|
[938] | 916 | }
|
---|
[2097] | 917 |
|
---|
[903] | 918 | return true;
|
---|
| 919 | }
|
---|
[1602] | 920 | if (key == "ShowViewCells")
|
---|
| 921 | {
|
---|
| 922 | // only use this option if view cells are available
|
---|
| 923 | if (mViewCellsLoaded)
|
---|
| 924 | {
|
---|
[1606] | 925 | mShowViewCells = *static_cast<const bool *>(val);
|
---|
[1602] | 926 | // if we decide use view cells
|
---|
| 927 | // all objects are set to invisible per default
|
---|
[1606] | 928 | VisualizeViewCells(mShowViewCells);
|
---|
[1602] | 929 | }
|
---|
| 930 |
|
---|
| 931 | return true;
|
---|
| 932 | }
|
---|
[1276] | 933 | if (key == "NormalExecution")
|
---|
| 934 | {
|
---|
| 935 | mNormalExecution = *static_cast<const bool *>(val);
|
---|
| 936 | return true;
|
---|
| 937 | }
|
---|
[903] | 938 | if (key == "UseVisibilityFilter")
|
---|
[675] | 939 | {
|
---|
[903] | 940 | mUseVisibilityFilter = *static_cast<const bool *>(val);
|
---|
[1823] | 941 |
|
---|
| 942 | // set null => recomputation of the pvs
|
---|
[903] | 943 | mElementaryViewCell = NULL;
|
---|
| 944 | return true;
|
---|
| 945 | }
|
---|
[1823] | 946 | if (key == "ViewCellsLoaded")
|
---|
| 947 | {
|
---|
| 948 | return mViewCellsLoaded;
|
---|
| 949 | }
|
---|
[675] | 950 |
|
---|
| 951 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
| 952 | setOption(key, val) || TerrainSceneManager::setOption(key, val);
|
---|
| 953 | }
|
---|
| 954 | //-----------------------------------------------------------------------
|
---|
[1816] | 955 | bool OcclusionCullingSceneManager::getOption(const String &key, void *val)
|
---|
[675] | 956 | {
|
---|
| 957 | if (key == "NumHierarchyNodes")
|
---|
| 958 | {
|
---|
| 959 | * static_cast<unsigned int *>(val) = (unsigned int)mNumOctants;
|
---|
| 960 | return true;
|
---|
| 961 | }
|
---|
[925] | 962 | if (key == "VisibilityManager")
|
---|
| 963 | {
|
---|
| 964 | * static_cast<GtpVisibility::VisibilityManager **>(val) =
|
---|
| 965 | (GtpVisibility::VisibilityManager *)mVisibilityManager;
|
---|
| 966 | return true;
|
---|
| 967 | }
|
---|
| 968 | if (key == "HierarchInterface")
|
---|
| 969 | {
|
---|
| 970 | * static_cast<GtpVisibility::HierarchyInterface **>(val) =
|
---|
| 971 | (GtpVisibility::HierarchyInterface *)mHierarchyInterface;
|
---|
| 972 | return true;
|
---|
| 973 | }
|
---|
[1816] | 974 | if (key == "ShowTerrain")
|
---|
| 975 | {
|
---|
| 976 | * static_cast<bool *>(val) = (bool *)mShowTerrain;
|
---|
| 977 | return true;
|
---|
| 978 | }
|
---|
[1823] | 979 | if (key == "UseDepthPass")
|
---|
| 980 | {
|
---|
| 981 | * static_cast<bool *>(val) = (bool *)mUseDepthPass;
|
---|
| 982 | return true;
|
---|
| 983 | }
|
---|
| 984 | if (key == "AlgorithmType")
|
---|
| 985 | {
|
---|
| 986 | GtpVisibility::VisibilityEnvironment::CullingManagerType algorithm =
|
---|
| 987 | mVisibilityManager->GetCullingManagerType();
|
---|
[925] | 988 |
|
---|
[1823] | 989 | * static_cast<unsigned int *>(val) =
|
---|
| 990 | (unsigned int)algorithm;
|
---|
| 991 | return true;
|
---|
| 992 | }
|
---|
| 993 |
|
---|
[675] | 994 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
| 995 | getOption(key, val) && TerrainSceneManager::getOption(key, val);
|
---|
| 996 | }
|
---|
| 997 | //-----------------------------------------------------------------------
|
---|
[720] | 998 | bool OcclusionCullingSceneManager::getOptionValues(const String & key,
|
---|
[675] | 999 | StringVector &refValueList)
|
---|
| 1000 | {
|
---|
| 1001 | return TerrainSceneManager::getOptionValues( key, refValueList);
|
---|
| 1002 | }
|
---|
| 1003 | //-----------------------------------------------------------------------
|
---|
[720] | 1004 | bool OcclusionCullingSceneManager::getOptionKeys(StringVector & refKeys)
|
---|
[675] | 1005 | {
|
---|
| 1006 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
| 1007 | getOptionKeys(refKeys) || TerrainSceneManager::getOptionKeys(refKeys);
|
---|
| 1008 | }
|
---|
| 1009 | //-----------------------------------------------------------------------
|
---|
[720] | 1010 | void OcclusionCullingSceneManager::setVisibilityManager(GtpVisibility::
|
---|
[675] | 1011 | VisibilityManager *visManager)
|
---|
| 1012 | {
|
---|
| 1013 | mVisibilityManager = visManager;
|
---|
| 1014 | }
|
---|
| 1015 | //-----------------------------------------------------------------------
|
---|
[720] | 1016 | GtpVisibility::VisibilityManager *OcclusionCullingSceneManager::getVisibilityManager( void )
|
---|
[675] | 1017 | {
|
---|
| 1018 | return mVisibilityManager;
|
---|
| 1019 | }
|
---|
| 1020 | //-----------------------------------------------------------------------
|
---|
[720] | 1021 | void OcclusionCullingSceneManager::WriteLog()
|
---|
[675] | 1022 | {
|
---|
| 1023 | std::stringstream d;
|
---|
| 1024 |
|
---|
| 1025 | d << "Depth pass: " << StringConverter::toString(mUseDepthPass) << ", "
|
---|
| 1026 | << "Delay transparents: " << StringConverter::toString(mDelayRenderTransparents) << ", "
|
---|
| 1027 | << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetTestGeometryForVisibleLeaves()) << ", "
|
---|
| 1028 | << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << ", "
|
---|
| 1029 | << "Hierarchy nodes: " << mNumOctants << ", "
|
---|
| 1030 | << "Traversed nodes: " << mHierarchyInterface->GetNumTraversedNodes() << ", "
|
---|
| 1031 | << "Rendered nodes: " << mHierarchyInterface->GetNumRenderedNodes() << ", "
|
---|
| 1032 | << "Query culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumQueryCulledNodes() << ", "
|
---|
| 1033 | << "Frustum culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumFrustumCulledNodes() << ", "
|
---|
[868] | 1034 | << "Queries issued: " << mVisibilityManager->GetCullingManager()->GetNumQueriesIssued() << ", "
|
---|
| 1035 | << "Found objects: " << (int)mVisible.size() << "\n";
|
---|
[675] | 1036 |
|
---|
| 1037 | LogManager::getSingleton().logMessage(d.str());
|
---|
| 1038 | }
|
---|
| 1039 | //-----------------------------------------------------------------------
|
---|
[925] | 1040 | void OcclusionCullingSceneManager::renderBasicQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
| 1041 | QueuedRenderableCollection::OrganisationMode om)
|
---|
[675] | 1042 | {
|
---|
[925] | 1043 | // Basic render loop
|
---|
| 1044 | // Iterate through priorities
|
---|
| 1045 | RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
|
---|
| 1046 |
|
---|
| 1047 | while (groupIt.hasMoreElements())
|
---|
| 1048 | {
|
---|
| 1049 | RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
|
---|
| 1050 |
|
---|
| 1051 | // Sort the queue first
|
---|
| 1052 | pPriorityGrp->sort(mCameraInProgress);
|
---|
| 1053 |
|
---|
| 1054 | // Do solids
|
---|
| 1055 | renderObjects(pPriorityGrp->getSolidsBasic(), om, true);
|
---|
| 1056 |
|
---|
[1593] | 1057 | // for correct rendering, transparents must be rendered
|
---|
| 1058 | // after hierarchical culling => don't render them now
|
---|
[925] | 1059 |
|
---|
[1593] | 1060 | if (mNormalExecution || !mSkipTransparents)
|
---|
[925] | 1061 | {
|
---|
[1593] | 1062 | // Do transparents (always descending)
|
---|
[925] | 1063 | renderObjects(pPriorityGrp->getTransparents(),
|
---|
[1597] | 1064 | QueuedRenderableCollection::OM_SORT_DESCENDING, true);
|
---|
[925] | 1065 | }
|
---|
| 1066 |
|
---|
| 1067 |
|
---|
[1593] | 1068 | } // for each priority
|
---|
[675] | 1069 | }
|
---|
[925] | 1070 |
|
---|
[675] | 1071 | //-----------------------------------------------------------------------
|
---|
[720] | 1072 | bool OcclusionCullingSceneManager::validatePassForRendering(Pass* pass)
|
---|
[675] | 1073 | {
|
---|
[1276] | 1074 | if (mNormalExecution)
|
---|
[868] | 1075 | {
|
---|
| 1076 | return SceneManager::validatePassForRendering(pass);
|
---|
| 1077 | }
|
---|
| 1078 |
|
---|
[675] | 1079 | // skip all but first pass if we are doing the depth pass
|
---|
[868] | 1080 | if ((mIsDepthPassPhase || mIsItemBufferPhase) && (pass->getIndex() > 0))
|
---|
[675] | 1081 | {
|
---|
| 1082 | return false;
|
---|
| 1083 | }
|
---|
[868] | 1084 | // all but first pass
|
---|
| 1085 | /*else if ((!mIsDepthPassPhase || mIsItemBufferPhase) && (pass->getIndex() != 0))
|
---|
| 1086 | {
|
---|
| 1087 | return false;
|
---|
| 1088 | }*/
|
---|
[675] | 1089 |
|
---|
| 1090 | return SceneManager::validatePassForRendering(pass);
|
---|
| 1091 | }
|
---|
| 1092 | //-----------------------------------------------------------------------
|
---|
[897] | 1093 | void OcclusionCullingSceneManager::_renderQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
| 1094 | QueuedRenderableCollection::OrganisationMode om)
|
---|
[675] | 1095 | {
|
---|
[1276] | 1096 | if (mNormalExecution || !mIsItemBufferPhase)
|
---|
[675] | 1097 | {
|
---|
[897] | 1098 | TerrainSceneManager::_renderQueueGroupObjects(pGroup, om);
|
---|
[675] | 1099 | return;
|
---|
| 1100 | }
|
---|
[897] | 1101 | #ifdef ITEM_BUFFER
|
---|
| 1102 | //-- item buffer
|
---|
[1622] | 1103 | //-- render objects using false colors
|
---|
[675] | 1104 |
|
---|
| 1105 | // Iterate through priorities
|
---|
| 1106 | RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
|
---|
| 1107 |
|
---|
| 1108 | while (groupIt.hasMoreElements())
|
---|
| 1109 | {
|
---|
| 1110 | RenderItemBuffer(groupIt.getNext());
|
---|
| 1111 | }
|
---|
[897] | 1112 | #endif // ITEM_BUFFER
|
---|
[675] | 1113 | }
|
---|
[897] | 1114 | #ifdef ITEM_BUFFER
|
---|
[675] | 1115 | //-----------------------------------------------------------------------
|
---|
[720] | 1116 | void OcclusionCullingSceneManager::RenderItemBuffer(RenderPriorityGroup* pGroup)
|
---|
[675] | 1117 | {
|
---|
| 1118 | // Do solids
|
---|
[897] | 1119 | QueuedRenderableCollection solidObjs = pGroup->getSolidsBasic();//msz
|
---|
[675] | 1120 |
|
---|
| 1121 | // ----- SOLIDS LOOP -----
|
---|
| 1122 | RenderPriorityGroup::SolidRenderablePassMap::const_iterator ipass, ipassend;
|
---|
| 1123 | ipassend = solidObjs.end();
|
---|
| 1124 |
|
---|
| 1125 | for (ipass = solidObjs.begin(); ipass != ipassend; ++ipass)
|
---|
| 1126 | {
|
---|
| 1127 | // Fast bypass if this group is now empty
|
---|
| 1128 | if (ipass->second->empty())
|
---|
| 1129 | continue;
|
---|
| 1130 |
|
---|
[868] | 1131 | // Render only first pass of renderable as false color
|
---|
[675] | 1132 | if (ipass->first->getIndex() > 0)
|
---|
| 1133 | continue;
|
---|
| 1134 |
|
---|
| 1135 | RenderPriorityGroup::RenderableList* rendList = ipass->second;
|
---|
| 1136 |
|
---|
| 1137 | RenderPriorityGroup::RenderableList::const_iterator irend, irendend;
|
---|
| 1138 | irendend = rendList->end();
|
---|
| 1139 |
|
---|
| 1140 | for (irend = rendList->begin(); irend != irendend; ++irend)
|
---|
| 1141 | {
|
---|
[868] | 1142 | if (0)
|
---|
| 1143 | {
|
---|
[1593] | 1144 | std::stringstream d; d << "itembuffer, pass name: " <<
|
---|
| 1145 | ipass->first->getParent()->getParent()->getName();
|
---|
| 1146 |
|
---|
| 1147 | LogManager::getSingleton().logMessage(d.str());
|
---|
[868] | 1148 | }
|
---|
[675] | 1149 |
|
---|
| 1150 | RenderSingleObjectForItemBuffer(*irend, ipass->first);
|
---|
| 1151 | }
|
---|
| 1152 | }
|
---|
| 1153 |
|
---|
[1816] | 1154 | ///////////
|
---|
[868] | 1155 | //-- TRANSPARENT LOOP: must be handled differently from solids
|
---|
[675] | 1156 |
|
---|
| 1157 | // transparents are treated either as solids or completely discarded
|
---|
| 1158 | if (mRenderTransparentsForItemBuffer)
|
---|
| 1159 | {
|
---|
[897] | 1160 | QueuedRenderableCollection transpObjs = pGroup->getTransparents(); //msz
|
---|
[675] | 1161 | RenderPriorityGroup::TransparentRenderablePassList::const_iterator
|
---|
| 1162 | itrans, itransend;
|
---|
| 1163 |
|
---|
| 1164 | itransend = transpObjs.end();
|
---|
| 1165 | for (itrans = transpObjs.begin(); itrans != itransend; ++itrans)
|
---|
| 1166 | {
|
---|
| 1167 | // like for solids, render only first pass
|
---|
| 1168 | if (itrans->pass->getIndex() == 0)
|
---|
| 1169 | {
|
---|
| 1170 | RenderSingleObjectForItemBuffer(itrans->renderable, itrans->pass);
|
---|
| 1171 | }
|
---|
| 1172 | }
|
---|
| 1173 | }
|
---|
| 1174 | }
|
---|
| 1175 | //-----------------------------------------------------------------------
|
---|
[720] | 1176 | void OcclusionCullingSceneManager::RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass)
|
---|
[675] | 1177 | {
|
---|
| 1178 | static LightList nullLightList;
|
---|
| 1179 |
|
---|
| 1180 | int col[4];
|
---|
| 1181 |
|
---|
| 1182 | // -- create color code out of object id
|
---|
| 1183 | col[0] = (rend->getId() >> 16) & 255;
|
---|
| 1184 | col[1] = (rend->getId() >> 8) & 255;
|
---|
| 1185 | col[2] = rend->getId() & 255;
|
---|
| 1186 | // col[3] = 255;
|
---|
| 1187 |
|
---|
| 1188 | //mDestRenderSystem->setColour(col[0], col[1], col[2], col[3]);
|
---|
| 1189 |
|
---|
| 1190 | mItemBufferPass->setAmbient(ColourValue(col[0] / 255.0f,
|
---|
| 1191 | col[1] / 255.0f,
|
---|
| 1192 | col[2] / 255.0f, 1));
|
---|
| 1193 |
|
---|
| 1194 | // set vertex program of current pass
|
---|
| 1195 | if (mExecuteVertexProgramForAllPasses && pass->hasVertexProgram())
|
---|
| 1196 | {
|
---|
| 1197 | mItemBufferPass->setVertexProgram(pass->getVertexProgramName());
|
---|
| 1198 |
|
---|
| 1199 | if (mItemBufferPass->hasVertexProgram())
|
---|
| 1200 | {
|
---|
| 1201 | const GpuProgramPtr& prg = mItemBufferPass->getVertexProgram();
|
---|
| 1202 | // Load this program if not done already
|
---|
| 1203 | if (!prg->isLoaded())
|
---|
| 1204 | prg->load();
|
---|
| 1205 | // Copy params
|
---|
| 1206 | mItemBufferPass->setVertexProgramParameters(pass->getVertexProgramParameters());
|
---|
| 1207 | }
|
---|
| 1208 | }
|
---|
| 1209 | else if (mItemBufferPass->hasVertexProgram())
|
---|
| 1210 | {
|
---|
| 1211 | mItemBufferPass->setVertexProgram("");
|
---|
| 1212 | }
|
---|
| 1213 |
|
---|
[897] | 1214 | const Pass *usedPass = _setPass(mItemBufferPass);
|
---|
[675] | 1215 |
|
---|
| 1216 |
|
---|
[903] | 1217 | // render a single object, this will set up auto params if required
|
---|
[675] | 1218 | renderSingleObject(rend, usedPass, false, &nullLightList);
|
---|
| 1219 | }
|
---|
[897] | 1220 | #endif // ITEM_BUFFER
|
---|
[675] | 1221 | //-----------------------------------------------------------------------
|
---|
[720] | 1222 | GtpVisibility::VisibilityManager *OcclusionCullingSceneManager::GetVisibilityManager()
|
---|
[675] | 1223 | {
|
---|
| 1224 | return mVisibilityManager;
|
---|
| 1225 | }
|
---|
| 1226 | //-----------------------------------------------------------------------
|
---|
[720] | 1227 | void OcclusionCullingSceneManager::InitVisibilityCulling(Camera *cam)
|
---|
[675] | 1228 | {
|
---|
| 1229 | // reset culling manager stats
|
---|
| 1230 | mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes);
|
---|
| 1231 |
|
---|
| 1232 | // set depth pass flag before rendering
|
---|
| 1233 | mIsDepthPassPhase = mUseDepthPass;
|
---|
| 1234 |
|
---|
[868] | 1235 | mIsHierarchicalCulling = true; // during hierarchical culling
|
---|
| 1236 |
|
---|
[675] | 1237 | // item buffer needs full ambient lighting to use item colors as unique id
|
---|
| 1238 | if (mUseItemBuffer)
|
---|
| 1239 | {
|
---|
| 1240 | mIsItemBufferPhase = true;
|
---|
| 1241 | setAmbientLight(ColourValue(1,1,1,1));
|
---|
| 1242 | }
|
---|
| 1243 |
|
---|
| 1244 |
|
---|
| 1245 | // set passes which are stored in render queue
|
---|
| 1246 | // for rendering AFTER hierarchical culling, i.e., passes which need
|
---|
| 1247 | // a special rendering order
|
---|
[868] | 1248 |
|
---|
[675] | 1249 | mLeavePassesInQueue = 0;
|
---|
| 1250 |
|
---|
[897] | 1251 | // if we have the depth pass or use an item buffer, no passes are left in the queue
|
---|
| 1252 | if (1 && !mUseDepthPass && !mUseItemBuffer)
|
---|
[675] | 1253 | {
|
---|
| 1254 | if (mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
|
---|
| 1255 | {
|
---|
| 1256 | // TODO: remove this pass because it should be processed during hierarchical culling
|
---|
| 1257 | //mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
|
---|
| 1258 |
|
---|
| 1259 | mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DECAL;
|
---|
| 1260 | mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DIFFUSE_SPECULAR;
|
---|
| 1261 | mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
|
---|
| 1262 |
|
---|
[903] | 1263 | // just render ambient passes
|
---|
[897] | 1264 | /*** msz: no more IRS_AMBIENT, see OgreSceneManager.h ***/
|
---|
| 1265 | // mIlluminationStage = IRS_AMBIENT;
|
---|
[925] | 1266 | //getRenderQueue()->setSplitPassesByLightingType(true);
|
---|
[675] | 1267 | }
|
---|
| 1268 |
|
---|
| 1269 | if (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE)
|
---|
| 1270 | {
|
---|
| 1271 | mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
|
---|
| 1272 | mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
|
---|
| 1273 | }
|
---|
| 1274 |
|
---|
| 1275 | // transparents should be rendered after hierarchical culling to
|
---|
| 1276 | // provide front-to-back ordering
|
---|
| 1277 | if (mDelayRenderTransparents)
|
---|
| 1278 | {
|
---|
| 1279 | mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
|
---|
| 1280 | }
|
---|
| 1281 | }
|
---|
| 1282 |
|
---|
[868] | 1283 | // skip rendering transparents during the hierarchical culling
|
---|
[675] | 1284 | // (because they will be rendered afterwards)
|
---|
[868] | 1285 | mSkipTransparents =
|
---|
| 1286 | (mIsDepthPassPhase || (mLeavePassesInQueue & RenderPriorityGroup::TRANSPARENT_PASSES));
|
---|
[675] | 1287 |
|
---|
| 1288 | // -- initialise interface for rendering traversal of the hierarchy
|
---|
| 1289 | mHierarchyInterface->SetHierarchyRoot(mOctree);
|
---|
| 1290 |
|
---|
| 1291 | // possible two cameras (one for culling, one for rendering)
|
---|
| 1292 | mHierarchyInterface->InitTraversal(mCameraInProgress,
|
---|
| 1293 | mCullCamera ? getCamera("CullCamera") : NULL,
|
---|
| 1294 | mLeavePassesInQueue);
|
---|
| 1295 |
|
---|
| 1296 | }
|
---|
| 1297 | //-----------------------------------------------------------------------
|
---|
[720] | 1298 | OctreeHierarchyInterface *OcclusionCullingSceneManager::GetHierarchyInterface()
|
---|
[675] | 1299 | {
|
---|
| 1300 | return mHierarchyInterface;
|
---|
| 1301 | }
|
---|
| 1302 | //-----------------------------------------------------------------------
|
---|
[720] | 1303 | void OcclusionCullingSceneManager::endFrame()
|
---|
[675] | 1304 | {
|
---|
| 1305 | TerrainRenderable::ResetRenderLevelIndex();
|
---|
| 1306 | }
|
---|
| 1307 | //-----------------------------------------------------------------------
|
---|
[720] | 1308 | Entity* OcclusionCullingSceneManager::createEntity(const String& entityName,
|
---|
[675] | 1309 | const String& meshName)
|
---|
| 1310 | {
|
---|
| 1311 | Entity *ent = SceneManager::createEntity(entityName, meshName);
|
---|
| 1312 |
|
---|
| 1313 | for (int i = 0; i < (int)ent->getNumSubEntities(); ++i)
|
---|
| 1314 | {
|
---|
| 1315 | ent->getSubEntity(i)->setId(mCurrentEntityId);
|
---|
| 1316 | }
|
---|
| 1317 |
|
---|
| 1318 | // increase counter of entity id values
|
---|
| 1319 | ++ mCurrentEntityId;
|
---|
| 1320 |
|
---|
| 1321 | return ent;
|
---|
| 1322 | }
|
---|
| 1323 | //-----------------------------------------------------------------------
|
---|
[897] | 1324 | void OcclusionCullingSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(
|
---|
| 1325 | RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om)
|
---|
[675] | 1326 | {
|
---|
| 1327 | // only render solid passes during hierarchical culling
|
---|
| 1328 | if (mIsHierarchicalCulling)
|
---|
| 1329 | {
|
---|
| 1330 | RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
|
---|
| 1331 | LightList lightList;
|
---|
| 1332 |
|
---|
| 1333 | while (groupIt.hasMoreElements())
|
---|
| 1334 | {
|
---|
| 1335 | RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
|
---|
| 1336 |
|
---|
| 1337 | // Sort the queue first
|
---|
| 1338 | pPriorityGrp->sort(mCameraInProgress);
|
---|
| 1339 |
|
---|
| 1340 | // Clear light list
|
---|
| 1341 | lightList.clear();
|
---|
| 1342 |
|
---|
| 1343 | // Render all the ambient passes first, no light iteration, no lights
|
---|
[897] | 1344 | /*** msz: no more IRS_AMBIENT, see OgreSceneManager.h ***/
|
---|
| 1345 | // mIlluminationStage = IRS_AMBIENT;
|
---|
[675] | 1346 |
|
---|
[897] | 1347 | OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsBasic(), om, false, &lightList);
|
---|
[675] | 1348 | // Also render any objects which have receive shadows disabled
|
---|
[897] | 1349 | OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsNoShadowReceive(), om, true);
|
---|
[903] | 1350 | #if 0
|
---|
| 1351 | std::stringstream d;
|
---|
| 1352 | d << " solid size: " << (int)pPriorityGrp->_getSolidPasses().size()
|
---|
| 1353 | << " solid no shadow size: " << (int)pPriorityGrp->_getSolidPassesNoShadow().size()
|
---|
| 1354 | << "difspec size: " << (int)pPriorityGrp->_getSolidPassesDiffuseSpecular().size()
|
---|
| 1355 | << " decal size: " << (int)pPriorityGrp->_getSolidPassesDecal().size();
|
---|
| 1356 | LogManager::getSingleton().logMessage(d.str());
|
---|
| 1357 | #endif
|
---|
[675] | 1358 | }
|
---|
| 1359 | }
|
---|
[903] | 1360 | else // render the rest of the passes
|
---|
[675] | 1361 | {
|
---|
[897] | 1362 | OctreeSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(pGroup, om);
|
---|
[675] | 1363 | }
|
---|
| 1364 | }
|
---|
| 1365 | //-----------------------------------------------------------------------
|
---|
[897] | 1366 | void OcclusionCullingSceneManager::renderModulativeStencilShadowedQueueGroupObjects(
|
---|
| 1367 | RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om)
|
---|
[675] | 1368 | {
|
---|
| 1369 | if (mIsHierarchicalCulling)
|
---|
| 1370 | {
|
---|
| 1371 | // Iterate through priorities
|
---|
| 1372 | RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
|
---|
| 1373 |
|
---|
| 1374 | while (groupIt.hasMoreElements())
|
---|
| 1375 | {
|
---|
| 1376 | RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
|
---|
| 1377 |
|
---|
| 1378 | // Sort the queue first
|
---|
| 1379 | pPriorityGrp->sort(mCameraInProgress);
|
---|
| 1380 | // Do (shadowable) solids
|
---|
[897] | 1381 | OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsBasic(), om, true);
|
---|
[675] | 1382 | }
|
---|
| 1383 | }
|
---|
| 1384 | else
|
---|
| 1385 | {
|
---|
[931] | 1386 | OctreeSceneManager::renderModulativeStencilShadowedQueueGroupObjects(pGroup, om);
|
---|
[675] | 1387 | }
|
---|
| 1388 | }
|
---|
[903] | 1389 | //-------------------------------------------------------------------------
|
---|
| 1390 | void OcclusionCullingSceneManager::SetObjectsVisible(const bool visible)
|
---|
| 1391 | {
|
---|
| 1392 | GtpVisibilityPreprocessor::ObjectContainer::iterator it, it_end = mObjects.end();
|
---|
[828] | 1393 |
|
---|
[903] | 1394 | for (it = mObjects.begin(); it != it_end; ++ it)
|
---|
| 1395 | {
|
---|
[1616] | 1396 | GtpVisibilityPreprocessor::Intersectable *entry = *it;
|
---|
| 1397 |
|
---|
| 1398 | switch (entry->Type())
|
---|
| 1399 | {
|
---|
| 1400 | case GtpVisibilityPreprocessor::Intersectable::OGRE_MESH_INSTANCE:
|
---|
| 1401 | {
|
---|
[2066] | 1402 | OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(entry);
|
---|
[1616] | 1403 | omi->GetEntity()->setVisible(visible);
|
---|
| 1404 | //GtpVisibilityPreprocessor::Debug << "assigned id " << omi->GetId() << endl;
|
---|
| 1405 | }
|
---|
| 1406 | break;
|
---|
[2066] | 1407 | case GtpVisibilityPreprocessor::Intersectable::ENGINE_INTERSECTABLE:
|
---|
[1616] | 1408 | {
|
---|
[2066] | 1409 | EngineIntersectable *oi = static_cast<EngineIntersectable *>(entry);
|
---|
[1616] | 1410 |
|
---|
| 1411 | EntityContainer *entries = oi->GetItem();
|
---|
| 1412 | EntityContainer::const_iterator eit,
|
---|
| 1413 | eit_end = entries->end();
|
---|
| 1414 | for (eit = entries->begin(); eit != eit_end; ++ eit)
|
---|
| 1415 | {
|
---|
| 1416 | Entity *ent = *eit;
|
---|
| 1417 | ent->setVisible(visible);
|
---|
| 1418 | }
|
---|
| 1419 | }
|
---|
| 1420 | break;
|
---|
| 1421 | default:
|
---|
| 1422 | break;
|
---|
| 1423 | }
|
---|
[903] | 1424 | }
|
---|
| 1425 | }
|
---|
| 1426 | //-----------------------------------------------------------------------
|
---|
[938] | 1427 | bool OcclusionCullingSceneManager::LoadViewCells(const String &filename)
|
---|
[863] | 1428 | {
|
---|
[2097] | 1429 | // no filename specified
|
---|
[1823] | 1430 | if (filename == "")
|
---|
| 1431 | return false;
|
---|
| 1432 |
|
---|
[2097] | 1433 | // view cells already loaded
|
---|
[1676] | 1434 | if (mViewCellsLoaded)
|
---|
| 1435 | return true;
|
---|
| 1436 |
|
---|
[938] | 1437 | // converter between view cell ids and Ogre entites
|
---|
[1595] | 1438 | OctreeBoundingBoxConverter bconverter(this);
|
---|
[931] | 1439 |
|
---|
[863] | 1440 | // load the view cells assigning the found objects to the pvss
|
---|
[2097] | 1441 | const bool finalizeViewCells = false;
|
---|
[903] | 1442 |
|
---|
[1823] | 1443 | mViewCellsManager = GtpVisibilityPreprocessor::
|
---|
| 1444 | ViewCellsManager::LoadViewCells(filename,
|
---|
| 1445 | &mObjects,
|
---|
| 1446 | true,
|
---|
| 1447 | &bconverter);
|
---|
[2097] | 1448 |
|
---|
| 1449 | Ogre::LogManager::getSingleton().logMessage("*******************");
|
---|
[1823] | 1450 |
|
---|
[1620] | 1451 | // objects are set to invisible initially
|
---|
| 1452 | SetObjectsVisible(false);
|
---|
[1616] | 1453 |
|
---|
[1593] | 1454 | if (finalizeViewCells)
|
---|
| 1455 | {
|
---|
| 1456 | CreateViewCellsGeometry();
|
---|
| 1457 | }
|
---|
| 1458 |
|
---|
[938] | 1459 | return (mViewCellsManager != NULL);
|
---|
[863] | 1460 | }
|
---|
[903] | 1461 | //-------------------------------------------------------------------------
|
---|
[1593] | 1462 | void OcclusionCullingSceneManager::ApplyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc,
|
---|
[903] | 1463 | const bool load)
|
---|
[2097] | 1464 | {
|
---|
| 1465 | // NOTE: should not encounter NULL view cell,
|
---|
[1593] | 1466 | // rather apply view cell representing unbounded space then
|
---|
[903] | 1467 | if (!vc)
|
---|
| 1468 | {
|
---|
[2097] | 1469 | LogManager::getSingleton().logMessage("error: should not come here");
|
---|
| 1470 | // question: if no view cell, set everything visible?
|
---|
[1616] | 1471 | //SetObjectsVisible(true);
|
---|
[1622] | 1472 | SetObjectsVisible(false);
|
---|
[903] | 1473 | return;
|
---|
| 1474 | }
|
---|
[944] | 1475 |
|
---|
[1816] | 1476 | GtpVisibilityPreprocessor::ObjectPvsIterator pit = vc->GetPvs().GetIterator();
|
---|
[903] | 1477 |
|
---|
[1593] | 1478 | ////////////
|
---|
| 1479 | //-- set PVS of view cell to visible
|
---|
| 1480 |
|
---|
[2097] | 1481 | std::stringstream d; d << "appying new view cell pvs: " << vc->GetPvs().GetSize();
|
---|
| 1482 | LogManager::getSingleton().logMessage(d.str());
|
---|
| 1483 |
|
---|
[1816] | 1484 | while (pit.HasMoreEntries())
|
---|
| 1485 | {
|
---|
| 1486 | GtpVisibilityPreprocessor::ObjectPvsEntry entry = pit.Next();
|
---|
| 1487 | GtpVisibilityPreprocessor::Intersectable *obj = entry.mObject;
|
---|
| 1488 |
|
---|
[1610] | 1489 | // no associated geometry found
|
---|
[1816] | 1490 | if (!obj) continue;
|
---|
[1616] | 1491 |
|
---|
[1816] | 1492 | switch (obj->Type())
|
---|
[1616] | 1493 | {
|
---|
| 1494 | case GtpVisibilityPreprocessor::Intersectable::OGRE_MESH_INSTANCE:
|
---|
| 1495 | {
|
---|
[2066] | 1496 | OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(obj);
|
---|
[1616] | 1497 | omi->GetEntity()->setVisible(load);
|
---|
[2097] | 1498 | }
|
---|
[1616] | 1499 | break;
|
---|
[2066] | 1500 | case GtpVisibilityPreprocessor::Intersectable::ENGINE_INTERSECTABLE:
|
---|
[1616] | 1501 | {
|
---|
[2066] | 1502 | EngineIntersectable *oi = static_cast<EngineIntersectable *>(obj);
|
---|
[903] | 1503 |
|
---|
[1616] | 1504 | EntityContainer *entries = oi->GetItem();
|
---|
| 1505 |
|
---|
[1816] | 1506 | EntityContainer::const_iterator eit, eit_end = entries->end();
|
---|
| 1507 |
|
---|
[1616] | 1508 | for (eit = entries->begin(); eit != eit_end; ++ eit)
|
---|
| 1509 | {
|
---|
| 1510 | Entity *ent = *eit;
|
---|
| 1511 | ent->setVisible(load);
|
---|
| 1512 | }
|
---|
| 1513 | }
|
---|
| 1514 | break;
|
---|
| 1515 | default:
|
---|
| 1516 | break;
|
---|
| 1517 | }
|
---|
[863] | 1518 | }
|
---|
| 1519 | }
|
---|
[903] | 1520 | //-------------------------------------------------------------------------
|
---|
[1593] | 1521 | void OcclusionCullingSceneManager::UpdatePvs(Camera *cam)
|
---|
[903] | 1522 | {
|
---|
[938] | 1523 | if (!(mViewCellsLoaded && mUseViewCells))
|
---|
| 1524 | return;
|
---|
[863] | 1525 |
|
---|
[938] | 1526 | const GtpVisibilityPreprocessor::Vector3 viewPoint =
|
---|
| 1527 | OgreTypeConverter::ConvertFromOgre(cam->getDerivedPosition());
|
---|
[903] | 1528 |
|
---|
[2097] | 1529 | //std::stringstream d; d << "vp: " << viewPoint;
|
---|
| 1530 | //LogManager::getSingleton().logMessage(d.str());
|
---|
| 1531 |
|
---|
[938] | 1532 | GtpVisibilityPreprocessor::ViewCell *newElementary =
|
---|
| 1533 | mViewCellsManager->GetViewCell(viewPoint);
|
---|
[903] | 1534 |
|
---|
[2097] | 1535 | // elementary view cell did not change => don't change pvs
|
---|
[938] | 1536 | if (mElementaryViewCell == newElementary)
|
---|
| 1537 | return;
|
---|
[903] | 1538 |
|
---|
[938] | 1539 | mElementaryViewCell = newElementary;
|
---|
[1593] | 1540 |
|
---|
| 1541 |
|
---|
| 1542 | //////////////
|
---|
[938] | 1543 | //-- unload old pvs
|
---|
[903] | 1544 |
|
---|
[1593] | 1545 | ApplyViewCellPvs(mCurrentViewCell, false);
|
---|
[903] | 1546 |
|
---|
[1593] | 1547 | // the new view cell
|
---|
[938] | 1548 | GtpVisibilityPreprocessor::ViewCell *viewCell;
|
---|
[903] | 1549 |
|
---|
[938] | 1550 | if (mUseVisibilityFilter)
|
---|
[1593] | 1551 | {
|
---|
| 1552 | ////////////
|
---|
[938] | 1553 | //-- compute new filtered cell
|
---|
[1593] | 1554 |
|
---|
[938] | 1555 | GtpVisibilityPreprocessor::PrVs prvs;
|
---|
| 1556 | mViewCellsManager->GetPrVS(viewPoint, prvs, 5);
|
---|
| 1557 | viewCell = prvs.mViewCell;
|
---|
| 1558 | }
|
---|
| 1559 | else
|
---|
| 1560 | {
|
---|
[1597] | 1561 | viewCell = newElementary;
|
---|
[938] | 1562 | }
|
---|
[1593] | 1563 |
|
---|
| 1564 | ///////////////
|
---|
[938] | 1565 | //-- load new pvs
|
---|
[903] | 1566 |
|
---|
[1593] | 1567 | ApplyViewCellPvs(viewCell, true);
|
---|
| 1568 |
|
---|
| 1569 | if (viewCell)
|
---|
| 1570 | {
|
---|
[2097] | 1571 | // store current view cell
|
---|
[1593] | 1572 | mCurrentViewCell->SetPvs(viewCell->GetPvs());
|
---|
| 1573 | mCurrentViewCell->SetMesh(viewCell->GetMesh());
|
---|
| 1574 | mCurrentViewCell->SetId(viewCell->GetId());
|
---|
[903] | 1575 |
|
---|
[1593] | 1576 | // delete merge tree of filtered view cell
|
---|
| 1577 | if (mUseVisibilityFilter)
|
---|
| 1578 | mViewCellsManager->DeleteLocalMergeTree(viewCell);
|
---|
| 1579 | }
|
---|
[903] | 1580 | }
|
---|
[1593] | 1581 | //-------------------------------------------------------------------------
|
---|
| 1582 | void OcclusionCullingSceneManager::CreateViewCellsGeometry()
|
---|
| 1583 | {
|
---|
[1616] | 1584 | //LogManager::getSingleton().logMessage("creating view cells geometry");
|
---|
[1622] | 1585 | if (mViewCellsGeometryLoaded) return;
|
---|
[1593] | 1586 |
|
---|
[2067] | 1587 | GtpVisibilityPreprocessor::ViewCellContainer viewCells =
|
---|
| 1588 | mViewCellsManager->GetViewCells();
|
---|
[1593] | 1589 |
|
---|
| 1590 | GtpVisibilityPreprocessor::ViewCellContainer::const_iterator it, it_end = viewCells.end();
|
---|
| 1591 | for (it = viewCells.begin(); it != it_end; ++ it)
|
---|
| 1592 | {
|
---|
| 1593 | GtpVisibilityPreprocessor::ViewCell *viewCell = *it;
|
---|
| 1594 |
|
---|
[2067] | 1595 | ManualObject *manual =
|
---|
| 1596 | OgreTypeConverter::ConvertToOgre(viewCell->GetMesh(), this);
|
---|
[1616] | 1597 |
|
---|
| 1598 | if (manual)
|
---|
| 1599 | {
|
---|
| 1600 | mViewCellsGeometry[viewCell->GetId()] = manual;
|
---|
[1593] | 1601 |
|
---|
[1616] | 1602 | // attach to scene node
|
---|
| 1603 | getRootSceneNode()->createChildSceneNode()->attachObject(manual);
|
---|
| 1604 | manual->setQueryFlags(0); // returned by no query
|
---|
[1602] | 1605 |
|
---|
[1616] | 1606 | // initialy set to invisible
|
---|
| 1607 | manual->setVisible(false);
|
---|
| 1608 | }
|
---|
[1593] | 1609 | }
|
---|
[1616] | 1610 |
|
---|
| 1611 | mViewCellsGeometryLoaded = true;
|
---|
[1593] | 1612 | }
|
---|
[1602] | 1613 | //-------------------------------------------------------------------------
|
---|
| 1614 | void OcclusionCullingSceneManager::VisualizeViewCells(const bool visualize)
|
---|
| 1615 | {
|
---|
[1616] | 1616 | MovableMap::const_iterator mit, mit_end = mViewCellsGeometry.end();
|
---|
[1602] | 1617 |
|
---|
| 1618 | for (mit = mViewCellsGeometry.begin(); mit != mit_end; ++ mit)
|
---|
| 1619 | {
|
---|
[1616] | 1620 | if ((*mit).second)
|
---|
| 1621 | (*mit).second->setVisible(visualize);
|
---|
[1602] | 1622 | }
|
---|
| 1623 | }
|
---|
[955] | 1624 | #if 0
|
---|
[951] | 1625 | //-------------------------------------------------------------------------
|
---|
| 1626 | void OcclusionCullingSceneManager::TestVisible(SceneNode *node)
|
---|
| 1627 | {
|
---|
| 1628 | // first test for scene node, then for octant (part of the hierarchy)
|
---|
| 1629 | if (!node->mVisibleChildren)
|
---|
[1602] | 1630 | {
|
---|
[951] | 1631 | node->setVisible(false);
|
---|
[1602] | 1632 | }
|
---|
[903] | 1633 |
|
---|
[951] | 1634 | node->getOctant()->mVisibleChildren --;
|
---|
| 1635 | }
|
---|
| 1636 | //-------------------------------------------------------------------------
|
---|
| 1637 | void OcclusionCullingSceneManager::TestVisible(Octree *octant)
|
---|
| 1638 | {
|
---|
| 1639 | // first test for scene node, then for octant (part of the hierarchy)
|
---|
| 1640 | if (!octant->mVisibleChildren)
|
---|
[1593] | 1641 | {
|
---|
[951] | 1642 | octant->setVisible(false);
|
---|
[1593] | 1643 | }
|
---|
[951] | 1644 | }
|
---|
[903] | 1645 |
|
---|
[951] | 1646 | //-------------------------------------------------------------------------
|
---|
| 1647 | void OcclusionCullingSceneManager::UpdateVisibility(Entity *ent)
|
---|
| 1648 | {
|
---|
| 1649 | if (!ent->isVisible())
|
---|
| 1650 | {
|
---|
| 1651 | bool visible = TestVisible(ent->getParentNode());
|
---|
| 1652 |
|
---|
| 1653 | if (!visible)
|
---|
| 1654 | visible = TestVisible(octant->getParentNode());
|
---|
[903] | 1655 |
|
---|
[951] | 1656 | if (!visible)
|
---|
| 1657 | mHierarchyInterface->pullupVisibility();
|
---|
| 1658 | }
|
---|
| 1659 | }
|
---|
[955] | 1660 | #endif
|
---|
[1816] | 1661 | // splits strings containing multiple file names
|
---|
[1823] | 1662 | static int SplitFilenames(const std::string str,
|
---|
| 1663 | std::vector<std::string> &filenames)
|
---|
[1816] | 1664 | {
|
---|
| 1665 | int pos = 0;
|
---|
| 1666 |
|
---|
| 1667 | while(1)
|
---|
| 1668 | {
|
---|
| 1669 | int npos = (int)str.find(';', pos);
|
---|
| 1670 |
|
---|
| 1671 | if (npos < 0 || npos - pos < 1)
|
---|
| 1672 | break;
|
---|
| 1673 | filenames.push_back(std::string(str, pos, npos - pos));
|
---|
| 1674 | pos = npos + 1;
|
---|
| 1675 | }
|
---|
| 1676 |
|
---|
| 1677 | filenames.push_back(std::string(str, pos, str.size() - pos));
|
---|
| 1678 | return (int)filenames.size();
|
---|
| 1679 | }
|
---|
[903] | 1680 | //-----------------------------------------------------------------------
|
---|
[1816] | 1681 | bool OcclusionCullingSceneManager::LoadScene(const String &filename)
|
---|
| 1682 | {
|
---|
| 1683 | using namespace std;
|
---|
| 1684 | // use leaf nodes of the original spatial hierarchy as occludees
|
---|
| 1685 | vector<string> filenames;
|
---|
| 1686 | const int files = SplitFilenames(filename, filenames);
|
---|
| 1687 |
|
---|
| 1688 | std::stringstream d;
|
---|
| 1689 | d << "number of input files: " << files << "\n";
|
---|
| 1690 | LogManager::getSingleton().logMessage(d.str());
|
---|
| 1691 |
|
---|
| 1692 | bool result = false;
|
---|
| 1693 | vector<string>::const_iterator fit, fit_end = filenames.end();
|
---|
| 1694 | int i = 0;
|
---|
| 1695 |
|
---|
| 1696 | if (filename == "terrain")
|
---|
| 1697 | {
|
---|
[1823] | 1698 | LogManager::getSingleton().logMessage("loading terrain");
|
---|
| 1699 |
|
---|
[1816] | 1700 | // terrain hack
|
---|
[1823] | 1701 | return false;
|
---|
[1816] | 1702 | }
|
---|
[2097] | 1703 | /*
|
---|
[1816] | 1704 | for (fit = filenames.begin(); fit != fit_end; ++ fit, ++ i)
|
---|
| 1705 | {
|
---|
| 1706 | const string fn = *fit;
|
---|
| 1707 |
|
---|
| 1708 | if (strstr(fn.c_str(), ".iv") || strstr(fn.c_str(), ".wrl"))
|
---|
| 1709 | {
|
---|
| 1710 | // load iv files
|
---|
| 1711 | if (!LoadSceneIV(fn, getRootSceneNode(), i))
|
---|
| 1712 | {
|
---|
| 1713 | // terrain hack
|
---|
| 1714 | LogManager::getSingleton().logMessage("error loading file");
|
---|
| 1715 | }
|
---|
| 1716 | }
|
---|
| 1717 |
|
---|
| 1718 | // at least one piece of geometry loaded
|
---|
| 1719 | result = true;
|
---|
| 1720 | }
|
---|
[2097] | 1721 | */ result=true;
|
---|
[1816] | 1722 | return result;
|
---|
| 1723 | }
|
---|
| 1724 | //-----------------------------------------------------------------------
|
---|
| 1725 | bool OcclusionCullingSceneManager::LoadSceneIV(const String &filename,
|
---|
| 1726 | SceneNode *root,
|
---|
| 1727 | const int index)
|
---|
| 1728 | {
|
---|
| 1729 | IVReader ivReader;
|
---|
| 1730 |
|
---|
| 1731 | Timer *timer = PlatformManager::getSingleton().createTimer();
|
---|
| 1732 | timer->reset();
|
---|
| 1733 |
|
---|
| 1734 | if (1)
|
---|
| 1735 | {
|
---|
| 1736 | std::string logFilename = "IVLog" + Ogre::StringConverter().toString(index) + ".log";
|
---|
| 1737 |
|
---|
| 1738 | Log *log = LogManager::getSingleton().createLog(logFilename);
|
---|
| 1739 | ivReader.setLog(log);
|
---|
| 1740 | }
|
---|
| 1741 |
|
---|
| 1742 | //viennaNode->translate(Vector3(-300, -300, 0));
|
---|
| 1743 |
|
---|
| 1744 | if (ivReader.loadFile(filename.c_str()))
|
---|
| 1745 | {
|
---|
| 1746 | SceneNode *node = root->createChildSceneNode("IVSceneNode" + index);
|
---|
| 1747 |
|
---|
| 1748 | ivReader.buildTree(this, node);
|
---|
| 1749 |
|
---|
| 1750 | ivReader.collapse();
|
---|
| 1751 |
|
---|
| 1752 | std::stringstream d;
|
---|
| 1753 | d << "loaded " << filename << " in " << timer->getMilliseconds() * 1e-3 << " secs";
|
---|
| 1754 | LogManager::getSingleton().logMessage(d.str());
|
---|
| 1755 |
|
---|
| 1756 | PlatformManager::getSingleton().destroyTimer(timer);
|
---|
| 1757 |
|
---|
| 1758 | //-- bake into static geometry
|
---|
| 1759 | /*if (USE_STATIC_GEOMETRY)
|
---|
| 1760 | {
|
---|
| 1761 | BakeSceneIntoStaticGeometry("staticVienna", "Vienna");
|
---|
| 1762 | }*/
|
---|
| 1763 |
|
---|
| 1764 | return true;
|
---|
| 1765 | }
|
---|
| 1766 |
|
---|
| 1767 | return false;
|
---|
| 1768 | }
|
---|
| 1769 | //-----------------------------------------------------------------------
|
---|
[903] | 1770 | const String OcclusionCullingSceneManagerFactory::FACTORY_TYPE_NAME = "OcclusionCullingSceneManager";
|
---|
| 1771 | //-----------------------------------------------------------------------
|
---|
| 1772 | void OcclusionCullingSceneManagerFactory::initMetaData(void) const
|
---|
| 1773 | {
|
---|
| 1774 | mMetaData.typeName = FACTORY_TYPE_NAME;
|
---|
| 1775 | mMetaData.description = "Scene manager organising the scene on the basis of an octree with advanced occlusion culling (TM).";
|
---|
| 1776 | mMetaData.sceneTypeMask = 0xFFFF; // support all types
|
---|
| 1777 | mMetaData.worldGeometrySupported = false;
|
---|
| 1778 | }
|
---|
| 1779 | //-----------------------------------------------------------------------
|
---|
[925] | 1780 | SceneManager *OcclusionCullingSceneManagerFactory::createInstance(
|
---|
| 1781 | const String& instanceName)
|
---|
[903] | 1782 | {
|
---|
[2097] | 1783 | OcclusionCullingSceneManager* tsm =
|
---|
| 1784 | new OcclusionCullingSceneManager(instanceName, visManager);
|
---|
[925] | 1785 |
|
---|
| 1786 | // Create & register default sources (one per manager)
|
---|
| 1787 | HeightmapTerrainPageSource* ps = new HeightmapTerrainPageSource();
|
---|
| 1788 | mTerrainPageSources.push_back(ps);
|
---|
| 1789 | tsm->registerPageSource("Heightmap", ps);
|
---|
| 1790 |
|
---|
| 1791 | return tsm;
|
---|
[903] | 1792 | }
|
---|
| 1793 | //-----------------------------------------------------------------------
|
---|
| 1794 | void OcclusionCullingSceneManagerFactory::destroyInstance(SceneManager* instance)
|
---|
| 1795 | {
|
---|
| 1796 | delete instance;
|
---|
| 1797 | }
|
---|
| 1798 |
|
---|
[675] | 1799 | } // namespace Ogre
|
---|