mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-21 18:40:01 +00:00
Merge pull request #2298 from akortunov/optimize
Do not allocate eight dummy LightStateAttribute's for every stateset
This commit is contained in:
commit
1444ef6f43
@ -165,6 +165,8 @@ namespace SceneUtil
|
|||||||
, mLightingMask(~0u)
|
, mLightingMask(~0u)
|
||||||
{
|
{
|
||||||
setUpdateCallback(new LightManagerUpdateCallback);
|
setUpdateCallback(new LightManagerUpdateCallback);
|
||||||
|
for (unsigned int i=0; i<8; ++i)
|
||||||
|
mDummies.push_back(new LightStateAttribute(i, std::vector<osg::ref_ptr<osg::Light> >()));
|
||||||
}
|
}
|
||||||
|
|
||||||
LightManager::LightManager(const LightManager ©, const osg::CopyOp ©op)
|
LightManager::LightManager(const LightManager ©, const osg::CopyOp ©op)
|
||||||
@ -219,7 +221,6 @@ namespace SceneUtil
|
|||||||
|
|
||||||
osg::ref_ptr<osg::StateSet> LightManager::getLightListStateSet(const LightList &lightList, unsigned int frameNum)
|
osg::ref_ptr<osg::StateSet> LightManager::getLightListStateSet(const LightList &lightList, unsigned int frameNum)
|
||||||
{
|
{
|
||||||
|
|
||||||
// possible optimization: return a StateSet containing all requested lights plus some extra lights (if a suitable one exists)
|
// possible optimization: return a StateSet containing all requested lights plus some extra lights (if a suitable one exists)
|
||||||
size_t hash = 0;
|
size_t hash = 0;
|
||||||
for (unsigned int i=0; i<lightList.size();++i)
|
for (unsigned int i=0; i<lightList.size();++i)
|
||||||
@ -236,27 +237,22 @@ namespace SceneUtil
|
|||||||
std::vector<osg::ref_ptr<osg::Light> > lights;
|
std::vector<osg::ref_ptr<osg::Light> > lights;
|
||||||
lights.reserve(lightList.size());
|
lights.reserve(lightList.size());
|
||||||
for (unsigned int i=0; i<lightList.size();++i)
|
for (unsigned int i=0; i<lightList.size();++i)
|
||||||
{
|
|
||||||
lights.push_back(lightList[i]->mLightSource->getLight(frameNum));
|
lights.push_back(lightList[i]->mLightSource->getLight(frameNum));
|
||||||
}
|
|
||||||
|
|
||||||
// the first light state attribute handles the actual state setting for all lights
|
// the first light state attribute handles the actual state setting for all lights
|
||||||
// it's best to batch these up so that we don't need to touch the modelView matrix more than necessary
|
// it's best to batch these up so that we don't need to touch the modelView matrix more than necessary
|
||||||
osg::ref_ptr<LightStateAttribute> attr = new LightStateAttribute(mStartLight, lights);
|
|
||||||
// don't use setAttributeAndModes, that does not support light indices!
|
// don't use setAttributeAndModes, that does not support light indices!
|
||||||
stateset->setAttribute(attr, osg::StateAttribute::ON);
|
stateset->setAttribute(new LightStateAttribute(mStartLight, std::move(lights)), osg::StateAttribute::ON);
|
||||||
|
|
||||||
for (unsigned int i=0; i<lightList.size(); ++i)
|
for (unsigned int i=0; i<lightList.size(); ++i)
|
||||||
stateset->setMode(GL_LIGHT0 + mStartLight + i, osg::StateAttribute::ON);
|
stateset->setMode(GL_LIGHT0 + mStartLight + i, osg::StateAttribute::ON);
|
||||||
|
|
||||||
// need to push some dummy attributes to ensure proper state tracking
|
// need to push some dummy attributes to ensure proper state tracking
|
||||||
// lights need to reset to their default when the StateSet is popped
|
// lights need to reset to their default when the StateSet is popped
|
||||||
for (unsigned int i=1; i<lightList.size(); ++i)
|
for (unsigned int i=1; i<lightList.size(); ++i)
|
||||||
{
|
stateset->setAttribute(mDummies[i+mStartLight].get(), osg::StateAttribute::ON);
|
||||||
osg::ref_ptr<LightStateAttribute> dummy = new LightStateAttribute(mStartLight+i, std::vector<osg::ref_ptr<osg::Light> >());
|
|
||||||
stateset->setAttribute(dummy, osg::StateAttribute::ON);
|
|
||||||
}
|
|
||||||
|
|
||||||
stateSetCache.insert(std::make_pair(hash, stateset));
|
stateSetCache.emplace(hash, stateset);
|
||||||
return stateset;
|
return stateset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,6 +140,8 @@ namespace SceneUtil
|
|||||||
typedef std::map<size_t, osg::ref_ptr<osg::StateSet> > LightStateSetMap;
|
typedef std::map<size_t, osg::ref_ptr<osg::StateSet> > LightStateSetMap;
|
||||||
LightStateSetMap mStateSetCache[2];
|
LightStateSetMap mStateSetCache[2];
|
||||||
|
|
||||||
|
std::vector<osg::ref_ptr<osg::StateAttribute>> mDummies;
|
||||||
|
|
||||||
int mStartLight;
|
int mStartLight;
|
||||||
|
|
||||||
unsigned int mLightingMask;
|
unsigned int mLightingMask;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user