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

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