From b4a6b6387bd529ac11fea137720b5c6f6f21deab Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 3 Feb 2017 03:11:36 +0100 Subject: [PATCH] Create own instance of osgDB::SharedStateManager so we control when to call prune() prune() is now called in the background thread, just like the resource cache update. Seems to improve performance by ~0.3 ms/frame --- components/resource/scenemanager.cpp | 7 ++++++- components/resource/scenemanager.hpp | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/components/resource/scenemanager.cpp b/components/resource/scenemanager.cpp index cc719e231..de4ce28a5 100644 --- a/components/resource/scenemanager.cpp +++ b/components/resource/scenemanager.cpp @@ -181,6 +181,7 @@ namespace Resource , mAutoUseNormalMaps(false) , mAutoUseSpecularMaps(false) , mInstanceCache(new MultiObjectCache) + , mSharedStateManager(new osgDB::SharedStateManager) , mImageManager(imageManager) , mNifFileManager(nifFileManager) , mMinFilter(osg::Texture::LINEAR_MIPMAP_LINEAR) @@ -392,7 +393,7 @@ namespace Resource // share state mSharedStateMutex.lock(); - osgDB::Registry::instance()->getOrCreateSharedStateManager()->share(loaded.get()); + mSharedStateManager->share(loaded.get()); mSharedStateMutex.unlock(); if (mIncrementalCompileOperation) @@ -549,6 +550,10 @@ namespace Resource void SceneManager::updateCache(double referenceTime) { + mSharedStateMutex.lock(); + mSharedStateManager->prune(); + mSharedStateMutex.unlock(); + ResourceManager::updateCache(referenceTime); mInstanceCache->removeUnreferencedObjectsInCache(); diff --git a/components/resource/scenemanager.hpp b/components/resource/scenemanager.hpp index a2107fc4a..ee4a453a3 100644 --- a/components/resource/scenemanager.hpp +++ b/components/resource/scenemanager.hpp @@ -22,6 +22,11 @@ namespace osgUtil class IncrementalCompileOperation; } +namespace osgDB +{ + class SharedStateManager; +} + namespace Shader { class ShaderManager; @@ -147,6 +152,7 @@ namespace Resource osg::ref_ptr mInstanceCache; + osg::ref_ptr mSharedStateManager; OpenThreads::Mutex mSharedStateMutex; Resource::ImageManager* mImageManager;