[59] | 1 | #include "OgreVisibilityOctreeSceneManager.h"
|
---|
[74] | 2 | #include "OgreVisibilityOptionsManager.h"
|
---|
[59] | 3 | #include <OgreMath.h>
|
---|
| 4 | #include <OgreIteratorWrappers.h>
|
---|
| 5 | #include <OgreRenderSystem.h>
|
---|
| 6 | #include <OgreCamera.h>
|
---|
| 7 |
|
---|
| 8 | #include <windows.h>
|
---|
| 9 |
|
---|
| 10 | namespace Ogre {
|
---|
| 11 |
|
---|
| 12 | //-----------------------------------------------------------------------
|
---|
| 13 | VisibilityOctreeSceneManager::VisibilityOctreeSceneManager(
|
---|
[87] | 14 | GtpVisibility::VisibilityManager *visManager)
|
---|
| 15 | : mVisibilityManager(visManager), mUseCulling(true)
|
---|
[59] | 16 | {
|
---|
| 17 | mHierarchyInterface =
|
---|
| 18 | new OctreeHierarchyInterface(this, mDestRenderSystem);
|
---|
[91] | 19 | //visManager->SetCullingManager(GtpVisibility::VisibilityEnvironment::STOP_AND_WAIT_CULLING);
|
---|
| 20 |
|
---|
[59] | 21 | //mDisplayNodes = true;
|
---|
[86] | 22 | //mShowBoundingBoxes = true;
|
---|
| 23 | //mShowBoxes = true;
|
---|
[87] | 24 |
|
---|
[86] | 25 | mMaxDepth = 20;
|
---|
[59] | 26 | }
|
---|
| 27 | //-----------------------------------------------------------------------
|
---|
| 28 | VisibilityOctreeSceneManager::~VisibilityOctreeSceneManager()
|
---|
| 29 | {
|
---|
| 30 | delete mHierarchyInterface;
|
---|
| 31 | }
|
---|
| 32 | //-----------------------------------------------------------------------
|
---|
| 33 | void VisibilityOctreeSceneManager::_renderVisibleObjects()
|
---|
| 34 | {
|
---|
[87] | 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 |
|
---|
[59] | 48 | //-- render background
|
---|
| 49 | clearSpecialCaseRenderQueues();
|
---|
| 50 | addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND);
|
---|
| 51 | addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY);
|
---|
| 52 |
|
---|
| 53 | setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);
|
---|
[87] | 54 | SceneManager::_renderVisibleObjects();
|
---|
| 55 |
|
---|
[59] | 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 |
|
---|
[87] | 65 | //-- the hierarchical culling algorithm
|
---|
[59] | 66 | mVisibilityManager->ApplyVisibilityCulling();
|
---|
| 67 |
|
---|
| 68 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
| 69 | _deleteRenderedQueueGroups();
|
---|
| 70 | #endif
|
---|
| 71 |
|
---|
[87] | 72 | //-- render remaining objects, e.g., overlay
|
---|
[59] | 73 | clearSpecialCaseRenderQueues();
|
---|
| 74 | SceneManager::_renderVisibleObjects();
|
---|
| 75 | }
|
---|
| 76 | //-----------------------------------------------------------------------
|
---|
| 77 | void VisibilityOctreeSceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters)
|
---|
| 78 | {
|
---|
[87] | 79 | // empty if hierarchical culling is used =>
|
---|
| 80 | // we interleave identification and rendering of objects
|
---|
[59] | 81 | // in _renderVisibibleObjects
|
---|
[87] | 82 | if(!mUseCulling)
|
---|
| 83 | {
|
---|
| 84 | OctreeSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
|
---|
| 85 | }
|
---|
[59] | 86 | }
|
---|
| 87 | //-----------------------------------------------------------------------
|
---|
| 88 | void 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 | //-----------------------------------------------------------------------
|
---|
| 99 | bool VisibilityOctreeSceneManager::setOption(const String & key, const void * val)
|
---|
| 100 | {
|
---|
[87] | 101 | if (key == "UseCulling")
|
---|
| 102 | {
|
---|
| 103 | mUseCulling = (*static_cast<const bool *>(val));
|
---|
| 104 | return true;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[74] | 107 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
| 108 | setOption(key, val) || OctreeSceneManager::setOption(key, val);
|
---|
[59] | 109 | }
|
---|
| 110 | //-----------------------------------------------------------------------
|
---|
| 111 | bool VisibilityOctreeSceneManager::getOption(const String & key, void *val)
|
---|
| 112 | {
|
---|
[74] | 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);
|
---|
[59] | 121 | }
|
---|
| 122 | //-----------------------------------------------------------------------
|
---|
| 123 | bool VisibilityOctreeSceneManager::getOptionValues(const String & key, StringVector &refValueList)
|
---|
| 124 | {
|
---|
| 125 | return OctreeSceneManager::getOptionValues( key, refValueList );
|
---|
| 126 | }
|
---|
| 127 | //-----------------------------------------------------------------------
|
---|
| 128 | bool VisibilityOctreeSceneManager::getOptionKeys(StringVector & refKeys)
|
---|
| 129 | {
|
---|
[74] | 130 | return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
|
---|
| 131 | getOptionKeys ( refKeys ) || OctreeSceneManager::getOptionKeys(refKeys);
|
---|
[59] | 132 | }
|
---|
| 133 | //-----------------------------------------------------------------------
|
---|
| 134 | void VisibilityOctreeSceneManager::setVisibilityManager(GtpVisibility::VisibilityManager *visManager)
|
---|
| 135 | {
|
---|
| 136 | mVisibilityManager = visManager;
|
---|
| 137 | }
|
---|
| 138 | //-----------------------------------------------------------------------
|
---|
| 139 | GtpVisibility::VisibilityManager *VisibilityOctreeSceneManager::getVisibilityManager()
|
---|
| 140 | {
|
---|
| 141 | return mVisibilityManager;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | } // namespace Ogre |
---|