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