source: trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp @ 149

Revision 149, 23.0 KB checked in by mattausch, 19 years ago (diff)

queries using item buffer

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