Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main: LodListener - make MaterialLodChangedEvent work with Renderable #3109

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Components/Terrain/src/OgreTerrainQuadTreeNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 11 additions & 9 deletions OgreMain/include/OgreLodListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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; }

};
Expand Down
12 changes: 6 additions & 6 deletions OgreMain/include/OgreSceneManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1017,9 +1017,9 @@ namespace Ogre {
typedef std::vector<EntityMeshLodChangedEvent> EntityMeshLodChangedEventList;
EntityMeshLodChangedEventList mEntityMeshLodChangedEvents;

/// List of entity material LOD changed events
typedef std::vector<EntityMaterialLodChangedEvent> EntityMaterialLodChangedEventList;
EntityMaterialLodChangedEventList mEntityMaterialLodChangedEvents;
/// List of material LOD changed events
typedef std::vector<MaterialLodChangedEvent> MaterialLodChangedEventList;
MaterialLodChangedEventList mMaterialLodChangedEvents;

public:
//A render context, used to store internal data for pausing/resuming rendering
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions OgreMain/src/OgreEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions OgreMain/src/OgreInstanceBatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions OgreMain/src/OgreSceneManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand All @@ -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)
Expand Down
Loading