Merge pull request #858 from kcat/master

Separate and expand texture filtering options
openmw-38
scrawl 9 years ago
commit 69ccca490e

@ -451,12 +451,13 @@ 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_MIPMAP_NEAREST;
osg::Texture::FilterMode mag = osg::Texture::LINEAR;
if (Settings::Manager::getString("texture filtering", "General") == "trilinear")
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 mag filter", "General"),
Settings::Manager::getString("texture min 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

@ -35,12 +35,13 @@ namespace
return "#{sOn}";
}
std::string textureFilteringToStr(const std::string& val)
std::string textureMipmappingToStr(const std::string& val)
{
if (val == "trilinear")
return "Trilinear";
else
return "Bilinear";
if (val == "linear") return "Trilinear";
if (val == "nearest") return "Bilinear";
if (val != "none")
std::cerr<< "Invalid texture mipmap option: "<<val <<std::endl;
return "Other";
}
void parseResolution (int &x, int &y, const std::string& str)
@ -235,8 +236,8 @@ namespace MWGui
}
highlightCurrentResolution();
std::string tf = Settings::Manager::getString("texture filtering", "General");
mTextureFilteringButton->setCaption(textureFilteringToStr(tf));
std::string tmip = Settings::Manager::getString("texture mipmap", "General");
mTextureFilteringButton->setCaption(textureMipmappingToStr(tmip));
mAnisotropyLabel->setCaption("Anisotropy (" + MyGUI::utility::toString(Settings::Manager::getInt("anisotropy", "General")) + ")");
int waterTextureSize = Settings::Manager::getInt ("rtt size", "Water");
@ -425,7 +426,12 @@ namespace MWGui
void SettingsWindow::onTextureFilteringChanged(MyGUI::ComboBox* _sender, size_t pos)
{
Settings::Manager::setString("texture filtering", "General", Misc::StringUtils::lowerCase(_sender->getItemNameAt(pos)));
if(pos == 0)
Settings::Manager::setString("texture mipmap", "General", "nearest");
else if(pos == 1)
Settings::Manager::setString("texture mipmap", "General", "linear");
else
std::cerr<< "Unexpected option pos "<<pos <<std::endl;
apply();
}

@ -781,17 +781,13 @@ namespace MWRender
void RenderingManager::updateTextureFiltering()
{
osg::Texture::FilterMode min = osg::Texture::LINEAR_MIPMAP_NEAREST;
osg::Texture::FilterMode mag = osg::Texture::LINEAR;
if (Settings::Manager::getString("texture filtering", "General") == "trilinear")
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 mag filter", "General"),
Settings::Manager::getString("texture min filter", "General"),
Settings::Manager::getString("texture mipmap", "General"),
Settings::Manager::getInt("anisotropy", "General"),
mViewer
);
}
void RenderingManager::updateAmbient()
@ -826,7 +822,9 @@ namespace MWRender
mStateUpdater->setFogEnd(mViewDistance);
updateProjectionMatrix();
}
else if (it->first == "General" && (it->second == "texture filtering" || it->second == "anisotropy"))
else if (it->first == "General" && (it->second == "texture filter" ||
it->second == "texture mipmap" ||
it->second == "anisotropy"))
updateTextureFiltering();
else if (it->first == "Water")
mWater->processChangedSettings(changed);

@ -3,6 +3,7 @@
#include <osgDB/Registry>
#include <osg/GLExtensions>
#include <osg/Version>
#include <osgViewer/Viewer>
#include <stdexcept>
@ -65,6 +66,45 @@ namespace Resource
mUnRefImageDataAfterApply = unref;
}
void TextureManager::setFilterSettings(const std::string &magfilter, const std::string &minfilter,
const std::string &mipmap, int maxAnisotropy,
osgViewer::Viewer *viewer)
{
osg::Texture::FilterMode min = osg::Texture::LINEAR;
osg::Texture::FilterMode mag = osg::Texture::LINEAR;
if(magfilter == "nearest")
mag = osg::Texture::NEAREST;
else if(magfilter != "linear")
std::cerr<< "Invalid texture mag filter: "<<magfilter <<std::endl;
if(minfilter == "nearest")
min = osg::Texture::NEAREST;
else if(minfilter != "linear")
std::cerr<< "Invalid texture min filter: "<<minfilter <<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,9 @@ 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 &magfilter, const std::string &minfilter,
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 +64,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&);
};

@ -110,8 +110,14 @@ anisotropy = 4
# File format for screenshots. (jpg, png, tga, and possibly more).
screenshot format = png
# Isotropic texture filtering. (bilinear or trilinear).
texture filtering = trilinear
# Texture magnification filter type. (nearest or linear).
texture mag filter = linear
# Texture minification filter type. (nearest or linear).
texture min filter = linear
# Texture mipmap type. (none, nearest, or linear).
texture mipmap = nearest
[Input]

Loading…
Cancel
Save