1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-11 15:40:39 +00:00

Reduce texture memory usage in OpenMW

This commit is contained in:
scrawl 2015-05-02 19:36:36 +02:00
parent d772da3720
commit 1a5407af98
3 changed files with 14 additions and 2 deletions

View File

@ -17,6 +17,7 @@
#include <components/vfs/registerarchives.hpp>
#include <components/resource/resourcesystem.hpp>
#include <components/resource/texturemanager.hpp>
#include <components/compiler/extensions0.hpp>
@ -307,6 +308,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
VFS::registerArchives(mVFS.get(), mFileCollections, mArchives, true);
mResourceSystem.reset(new Resource::ResourceSystem(mVFS.get()));
mResourceSystem->getTextureManager()->setUnRefImageDataAfterApply(true);
// Create input and UI first to set up a bootstrapping environment for
// showing a loading screen and keeping the window responsive while doing so

View File

@ -37,10 +37,16 @@ namespace Resource
TextureManager::TextureManager(const VFS::Manager *vfs)
: mVFS(vfs)
, mWarningTexture(createWarningTexture())
, mUnRefImageDataAfterApply(false)
{
}
void TextureManager::setUnRefImageDataAfterApply(bool unref)
{
mUnRefImageDataAfterApply = unref;
}
/*
osg::ref_ptr<osg::Image> TextureManager::getImage(const std::string &filename)
{
@ -91,8 +97,7 @@ namespace Resource
texture->setWrap(osg::Texture::WRAP_S, wrapS);
texture->setWrap(osg::Texture::WRAP_T, wrapT);
// Can be enabled for single-context, i.e. in openmw
//texture->setUnRefImageDataAfterApply(true);
texture->setUnRefImageDataAfterApply(mUnRefImageDataAfterApply);
mTextures.insert(std::make_pair(key, texture));
return texture;

View File

@ -24,6 +24,10 @@ namespace Resource
// TODO: texture filtering settings
/// Keep a copy of the texture data around in system memory? This is needed when using multiple graphics contexts,
/// otherwise should be disabled to reduce memory usage.
void setUnRefImageDataAfterApply(bool unref);
/// Create or retrieve a Texture2D using the specified image filename, and wrap parameters.
osg::ref_ptr<osg::Texture2D> getTexture2D(const std::string& filename, osg::Texture::WrapMode wrapS, osg::Texture::WrapMode wrapT);
@ -43,6 +47,7 @@ namespace Resource
osg::ref_ptr<osg::Texture2D> mWarningTexture;
bool mUnRefImageDataAfterApply;
};
}