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