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