diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 0dc19144c0..15fee0cb1f 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -17,6 +17,7 @@ #include #include +#include #include @@ -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 diff --git a/components/resource/texturemanager.cpp b/components/resource/texturemanager.cpp index b86b70cde1..939f81d9b8 100644 --- a/components/resource/texturemanager.cpp +++ b/components/resource/texturemanager.cpp @@ -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 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; diff --git a/components/resource/texturemanager.hpp b/components/resource/texturemanager.hpp index f4ade515d3..d44d47d243 100644 --- a/components/resource/texturemanager.hpp +++ b/components/resource/texturemanager.hpp @@ -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 getTexture2D(const std::string& filename, osg::Texture::WrapMode wrapS, osg::Texture::WrapMode wrapT); @@ -43,6 +47,7 @@ namespace Resource osg::ref_ptr mWarningTexture; + bool mUnRefImageDataAfterApply; }; }