From 1d198a5592e0d4d6f3a4d0b7388d87f5e29b3482 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 15 Jun 2015 18:09:01 +0200 Subject: [PATCH] Keep the light list StateSet cache for more than one frame --- components/sceneutil/lightmanager.cpp | 23 +++++++++++++++-------- components/sceneutil/lightmanager.hpp | 17 +++++++++-------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/components/sceneutil/lightmanager.cpp b/components/sceneutil/lightmanager.cpp index 6040f9536..65955d9af 100644 --- a/components/sceneutil/lightmanager.cpp +++ b/components/sceneutil/lightmanager.cpp @@ -145,7 +145,6 @@ namespace SceneUtil { mLightsInViewSpace = false; mLights.clear(); - mStateSetCache.clear(); } 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) size_t hash = 0; for (unsigned int i=0; igetId()); LightStateSetMap::iterator found = mStateSetCache.find(hash); if (found != mStateSetCache.end()) @@ -190,10 +189,7 @@ namespace SceneUtil std::vector > lights; for (unsigned int i=0; igetLight()); - } + lights.push_back(lightList[i]->getLight()); osg::ref_ptr attr = new LightStateAttribute(mStartLight, lights); @@ -223,11 +219,22 @@ namespace SceneUtil return mStartLight; } + static int sLightId = 0; + LightSource::LightSource() : mRadius(0.f) { setNodeMask(Mask_Lit); 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) @@ -282,12 +289,12 @@ namespace SceneUtil osg::Matrixf mat = *cv->getModelViewMatrix(); transformBoundingSphere(mat, nodeBound); - std::vector lightList; + std::vector lightList; for (unsigned int i=0; i& getLights() const; - // Stores indices into the mLights vector - typedef std::vector LightList; + typedef std::vector LightList; osg::ref_ptr getLightListStateSet(const LightList& lightList);