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