mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-30 11:06:43 +00:00
Combine some duplicate code
This commit is contained in:
parent
b830a413d3
commit
5c0a847eaf
4 changed files with 58 additions and 66 deletions
|
@ -451,39 +451,12 @@ 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);
|
||||||
{
|
mResourceSystem->getTextureManager()->setFilterSettings(
|
||||||
osg::Texture::FilterMode min = osg::Texture::LINEAR;
|
Settings::Manager::getString("texture filter", "General"),
|
||||||
osg::Texture::FilterMode mag = osg::Texture::LINEAR;
|
Settings::Manager::getString("texture mipmap", "General"),
|
||||||
|
Settings::Manager::getInt("anisotropy", "General"),
|
||||||
std::string filter = Settings::Manager::getString("texture filter", "General");
|
NULL
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
||||||
|
|
|
@ -781,37 +781,12 @@ namespace MWRender
|
||||||
|
|
||||||
void RenderingManager::updateTextureFiltering()
|
void RenderingManager::updateTextureFiltering()
|
||||||
{
|
{
|
||||||
osg::Texture::FilterMode min = osg::Texture::LINEAR;
|
mResourceSystem->getTextureManager()->setFilterSettings(
|
||||||
osg::Texture::FilterMode mag = osg::Texture::LINEAR;
|
Settings::Manager::getString("texture filter", "General"),
|
||||||
|
Settings::Manager::getString("texture mipmap", "General"),
|
||||||
std::string filter = Settings::Manager::getString("texture filter", "General");
|
Settings::Manager::getInt("anisotropy", "General"),
|
||||||
if(filter == "nearest")
|
mViewer
|
||||||
{
|
);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderingManager::updateAmbient()
|
void RenderingManager::updateAmbient()
|
||||||
|
|
|
@ -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,41 @@ namespace Resource
|
||||||
mUnRefImageDataAfterApply = unref;
|
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)
|
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,8 @@ 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 &filter, const std::string &mipmap, int maxAnisotropy,
|
||||||
void setFilterSettings(osg::Texture::FilterMode minFilter, osg::Texture::FilterMode maxFilter, 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 +63,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&);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue