source: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp @ 2168

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