source: trunk/VUT/Ogre/src/OgreVisibilitySceneManager.cpp @ 155

Revision 155, 4.8 KB checked in by mattausch, 19 years ago (diff)

added node traversal interface

Line 
1#include <OgreMath.h>
2#include <OgreIteratorWrappers.h>
3#include <OgreRenderSystem.h>
4#include <OgreCamera.h>
5#include "OgreVisibilitySceneManager.h"
6#include "OgreSceneNodeHierarchyInterface.h"
7#include "OgreVisibilityOptionsManager.h"
8
9
10namespace Ogre {
11
12//-----------------------------------------------------------------------
13VisibilitySceneManager::VisibilitySceneManager(GtpVisibility::VisibilityManager *visManager)
14:mVisibilityManager(visManager), mUseDepthPass(false), mShowVisualization(false)
15{
16        mHierarchyInterface =
17                new SceneNodeHierarchyInterface(this, mDestRenderSystem);
18}
19//-----------------------------------------------------------------------
20VisibilitySceneManager::~VisibilitySceneManager()
21{
22        delete mHierarchyInterface;
23}
24//-----------------------------------------------------------------------
25void VisibilitySceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters)
26{
27        mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters);
28        // does nothing if hierarchical culling is used =>
29        // we interleave identification and rendering of objects
30        // in _renderVisibibleObjects
31        if (!mUseDepthPass)
32        {
33                SceneManager::_findVisibleObjects(cam, onlyShadowCasters);
34                return;
35        }
36}
37//-----------------------------------------------------------------------
38void VisibilitySceneManager::_renderVisibleObjects()
39{
40        if (!mShowVisualization)
41        {
42                mHierarchyInterface->SetHierarchyRoot(mSceneRoot);
43                mHierarchyInterface->InitTraversal(mCameraInProgress);
44
45                // reset culling manager stats
46                mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes);
47        }
48
49        // standard terrain scenemanager rendering without hierarchical culling
50        if (!mUseDepthPass || mShowVisualization)
51        {       
52                SceneManager::_renderVisibleObjects();
53       
54                return;
55        }
56
57        //-- hierarchical culling
58        // the objects of different layers (e.g., background, scene,
59        // overlay) must be identified and rendered one after another
60
61        //-- render background
62        clearSpecialCaseRenderQueues();
63        addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND);
64        addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY);
65
66        setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);
67        SceneManager::_renderVisibleObjects();
68
69#ifdef GTP_VISIBILITY_MODIFIED_OGRE
70        _deleteRenderedQueueGroups();
71#endif
72
73        //-- render visible objects (i.e., all but overlay)
74        clearSpecialCaseRenderQueues();
75        addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
76        setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
77
78
79        /**
80        * the hierarchical culling algorithm
81        **/
82        mVisibilityManager->ApplyVisibilityCulling();
83
84
85#ifdef GTP_VISIBILITY_MODIFIED_OGRE
86        _deleteRenderedQueueGroups();
87#endif
88
89        //-- render overlay
90        clearSpecialCaseRenderQueues();
91        SceneManager::_renderVisibleObjects();
92
93        //WriteLog(); // write out stats
94}
95//-----------------------------------------------------------------------
96void VisibilitySceneManager::_updateSceneGraph(Camera* cam)
97{
98        mVisibilityManager->GetCullingManager()->SetHierarchyInterface(mHierarchyInterface);
99        mHierarchyInterface->SetRenderSystem(mDestRenderSystem);
100       
101        SceneManager::_updateSceneGraph(cam);
102}
103//-----------------------------------------------------------------------
104bool VisibilitySceneManager::setOption(const String & key, const void * val)
105{
106        return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
107                setOption(key, val) || SceneManager::setOption(key, val);
108}
109//-----------------------------------------------------------------------
110bool VisibilitySceneManager::getOption(const String & key, void *val)
111{
112        if (key == "NumHierarchyNodes")
113        {
114                * static_cast<unsigned int *>(val) = (unsigned int)mSceneNodes.size();
115                return true;
116        }
117       
118        return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
119                getOption(key, val) && SceneManager::getOption(key, val);
120}
121//-----------------------------------------------------------------------
122bool VisibilitySceneManager::getOptionValues(const String & key, StringVector  &refValueList)
123{
124        return SceneManager::getOptionValues(key, refValueList);
125}
126//-----------------------------------------------------------------------
127bool VisibilitySceneManager::getOptionKeys(StringVector & refKeys)
128{
129        return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
130                getOptionKeys(refKeys) || SceneManager::getOptionKeys(refKeys);
131}
132//-----------------------------------------------------------------------
133void VisibilitySceneManager::setVisibilityManager(GtpVisibility::VisibilityManager *visManager)
134{
135        mVisibilityManager = visManager;
136}
137//-----------------------------------------------------------------------
138GtpVisibility::VisibilityManager *VisibilitySceneManager::getVisibilityManager()
139{
140        return mVisibilityManager;
141}
142
143} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.