GenericObjectCache stored osg::ref_ptr<osg::Object>, so everything cached had to derive from osg::Object whether that meant anything or not: NifFileHolder and BgsmFileHolder existed for no other reason, Resource::BulletShape and ESMTerrain::LandObject carried META_Object and a CopyOp constructor nothing ever called, and every getter paid a static_cast on the way out. The cache and MultiObjectCache now take their value type as a template parameter, ask "is anything else holding this?" through a useCount overload rather than a base class method, and constrain accept and releaseGLObjects so a value type with neither is not an error. Both holders are deleted; BulletShape, BulletShapeInstance and LandObject become plain classes held by std::shared_ptr across physics, pathfinding, navmeshtool and terrain storage; MWPhysics::HeightField's type-erased osg::Object keep-alive becomes the LandObject it was always holding; every remaining manager names the type it actually caches through the NodeResourceManager alias, which removes eight static_casts and stops clang-format wrapping the declarations. The preloader needs two keep-alive sets for now, because the render-owned entries are still osg::Object; they merge once those move behind the render backend.
61 lines
2.0 KiB
C++
61 lines
2.0 KiB
C++
#include "texturemanager.hpp"
|
|
|
|
#include <osg/Texture2D>
|
|
|
|
#include <components/resource/imagemanager.hpp>
|
|
#include <components/resource/objectcache.hpp>
|
|
#include <components/resource/scenemanager.hpp>
|
|
|
|
namespace Terrain
|
|
{
|
|
|
|
TextureManager::TextureManager(Resource::SceneManager* sceneMgr, double expiryDelay)
|
|
: ResourceManager<osg::ref_ptr<osg::Texture2D>>(sceneMgr->getVFS(), expiryDelay)
|
|
, mSceneManager(sceneMgr)
|
|
{
|
|
}
|
|
|
|
struct UpdateTextureFilteringFunctor
|
|
{
|
|
UpdateTextureFilteringFunctor(Resource::SceneManager* sceneMgr)
|
|
: mSceneManager(sceneMgr)
|
|
{
|
|
}
|
|
Resource::SceneManager* mSceneManager;
|
|
|
|
void operator()(std::string, osg::Object* obj)
|
|
{
|
|
mSceneManager->applyFilterSettings(static_cast<osg::Texture2D*>(obj));
|
|
}
|
|
};
|
|
|
|
void TextureManager::updateTextureFiltering()
|
|
{
|
|
UpdateTextureFilteringFunctor f(mSceneManager);
|
|
mCache->call(f);
|
|
}
|
|
|
|
osg::ref_ptr<osg::Texture2D> TextureManager::getTexture(VFS::Path::NormalizedView name)
|
|
{
|
|
// don't bother with case folding, since there is only one way of referring to terrain textures we can assume
|
|
// the case is always the same
|
|
osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(name);
|
|
|
|
if (obj != nullptr)
|
|
return static_cast<osg::Texture2D*>(obj.get());
|
|
|
|
osg::ref_ptr<osg::Texture2D> texture(new osg::Texture2D(mSceneManager->getImageManager()->getImage(name)));
|
|
texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
|
|
texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
|
|
mSceneManager->applyFilterSettings(texture);
|
|
mCache->addEntryToObjectCache(name.value(), texture.get());
|
|
return texture;
|
|
}
|
|
|
|
void TextureManager::reportStats(unsigned int frameNumber, osg::Stats* stats) const
|
|
{
|
|
Resource::reportStats("Terrain Texture", frameNumber, mCache->getStats(), *stats);
|
|
}
|
|
|
|
}
|