forked from teamnwah/openmw-tes3coop
Slightly more efficient applying of light state
This commit is contained in:
parent
3859c58a8a
commit
3e854a84a2
1 changed files with 17 additions and 6 deletions
|
@ -45,6 +45,8 @@ namespace SceneUtil
|
||||||
|
|
||||||
virtual void apply(osg::State& state) const
|
virtual void apply(osg::State& state) const
|
||||||
{
|
{
|
||||||
|
if (mLights.empty())
|
||||||
|
return;
|
||||||
osg::Matrix modelViewMatrix = state.getModelViewMatrix();
|
osg::Matrix modelViewMatrix = state.getModelViewMatrix();
|
||||||
|
|
||||||
state.applyModelViewMatrix(state.getInitialViewMatrix());
|
state.applyModelViewMatrix(state.getInitialViewMatrix());
|
||||||
|
@ -193,16 +195,25 @@ namespace SceneUtil
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet;
|
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet;
|
||||||
|
std::vector<osg::ref_ptr<osg::Light> > lights;
|
||||||
for (unsigned int i=0; i<lightList.size();++i)
|
for (unsigned int i=0; i<lightList.size();++i)
|
||||||
{
|
{
|
||||||
std::vector<osg::ref_ptr<osg::Light> > lights;
|
|
||||||
lights.push_back(lightList[i]->mLightSource->getLight(frameNum));
|
lights.push_back(lightList[i]->mLightSource->getLight(frameNum));
|
||||||
osg::ref_ptr<LightStateAttribute> attr = new LightStateAttribute(mStartLight+i, lights);
|
}
|
||||||
// don't use setAttributeAndModes, that does not support light indices!
|
|
||||||
stateset->setAttribute(attr, osg::StateAttribute::ON);
|
|
||||||
stateset->setAssociatedModes(attr, osg::StateAttribute::ON);
|
|
||||||
|
|
||||||
|
// 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
|
||||||
|
osg::ref_ptr<LightStateAttribute> attr = new LightStateAttribute(mStartLight, lights);
|
||||||
|
// don't use setAttributeAndModes, that does not support light indices!
|
||||||
|
stateset->setAttribute(attr, osg::StateAttribute::ON);
|
||||||
|
stateset->setAssociatedModes(attr, osg::StateAttribute::ON);
|
||||||
|
|
||||||
|
// need to push some dummy attributes to ensure proper state tracking
|
||||||
|
// lights need to reset to their default when the StateSet is popped
|
||||||
|
for (unsigned int i=1; i<lightList.size(); ++i)
|
||||||
|
{
|
||||||
|
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.insert(std::make_pair(hash, stateset));
|
||||||
|
|
Loading…
Reference in a new issue