source: trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp @ 91

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