diff --git a/Components/Terrain/src/OgreTerrainQuadTreeNode.cpp b/Components/Terrain/src/OgreTerrainQuadTreeNode.cpp index 1093d6bc65d..e6a9707e411 100644 --- a/Components/Terrain/src/OgreTerrainQuadTreeNode.cpp +++ b/Components/Terrain/src/OgreTerrainQuadTreeNode.cpp @@ -1228,9 +1228,21 @@ namespace Ogre MaterialPtr material = getMaterial(); const LodStrategy *materialStrategy = material->getLodStrategy(); Real lodValue = materialStrategy->getValue(this, cam); + + // Construct event object + MaterialLodChangedEvent matLodEvt; + matLodEvt.renderable = this; + matLodEvt.camera = cam; + matLodEvt.lodValue = lodValue; + matLodEvt.previousLodIndex = mMaterialLodIndex; + // Get the index at this biased depth mMaterialLodIndex = material->getLodIndex(lodValue); + + matLodEvt.newLodIndex = mMaterialLodIndex; + // Notify LOD event listeners + cam->getSceneManager()->_notifyMaterialLodChanged(matLodEvt); // For each LOD, the distance at which the LOD will transition *downwards* // is given by diff --git a/OgreMain/include/OgreLodListener.h b/OgreMain/include/OgreLodListener.h index 41c7568d0a7..90002462963 100644 --- a/OgreMain/include/OgreLodListener.h +++ b/OgreMain/include/OgreLodListener.h @@ -69,14 +69,14 @@ namespace Ogre { ushort newLodIndex; }; - /// Struct containing information about a material LOD change event for entities. - struct EntityMaterialLodChangedEvent + /// Struct containing information about a material LOD change event for renderables. + struct MaterialLodChangedEvent { - /// The sub-entity whose material's level of detail has changed. - SubEntity *subEntity; + /// The renderable whose material's level of detail has changed. + Renderable *renderable; /// The camera with respect to which the level of detail has changed. - Camera *camera; + const Camera *camera; /// LOD value as determined by LOD strategy. Real lodValue; @@ -88,6 +88,8 @@ namespace Ogre { ushort newLodIndex; }; + typedef MaterialLodChangedEvent EntityMaterialLodChangedEvent; + /** A interface class defining a listener which can be used to receive notifications of LOD events. @@ -172,7 +174,7 @@ namespace Ogre { { (void)evt; } /** - Called before an entity's material LOD has changed. + Called before an material LOD has changed. Do not change the Ogre state from this method, instead return true and perform changes in @@ -187,16 +189,16 @@ namespace Ogre { postqueueMaterialLodChanged called after rendering is complete. */ - virtual bool prequeueEntityMaterialLodChanged(EntityMaterialLodChangedEvent& evt) + virtual bool prequeueEntityMaterialLodChanged(MaterialLodChangedEvent& evt) { (void)evt; return false; } /** - Called after an entity's material LOD has changed. + Called after an material LOD has changed. May be called even if not requested from prequeueEntityMaterialLodChanged as only one event queue is maintained per SceneManger instance. */ - virtual void postqueueEntityMaterialLodChanged(const EntityMaterialLodChangedEvent& evt) + virtual void postqueueEntityMaterialLodChanged(const MaterialLodChangedEvent& evt) { (void)evt; } }; diff --git a/OgreMain/include/OgreSceneManager.h b/OgreMain/include/OgreSceneManager.h index 346ada663d5..c1a148b62a0 100644 --- a/OgreMain/include/OgreSceneManager.h +++ b/OgreMain/include/OgreSceneManager.h @@ -91,7 +91,7 @@ namespace Ogre { class LodListener; struct MovableObjectLodChangedEvent; struct EntityMeshLodChangedEvent; - struct EntityMaterialLodChangedEvent; + struct MaterialLodChangedEvent; class ShadowCasterSceneQueryListener; /** Structure collecting together information about the visible objects @@ -1017,9 +1017,9 @@ namespace Ogre { typedef std::vector EntityMeshLodChangedEventList; EntityMeshLodChangedEventList mEntityMeshLodChangedEvents; - /// List of entity material LOD changed events - typedef std::vector EntityMaterialLodChangedEventList; - EntityMaterialLodChangedEventList mEntityMaterialLodChangedEvents; + /// List of material LOD changed events + typedef std::vector MaterialLodChangedEventList; + MaterialLodChangedEventList mMaterialLodChangedEvents; public: //A render context, used to store internal data for pausing/resuming rendering @@ -3293,8 +3293,8 @@ namespace Ogre { /** Notify that an entity mesh LOD change event has occurred. */ void _notifyEntityMeshLodChanged(EntityMeshLodChangedEvent& evt); - /** Notify that an entity material LOD change event has occurred. */ - void _notifyEntityMaterialLodChanged(EntityMaterialLodChangedEvent& evt); + /** Notify that an material LOD change event has occurred. */ + void _notifyMaterialLodChanged(MaterialLodChangedEvent& evt); /** Handle LOD events. */ void _handleLodEvents(); diff --git a/OgreMain/src/OgreEntity.cpp b/OgreMain/src/OgreEntity.cpp index 8324db88443..35f1aed3958 100644 --- a/OgreMain/src/OgreEntity.cpp +++ b/OgreMain/src/OgreEntity.cpp @@ -396,15 +396,15 @@ namespace Ogre { idx = Math::Clamp(idx, mMaxMaterialLodIndex, mMinMaterialLodIndex); // Construct event object - EntityMaterialLodChangedEvent subEntEvt; - subEntEvt.subEntity = s; + MaterialLodChangedEvent subEntEvt; + subEntEvt.renderable = s; subEntEvt.camera = cam; subEntEvt.lodValue = biasedMaterialLodValue; subEntEvt.previousLodIndex = s->mMaterialLodIndex; subEntEvt.newLodIndex = idx; // Notify LOD event listeners - cam->getSceneManager()->_notifyEntityMaterialLodChanged(subEntEvt); + cam->getSceneManager()->_notifyMaterialLodChanged(subEntEvt); // Change LOD index s->mMaterialLodIndex = subEntEvt.newLodIndex; diff --git a/OgreMain/src/OgreInstanceBatch.cpp b/OgreMain/src/OgreInstanceBatch.cpp index 365f4a48c6d..79dbf100d30 100644 --- a/OgreMain/src/OgreInstanceBatch.cpp +++ b/OgreMain/src/OgreInstanceBatch.cpp @@ -454,17 +454,16 @@ namespace Ogre //Get the index at this depth unsigned short idx = mMaterial->getLodIndex( lodValue ); - //TODO: Replace subEntity for MovableObject // Construct event object - /*EntityMaterialLodChangedEvent subEntEvt; - subEntEvt.subEntity = this; + MaterialLodChangedEvent subEntEvt; + subEntEvt.renderable = this; subEntEvt.camera = cam; subEntEvt.lodValue = lodValue; - subEntEvt.previousLodIndex = m_materialLodIndex; + subEntEvt.previousLodIndex = mMaterialLodIndex; subEntEvt.newLodIndex = idx; //Notify LOD event listeners - cam->getSceneManager()->_notifyEntityMaterialLodChanged(subEntEvt);*/ + cam->getSceneManager()->_notifyMaterialLodChanged(subEntEvt); // Change LOD index mMaterialLodIndex = idx; diff --git a/OgreMain/src/OgreSceneManager.cpp b/OgreMain/src/OgreSceneManager.cpp index 20d9cd8d68a..5112ce9b8c2 100644 --- a/OgreMain/src/OgreSceneManager.cpp +++ b/OgreMain/src/OgreSceneManager.cpp @@ -3493,7 +3493,7 @@ void SceneManager::_notifyEntityMeshLodChanged(EntityMeshLodChangedEvent& evt) mEntityMeshLodChangedEvents.push_back(evt); } //--------------------------------------------------------------------- -void SceneManager::_notifyEntityMaterialLodChanged(EntityMaterialLodChangedEvent& evt) +void SceneManager::_notifyMaterialLodChanged(EntityMaterialLodChangedEvent& evt) { // Notify listeners and determine if event needs to be queued bool queueEvent = false; @@ -3505,7 +3505,7 @@ void SceneManager::_notifyEntityMaterialLodChanged(EntityMaterialLodChangedEvent // Push event onto queue if requested if (queueEvent) - mEntityMaterialLodChangedEvents.push_back(evt); + mMaterialLodChangedEvents.push_back(evt); } //--------------------------------------------------------------------- void SceneManager::_handleLodEvents() @@ -3519,14 +3519,14 @@ void SceneManager::_handleLodEvents() for (auto& e : mEntityMeshLodChangedEvents) l->postqueueEntityMeshLodChanged(e); - for (auto& e : mEntityMaterialLodChangedEvents) + for (auto& e : mMaterialLodChangedEvents) l->postqueueEntityMaterialLodChanged(e); } // Clear event queues mMovableObjectLodChangedEvents.clear(); mEntityMeshLodChangedEvents.clear(); - mEntityMaterialLodChangedEvents.clear(); + mMaterialLodChangedEvents.clear(); } //--------------------------------------------------------------------- void SceneManager::useLights(const LightList* lights, ushort limit)