Combine some duplicate code

openmw-38
Chris Robinson 9 years ago
parent b830a413d3
commit 5c0a847eaf

@ -451,39 +451,12 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
mResourceSystem.reset(new Resource::ResourceSystem(mVFS.get()));
mResourceSystem->getTextureManager()->setUnRefImageDataAfterApply(true);
{
osg::Texture::FilterMode min = osg::Texture::LINEAR;
osg::Texture::FilterMode mag = osg::Texture::LINEAR;
std::string filter = Settings::Manager::getString("texture filter", "General");
if(filter == "nearest")
{
min = osg::Texture::NEAREST;
mag = osg::Texture::NEAREST;
}
else if(filter != "linear")
std::cerr<< "Invalid texture filter option: "<<filter <<std::endl;
std::string mipmap = Settings::Manager::getString("texture mipmap", "General");
if(mipmap == "nearest")
{
if(min == osg::Texture::NEAREST)
min = osg::Texture::NEAREST_MIPMAP_NEAREST;
else if(min == osg::Texture::LINEAR)
min = osg::Texture::LINEAR_MIPMAP_NEAREST;
}
else if(mipmap != "none")
{
if(mipmap != "linear")
std::cerr<< "Invalid texture mipmap option: "<<mipmap <<std::endl;
if(min == osg::Texture::NEAREST)
min = osg::Texture::NEAREST_MIPMAP_LINEAR;
else if(min == osg::Texture::LINEAR)
min = osg::Texture::LINEAR_MIPMAP_LINEAR;
}
int maxAnisotropy = Settings::Manager::getInt("anisotropy", "General");
mResourceSystem->getTextureManager()->setFilterSettings(min, mag, maxAnisotropy);
}
mResourceSystem->getTextureManager()->setFilterSettings(
Settings::Manager::getString("texture filter", "General"),
Settings::Manager::getString("texture mipmap", "General"),
Settings::Manager::getInt("anisotropy", "General"),
NULL
);
// Create input and UI first to set up a bootstrapping environment for
// showing a loading screen and keeping the window responsive while doing so

@ -781,37 +781,12 @@ namespace MWRender
void RenderingManager::updateTextureFiltering()
{
osg::Texture::FilterMode min = osg::Texture::LINEAR;
osg::Texture::FilterMode mag = osg::Texture::LINEAR;
std::string filter = Settings::Manager::getString("texture filter", "General");
if(filter == "nearest")
{
min = osg::Texture::NEAREST;
mag = osg::Texture::NEAREST;
}
std::string mipmap = Settings::Manager::getString("texture mipmap", "General");
if(mipmap == "nearest")
{
if(min == osg::Texture::NEAREST)
min = osg::Texture::NEAREST_MIPMAP_NEAREST;
else if(min == osg::Texture::LINEAR)
min = osg::Texture::LINEAR_MIPMAP_NEAREST;
}
else if(mipmap != "none")
{
if(min == osg::Texture::NEAREST)
min = osg::Texture::NEAREST_MIPMAP_LINEAR;
else if(min == osg::Texture::LINEAR)
min = osg::Texture::LINEAR_MIPMAP_LINEAR;
}
int maxAnisotropy = Settings::Manager::getInt("anisotropy", "General");
mViewer->stopThreading();
mResourceSystem->getTextureManager()->setFilterSettings(min, mag, maxAnisotropy);
mViewer->startThreading();
mResourceSystem->getTextureManager()->setFilterSettings(
Settings::Manager::getString("texture filter", "General"),
Settings::Manager::getString("texture mipmap", "General"),
Settings::Manager::getInt("anisotropy", "General"),
mViewer
);
}
void RenderingManager::updateAmbient()

@ -3,6 +3,7 @@
#include <osgDB/Registry>
#include <osg/GLExtensions>
#include <osg/Version>
#include <osgViewer/Viewer>
#include <stdexcept>
@ -65,6 +66,41 @@ namespace Resource
mUnRefImageDataAfterApply = unref;
}
void TextureManager::setFilterSettings(const std::string &filter, const std::string &mipmap, int maxAnisotropy, osgViewer::Viewer *viewer)
{
osg::Texture::FilterMode min = osg::Texture::LINEAR;
osg::Texture::FilterMode mag = osg::Texture::LINEAR;
if(filter == "nearest")
{
min = osg::Texture::NEAREST;
mag = osg::Texture::NEAREST;
}
else if(filter != "linear")
std::cerr<< "Invalid texture filter: "<<filter <<std::endl;
if(mipmap == "nearest")
{
if(min == osg::Texture::NEAREST)
min = osg::Texture::NEAREST_MIPMAP_NEAREST;
else if(min == osg::Texture::LINEAR)
min = osg::Texture::LINEAR_MIPMAP_NEAREST;
}
else if(mipmap != "none")
{
if(mipmap != "linear")
std::cerr<< "Invalid texture mipmap: "<<mipmap <<std::endl;
if(min == osg::Texture::NEAREST)
min = osg::Texture::NEAREST_MIPMAP_LINEAR;
else if(min == osg::Texture::LINEAR)
min = osg::Texture::LINEAR_MIPMAP_LINEAR;
}
if(viewer) viewer->stopThreading();
setFilterSettings(min, mag, maxAnisotropy);
if(viewer) viewer->startThreading();
}
void TextureManager::setFilterSettings(osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter, int maxAnisotropy)
{
mMinFilter = minFilter;

@ -8,6 +8,11 @@
#include <osg/Image>
#include <osg/Texture2D>
namespace osgViewer
{
class Viewer;
}
namespace VFS
{
class Manager;
@ -23,8 +28,8 @@ namespace Resource
TextureManager(const VFS::Manager* vfs);
~TextureManager();
/// @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);
void setFilterSettings(const std::string &filter, const std::string &mipmap, int maxAnisotropy,
osgViewer::Viewer *view);
/// 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.
@ -58,6 +63,9 @@ namespace Resource
bool mUnRefImageDataAfterApply;
/// @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);
TextureManager(const TextureManager&);
void operator = (const TextureManager&);
};

Loading…
Cancel
Save