forked from teamnwah/openmw-tes3coop
Use the osgDB::ObjectCache in SceneManager, cleanup
This commit is contained in:
parent
909c4d96b6
commit
ea1efaac0c
5 changed files with 30 additions and 27 deletions
|
@ -26,6 +26,9 @@ namespace Resource
|
||||||
class BulletShape;
|
class BulletShape;
|
||||||
class BulletShapeInstance;
|
class BulletShapeInstance;
|
||||||
|
|
||||||
|
/// Handles loading, caching and "instancing" of bullet shapes.
|
||||||
|
/// A shape 'instance' is a clone of another shape, with the goal of setting a different scale on this instance.
|
||||||
|
/// @note May be used from any thread.
|
||||||
class BulletShapeManager
|
class BulletShapeManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace Resource
|
||||||
{
|
{
|
||||||
|
|
||||||
/// @brief Managing of keyframe resources
|
/// @brief Managing of keyframe resources
|
||||||
|
/// @note May be used from any thread.
|
||||||
class KeyframeManager
|
class KeyframeManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -32,7 +33,6 @@ namespace Resource
|
||||||
void clearCache();
|
void clearCache();
|
||||||
|
|
||||||
/// Retrieve a read-only keyframe resource by name (case-insensitive).
|
/// Retrieve a read-only keyframe resource by name (case-insensitive).
|
||||||
/// @note This method is safe to call from any thread.
|
|
||||||
/// @note Throws an exception if the resource is not found.
|
/// @note Throws an exception if the resource is not found.
|
||||||
osg::ref_ptr<const NifOsg::KeyframeHolder> get(const std::string& name);
|
osg::ref_ptr<const NifOsg::KeyframeHolder> get(const std::string& name);
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace Resource
|
||||||
{
|
{
|
||||||
|
|
||||||
/// @brief Handles caching of NIFFiles.
|
/// @brief Handles caching of NIFFiles.
|
||||||
/// @note The NifFileManager is completely thread safe.
|
/// @note May be used from any thread.
|
||||||
class NifFileManager
|
class NifFileManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -26,10 +26,12 @@
|
||||||
|
|
||||||
#include "imagemanager.hpp"
|
#include "imagemanager.hpp"
|
||||||
#include "niffilemanager.hpp"
|
#include "niffilemanager.hpp"
|
||||||
|
#include "objectcache.hpp"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/// @todo Do this in updateCallback so that animations are accounted for.
|
||||||
class InitWorldSpaceParticlesVisitor : public osg::NodeVisitor
|
class InitWorldSpaceParticlesVisitor : public osg::NodeVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -236,6 +238,7 @@ namespace Resource
|
||||||
, mMaxAnisotropy(1)
|
, mMaxAnisotropy(1)
|
||||||
, mUnRefImageDataAfterApply(false)
|
, mUnRefImageDataAfterApply(false)
|
||||||
, mParticleSystemMask(~0u)
|
, mParticleSystemMask(~0u)
|
||||||
|
, mCache(new osgDB::ObjectCache)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,8 +318,10 @@ namespace Resource
|
||||||
std::string normalized = name;
|
std::string normalized = name;
|
||||||
mVFS->normalizeFilename(normalized);
|
mVFS->normalizeFilename(normalized);
|
||||||
|
|
||||||
Index::iterator it = mIndex.find(normalized);
|
osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(normalized);
|
||||||
if (it == mIndex.end())
|
if (obj)
|
||||||
|
return osg::ref_ptr<const osg::Node>(static_cast<osg::Node*>(obj.get()));
|
||||||
|
else
|
||||||
{
|
{
|
||||||
osg::ref_ptr<osg::Node> loaded;
|
osg::ref_ptr<osg::Node> loaded;
|
||||||
try
|
try
|
||||||
|
@ -357,11 +362,9 @@ namespace Resource
|
||||||
if (mIncrementalCompileOperation)
|
if (mIncrementalCompileOperation)
|
||||||
mIncrementalCompileOperation->add(loaded);
|
mIncrementalCompileOperation->add(loaded);
|
||||||
|
|
||||||
mIndex[normalized] = loaded;
|
mCache->addEntryToObjectCache(normalized, loaded);
|
||||||
return loaded;
|
return loaded;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
return it->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::ref_ptr<osg::Node> SceneManager::createInstance(const std::string &name)
|
osg::ref_ptr<osg::Node> SceneManager::createInstance(const std::string &name)
|
||||||
|
@ -386,10 +389,7 @@ namespace Resource
|
||||||
|
|
||||||
void SceneManager::releaseGLObjects(osg::State *state)
|
void SceneManager::releaseGLObjects(osg::State *state)
|
||||||
{
|
{
|
||||||
for (Index::iterator it = mIndex.begin(); it != mIndex.end(); ++it)
|
mCache->releaseGLObjects(state);
|
||||||
{
|
|
||||||
it->second->releaseGLObjects(state);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneManager::setIncrementalCompileOperation(osgUtil::IncrementalCompileOperation *ico)
|
void SceneManager::setIncrementalCompileOperation(osgUtil::IncrementalCompileOperation *ico)
|
||||||
|
@ -458,6 +458,8 @@ namespace Resource
|
||||||
mMagFilter = mag;
|
mMagFilter = mag;
|
||||||
mMaxAnisotropy = std::max(1, maxAnisotropy);
|
mMaxAnisotropy = std::max(1, maxAnisotropy);
|
||||||
|
|
||||||
|
mCache->clear();
|
||||||
|
|
||||||
SetFilterSettingsControllerVisitor setFilterSettingsControllerVisitor (mMinFilter, mMagFilter, mMaxAnisotropy);
|
SetFilterSettingsControllerVisitor setFilterSettingsControllerVisitor (mMinFilter, mMagFilter, mMaxAnisotropy);
|
||||||
SetFilterSettingsVisitor setFilterSettingsVisitor (mMinFilter, mMagFilter, mMaxAnisotropy);
|
SetFilterSettingsVisitor setFilterSettingsVisitor (mMinFilter, mMagFilter, mMaxAnisotropy);
|
||||||
if (viewer && viewer->getSceneData())
|
if (viewer && viewer->getSceneData())
|
||||||
|
@ -466,13 +468,6 @@ namespace Resource
|
||||||
viewer->getSceneData()->accept(setFilterSettingsVisitor);
|
viewer->getSceneData()->accept(setFilterSettingsVisitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Index::iterator it = mIndex.begin(); it != mIndex.end(); ++it)
|
|
||||||
{
|
|
||||||
osg::Node* node = it->second;
|
|
||||||
node->accept(setFilterSettingsControllerVisitor);
|
|
||||||
node->accept(setFilterSettingsVisitor);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(viewer) viewer->startThreading();
|
if(viewer) viewer->startThreading();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,11 @@ namespace osgUtil
|
||||||
class IncrementalCompileOperation;
|
class IncrementalCompileOperation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace osgDB
|
||||||
|
{
|
||||||
|
class ObjectCache;
|
||||||
|
}
|
||||||
|
|
||||||
namespace osgViewer
|
namespace osgViewer
|
||||||
{
|
{
|
||||||
class Viewer;
|
class Viewer;
|
||||||
|
@ -32,7 +37,8 @@ namespace osgViewer
|
||||||
namespace Resource
|
namespace Resource
|
||||||
{
|
{
|
||||||
|
|
||||||
/// @brief Handles loading and caching of scenes, e.g. NIF files
|
/// @brief Handles loading and caching of scenes, e.g. .nif files or .osg files
|
||||||
|
/// @note Some methods of the scene manager can be used from any thread, see the methods documentation for more details.
|
||||||
class SceneManager
|
class SceneManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -42,20 +48,24 @@ namespace Resource
|
||||||
/// Get a read-only copy of this scene "template"
|
/// Get a read-only copy of this scene "template"
|
||||||
/// @note If the given filename does not exist or fails to load, an error marker mesh will be used instead.
|
/// @note If the given filename does not exist or fails to load, an error marker mesh will be used instead.
|
||||||
/// If even the error marker mesh can not be found, an exception is thrown.
|
/// If even the error marker mesh can not be found, an exception is thrown.
|
||||||
|
/// @note Thread safe.
|
||||||
osg::ref_ptr<const osg::Node> getTemplate(const std::string& name);
|
osg::ref_ptr<const osg::Node> getTemplate(const std::string& name);
|
||||||
|
|
||||||
/// Create an instance of the given scene template
|
/// Create an instance of the given scene template
|
||||||
/// @see getTemplate
|
/// @see getTemplate
|
||||||
|
/// @note Thread safe.
|
||||||
osg::ref_ptr<osg::Node> createInstance(const std::string& name);
|
osg::ref_ptr<osg::Node> createInstance(const std::string& name);
|
||||||
|
|
||||||
/// Create an instance of the given scene template and immediately attach it to a parent node
|
/// Create an instance of the given scene template and immediately attach it to a parent node
|
||||||
/// @see getTemplate
|
/// @see getTemplate
|
||||||
|
/// @note Not thread safe, unless parentNode is not part of the main scene graph yet.
|
||||||
osg::ref_ptr<osg::Node> createInstance(const std::string& name, osg::Group* parentNode);
|
osg::ref_ptr<osg::Node> createInstance(const std::string& name, osg::Group* parentNode);
|
||||||
|
|
||||||
/// Attach the given scene instance to the given parent node
|
/// Attach the given scene instance to the given parent node
|
||||||
/// @note You should have the parentNode in its intended position before calling this method,
|
/// @note You should have the parentNode in its intended position before calling this method,
|
||||||
/// so that world space particles of the \a instance get transformed correctly.
|
/// so that world space particles of the \a instance get transformed correctly.
|
||||||
/// @note Assumes the given instance was not attached to any parents before.
|
/// @note Assumes the given instance was not attached to any parents before.
|
||||||
|
/// @note Not thread safe, unless parentNode is not part of the main scene graph yet.
|
||||||
void attachTo(osg::Node* instance, osg::Group* parentNode) const;
|
void attachTo(osg::Node* instance, osg::Group* parentNode) const;
|
||||||
|
|
||||||
/// Manually release created OpenGL objects for the given graphics context. This may be required
|
/// Manually release created OpenGL objects for the given graphics context. This may be required
|
||||||
|
@ -75,11 +85,12 @@ namespace Resource
|
||||||
/// @param mask The node mask to apply to loaded particle system nodes.
|
/// @param mask The node mask to apply to loaded particle system nodes.
|
||||||
void setParticleSystemMask(unsigned int mask);
|
void setParticleSystemMask(unsigned int mask);
|
||||||
|
|
||||||
|
/// @param viewer used to apply the new filter settings to the existing scene graph. If there is no scene yet, you can pass a NULL viewer.
|
||||||
void setFilterSettings(const std::string &magfilter, const std::string &minfilter,
|
void setFilterSettings(const std::string &magfilter, const std::string &minfilter,
|
||||||
const std::string &mipmap, int maxAnisotropy,
|
const std::string &mipmap, int maxAnisotropy,
|
||||||
osgViewer::Viewer *viewer);
|
osgViewer::Viewer *viewer);
|
||||||
|
|
||||||
/// Apply filter settings to the given texture. Note, when loading an object through this scene manager (i.e. calling getTemplate / createInstance)
|
/// Apply filter settings to the given texture. Note, when loading an object through this scene manager (i.e. calling getTemplate or createInstance)
|
||||||
/// the filter settings are applied automatically. This method is provided for textures that were created outside of the SceneManager.
|
/// the filter settings are applied automatically. This method is provided for textures that were created outside of the SceneManager.
|
||||||
void applyFilterSettings (osg::Texture* tex);
|
void applyFilterSettings (osg::Texture* tex);
|
||||||
|
|
||||||
|
@ -101,16 +112,10 @@ namespace Resource
|
||||||
|
|
||||||
unsigned int mParticleSystemMask;
|
unsigned int mParticleSystemMask;
|
||||||
|
|
||||||
// observer_ptr?
|
osg::ref_ptr<osgDB::ObjectCache> mCache;
|
||||||
typedef std::map<std::string, osg::ref_ptr<osg::Node> > Index;
|
|
||||||
Index mIndex;
|
|
||||||
|
|
||||||
SceneManager(const SceneManager&);
|
SceneManager(const SceneManager&);
|
||||||
void operator = (const SceneManager&);
|
void operator = (const SceneManager&);
|
||||||
|
|
||||||
/// @warning It is unsafe to call this function when a draw thread is using the textures. Call stopThreading() first!
|
|
||||||
void setFilterSettings(osg::Texture::FilterMode minFilter, osg::Texture::FilterMode maxFilter, int maxAnisotropy);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue