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.reset(new Resource::ResourceSystem(mVFS.get()));
mResourceSystem->getTextureManager()->setUnRefImageDataAfterApply(true); mResourceSystem->getTextureManager()->setUnRefImageDataAfterApply(true);
osg::Texture::FilterMode min = osg::Texture::LINEAR_MIPMAP_NEAREST; mResourceSystem->getTextureManager()->setFilterSettings(
osg::Texture::FilterMode mag = osg::Texture::LINEAR; Settings::Manager::getString("texture mag filter", "General"),
if (Settings::Manager::getString("texture filtering", "General") == "trilinear") Settings::Manager::getString("texture min filter", "General"),
min = osg::Texture::LINEAR_MIPMAP_LINEAR; Settings::Manager::getString("texture mipmap", "General"),
int maxAnisotropy = Settings::Manager::getInt("anisotropy", "General"); Settings::Manager::getInt("anisotropy", "General"),
mResourceSystem->getTextureManager()->setFilterSettings(min, mag, maxAnisotropy); NULL
);
// Create input and UI first to set up a bootstrapping environment for // Create input and UI first to set up a bootstrapping environment for
// showing a loading screen and keeping the window responsive while doing so // showing a loading screen and keeping the window responsive while doing so

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

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

@ -3,6 +3,7 @@
#include <osgDB/Registry> #include <osgDB/Registry>
#include <osg/GLExtensions> #include <osg/GLExtensions>
#include <osg/Version> #include <osg/Version>
#include <osgViewer/Viewer>
#include <stdexcept> #include <stdexcept>
@ -65,6 +66,45 @@ namespace Resource
mUnRefImageDataAfterApply = unref; 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) void TextureManager::setFilterSettings(osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter, int maxAnisotropy)
{ {
mMinFilter = minFilter; mMinFilter = minFilter;

@ -8,6 +8,11 @@
#include <osg/Image> #include <osg/Image>
#include <osg/Texture2D> #include <osg/Texture2D>
namespace osgViewer
{
class Viewer;
}
namespace VFS namespace VFS
{ {
class Manager; class Manager;
@ -23,8 +28,9 @@ namespace Resource
TextureManager(const VFS::Manager* vfs); TextureManager(const VFS::Manager* vfs);
~TextureManager(); ~TextureManager();
/// @warning It is unsafe to call this function when a draw thread is using the textures. Call stopThreading() first! void setFilterSettings(const std::string &magfilter, const std::string &minfilter,
void setFilterSettings(osg::Texture::FilterMode minFilter, osg::Texture::FilterMode maxFilter, int maxAnisotropy); 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, /// 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. /// otherwise should be disabled to reduce memory usage.
@ -58,6 +64,9 @@ namespace Resource
bool mUnRefImageDataAfterApply; 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&); TextureManager(const TextureManager&);
void operator = (const TextureManager&); void operator = (const TextureManager&);
}; };

@ -110,8 +110,14 @@ anisotropy = 4
# File format for screenshots. (jpg, png, tga, and possibly more). # File format for screenshots. (jpg, png, tga, and possibly more).
screenshot format = png screenshot format = png
# Isotropic texture filtering. (bilinear or trilinear). # Texture magnification filter type. (nearest or linear).
texture filtering = trilinear 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] [Input]

Loading…
Cancel
Save