forked from mirror/openmw-tes3mp
Keep the light list StateSet cache for more than one frame
This commit is contained in:
parent
07937c741a
commit
1d198a5592
2 changed files with 24 additions and 16 deletions
|
@ -145,7 +145,6 @@ namespace SceneUtil
|
||||||
{
|
{
|
||||||
mLightsInViewSpace = false;
|
mLightsInViewSpace = false;
|
||||||
mLights.clear();
|
mLights.clear();
|
||||||
mStateSetCache.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightManager::addLight(LightSource* lightSource, osg::Matrix worldMat)
|
void LightManager::addLight(LightSource* lightSource, osg::Matrix worldMat)
|
||||||
|
@ -180,7 +179,7 @@ namespace SceneUtil
|
||||||
// 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)
|
||||||
boost::hash_combine(hash, lightList[i]);
|
boost::hash_combine(hash, lightList[i]->getId());
|
||||||
|
|
||||||
LightStateSetMap::iterator found = mStateSetCache.find(hash);
|
LightStateSetMap::iterator found = mStateSetCache.find(hash);
|
||||||
if (found != mStateSetCache.end())
|
if (found != mStateSetCache.end())
|
||||||
|
@ -190,10 +189,7 @@ namespace SceneUtil
|
||||||
|
|
||||||
std::vector<osg::ref_ptr<osg::Light> > lights;
|
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)
|
||||||
{
|
lights.push_back(lightList[i]->getLight());
|
||||||
const LightSourceTransform& l = mLights[lightList[i]];
|
|
||||||
lights.push_back(l.mLightSource->getLight());
|
|
||||||
}
|
|
||||||
|
|
||||||
osg::ref_ptr<LightStateAttribute> attr = new LightStateAttribute(mStartLight, lights);
|
osg::ref_ptr<LightStateAttribute> attr = new LightStateAttribute(mStartLight, lights);
|
||||||
|
|
||||||
|
@ -223,11 +219,22 @@ namespace SceneUtil
|
||||||
return mStartLight;
|
return mStartLight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int sLightId = 0;
|
||||||
|
|
||||||
LightSource::LightSource()
|
LightSource::LightSource()
|
||||||
: mRadius(0.f)
|
: mRadius(0.f)
|
||||||
{
|
{
|
||||||
setNodeMask(Mask_Lit);
|
setNodeMask(Mask_Lit);
|
||||||
setUpdateCallback(new CollectLightCallback);
|
setUpdateCallback(new CollectLightCallback);
|
||||||
|
mId = sLightId++;
|
||||||
|
}
|
||||||
|
|
||||||
|
LightSource::LightSource(const LightSource ©, const osg::CopyOp ©op)
|
||||||
|
: osg::Node(copy, copyop)
|
||||||
|
, mLight(copy.mLight)
|
||||||
|
, mRadius(copy.mRadius)
|
||||||
|
{
|
||||||
|
mId = sLightId++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightListCallback::operator()(osg::Node *node, osg::NodeVisitor *nv)
|
void LightListCallback::operator()(osg::Node *node, osg::NodeVisitor *nv)
|
||||||
|
@ -282,12 +289,12 @@ namespace SceneUtil
|
||||||
osg::Matrixf mat = *cv->getModelViewMatrix();
|
osg::Matrixf mat = *cv->getModelViewMatrix();
|
||||||
transformBoundingSphere(mat, nodeBound);
|
transformBoundingSphere(mat, nodeBound);
|
||||||
|
|
||||||
std::vector<int> lightList;
|
std::vector<LightSource*> lightList;
|
||||||
for (unsigned int i=0; i<lights.size(); ++i)
|
for (unsigned int i=0; i<lights.size(); ++i)
|
||||||
{
|
{
|
||||||
const LightManager::LightSourceTransform& l = lights[i];
|
const LightManager::LightSourceTransform& l = lights[i];
|
||||||
if (l.mViewBound.intersects(nodeBound))
|
if (l.mViewBound.intersects(nodeBound))
|
||||||
lightList.push_back(i);
|
lightList.push_back(l.mLightSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lightList.empty())
|
if (lightList.empty())
|
||||||
|
|
|
@ -20,18 +20,15 @@ namespace SceneUtil
|
||||||
// The activation radius
|
// The activation radius
|
||||||
float mRadius;
|
float mRadius;
|
||||||
|
|
||||||
|
int mId;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
META_Node(SceneUtil, SceneUtil::LightSource)
|
META_Node(SceneUtil, SceneUtil::LightSource)
|
||||||
|
|
||||||
LightSource();
|
LightSource();
|
||||||
|
|
||||||
LightSource(const LightSource& copy, const osg::CopyOp& copyop)
|
LightSource(const LightSource& copy, const osg::CopyOp& copyop);
|
||||||
: osg::Node(copy, copyop)
|
|
||||||
, mLight(copy.mLight)
|
|
||||||
, mRadius(copy.mRadius)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
float getRadius() const
|
float getRadius() const
|
||||||
{
|
{
|
||||||
|
@ -52,6 +49,11 @@ namespace SceneUtil
|
||||||
{
|
{
|
||||||
mLight = light;
|
mLight = light;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getId()
|
||||||
|
{
|
||||||
|
return mId;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// All light sources must be a child of the LightManager node. The LightManager can be anywhere in the scene graph,
|
/// All light sources must be a child of the LightManager node. The LightManager can be anywhere in the scene graph,
|
||||||
|
@ -83,8 +85,7 @@ namespace SceneUtil
|
||||||
|
|
||||||
const std::vector<LightSourceTransform>& getLights() const;
|
const std::vector<LightSourceTransform>& getLights() const;
|
||||||
|
|
||||||
// Stores indices into the mLights vector
|
typedef std::vector<LightSource*> LightList;
|
||||||
typedef std::vector<int> LightList;
|
|
||||||
|
|
||||||
osg::ref_ptr<osg::StateSet> getLightListStateSet(const LightList& lightList);
|
osg::ref_ptr<osg::StateSet> getLightListStateSet(const LightList& lightList);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue