forked from teamnwah/openmw-tes3coop
Apply texture filter setting changes
This commit is contained in:
parent
5442bf23a6
commit
24bb2e152c
10 changed files with 72 additions and 27 deletions
|
@ -419,6 +419,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);
|
||||||
|
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);
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -469,7 +475,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the world
|
// Create the world
|
||||||
mEnvironment.setWorld( new MWWorld::World (*mViewer, rootNode, mResourceSystem.get(),
|
mEnvironment.setWorld( new MWWorld::World (mViewer, rootNode, mResourceSystem.get(),
|
||||||
mFileCollections, mContentFiles, mEncoder, mFallbackMap,
|
mFileCollections, mContentFiles, mEncoder, mFallbackMap,
|
||||||
mActivationDistanceOverride, mCellName, mStartupScript));
|
mActivationDistanceOverride, mCellName, mStartupScript));
|
||||||
MWBase::Environment::get().getWorld()->setupPlayer();
|
MWBase::Environment::get().getWorld()->setupPlayer();
|
||||||
|
|
|
@ -38,12 +38,10 @@ namespace
|
||||||
|
|
||||||
std::string textureFilteringToStr(const std::string& val)
|
std::string textureFilteringToStr(const std::string& val)
|
||||||
{
|
{
|
||||||
if (val == "anisotropic")
|
if (val == "trilinear")
|
||||||
return "Anisotropic";
|
|
||||||
else if (val == "bilinear")
|
|
||||||
return "Bilinear";
|
|
||||||
else
|
|
||||||
return "Trilinear";
|
return "Trilinear";
|
||||||
|
else
|
||||||
|
return "Bilinear";
|
||||||
}
|
}
|
||||||
|
|
||||||
void parseResolution (int &x, int &y, const std::string& str)
|
void parseResolution (int &x, int &y, const std::string& str)
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <osgViewer/Viewer>
|
#include <osgViewer/Viewer>
|
||||||
|
|
||||||
#include <components/resource/resourcesystem.hpp>
|
#include <components/resource/resourcesystem.hpp>
|
||||||
|
#include <components/resource/texturemanager.hpp>
|
||||||
|
|
||||||
#include <components/settings/settings.hpp>
|
#include <components/settings/settings.hpp>
|
||||||
|
|
||||||
|
@ -82,7 +83,7 @@ namespace MWRender
|
||||||
float mFogEnd;
|
float mFogEnd;
|
||||||
};
|
};
|
||||||
|
|
||||||
RenderingManager::RenderingManager(osgViewer::Viewer &viewer, osg::ref_ptr<osg::Group> rootNode, Resource::ResourceSystem* resourceSystem)
|
RenderingManager::RenderingManager(osgViewer::Viewer* viewer, osg::ref_ptr<osg::Group> rootNode, Resource::ResourceSystem* resourceSystem)
|
||||||
: mViewer(viewer)
|
: mViewer(viewer)
|
||||||
, mRootNode(rootNode)
|
, mRootNode(rootNode)
|
||||||
, mResourceSystem(resourceSystem)
|
, mResourceSystem(resourceSystem)
|
||||||
|
@ -97,13 +98,13 @@ namespace MWRender
|
||||||
|
|
||||||
mObjects.reset(new Objects(mResourceSystem, lightRoot));
|
mObjects.reset(new Objects(mResourceSystem, lightRoot));
|
||||||
|
|
||||||
mViewer.setIncrementalCompileOperation(new osgUtil::IncrementalCompileOperation);
|
mViewer->setIncrementalCompileOperation(new osgUtil::IncrementalCompileOperation);
|
||||||
|
|
||||||
mObjects->setIncrementalCompileOperation(mViewer.getIncrementalCompileOperation());
|
mObjects->setIncrementalCompileOperation(mViewer->getIncrementalCompileOperation());
|
||||||
|
|
||||||
mEffectManager.reset(new EffectManager(mRootNode, mResourceSystem));
|
mEffectManager.reset(new EffectManager(mRootNode, mResourceSystem));
|
||||||
|
|
||||||
mViewer.setLightingMode(osgViewer::View::NO_LIGHT);
|
mViewer->setLightingMode(osgViewer::View::NO_LIGHT);
|
||||||
|
|
||||||
osg::ref_ptr<osg::LightSource> source = new osg::LightSource;
|
osg::ref_ptr<osg::LightSource> source = new osg::LightSource;
|
||||||
mSunLight = new osg::Light;
|
mSunLight = new osg::Light;
|
||||||
|
@ -133,10 +134,10 @@ namespace MWRender
|
||||||
else
|
else
|
||||||
cullingMode |= osg::CullStack::SMALL_FEATURE_CULLING;
|
cullingMode |= osg::CullStack::SMALL_FEATURE_CULLING;
|
||||||
|
|
||||||
viewer.getCamera()->setCullingMode( cullingMode );
|
mViewer->getCamera()->setCullingMode( cullingMode );
|
||||||
|
|
||||||
mViewer.getCamera()->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
|
mViewer->getCamera()->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
|
||||||
mViewer.getCamera()->setCullingMode(cullingMode);
|
mViewer->getCamera()->setCullingMode(cullingMode);
|
||||||
|
|
||||||
mViewDistance = Settings::Manager::getFloat("viewing distance", "Viewing distance");
|
mViewDistance = Settings::Manager::getFloat("viewing distance", "Viewing distance");
|
||||||
mFieldOfView = Settings::Manager::getFloat("field of view", "General");
|
mFieldOfView = Settings::Manager::getFloat("field of view", "General");
|
||||||
|
@ -184,7 +185,7 @@ namespace MWRender
|
||||||
|
|
||||||
osg::Vec3f RenderingManager::getEyePos()
|
osg::Vec3f RenderingManager::getEyePos()
|
||||||
{
|
{
|
||||||
osg::Vec3d eye = mViewer.getCameraManipulator()->getMatrix().getTrans();
|
osg::Vec3d eye = mViewer->getCameraManipulator()->getMatrix().getTrans();
|
||||||
return eye;
|
return eye;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,7 +233,7 @@ namespace MWRender
|
||||||
|
|
||||||
void RenderingManager::configureFog(float /* fogDepth */, const osg::Vec4f &colour)
|
void RenderingManager::configureFog(float /* fogDepth */, const osg::Vec4f &colour)
|
||||||
{
|
{
|
||||||
mViewer.getCamera()->setClearColor(colour);
|
mViewer->getCamera()->setClearColor(colour);
|
||||||
|
|
||||||
mStateUpdater->setFogColor(colour);
|
mStateUpdater->setFogColor(colour);
|
||||||
mStateUpdater->setFogEnd(mViewDistance);
|
mStateUpdater->setFogEnd(mViewDistance);
|
||||||
|
@ -325,11 +326,26 @@ namespace MWRender
|
||||||
void RenderingManager::updateProjectionMatrix()
|
void RenderingManager::updateProjectionMatrix()
|
||||||
{
|
{
|
||||||
double fovy, aspect, zNear, zFar;
|
double fovy, aspect, zNear, zFar;
|
||||||
mViewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspect, zNear, zFar);
|
mViewer->getCamera()->getProjectionMatrixAsPerspective(fovy, aspect, zNear, zFar);
|
||||||
fovy = mFieldOfView;
|
fovy = mFieldOfView;
|
||||||
zNear = 5.f;
|
zNear = 5.f;
|
||||||
zFar = mViewDistance;
|
zFar = mViewDistance;
|
||||||
mViewer.getCamera()->setProjectionMatrixAsPerspective(fovy, aspect, zNear, zFar);
|
mViewer->getCamera()->setProjectionMatrixAsPerspective(fovy, aspect, zNear, zFar);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderingManager::processChangedSettings(const Settings::CategorySettingVector &changed)
|
void RenderingManager::processChangedSettings(const Settings::CategorySettingVector &changed)
|
||||||
|
@ -346,6 +362,8 @@ namespace MWRender
|
||||||
mViewDistance = Settings::Manager::getFloat("viewing distance", "Viewing distance");
|
mViewDistance = Settings::Manager::getFloat("viewing distance", "Viewing distance");
|
||||||
updateProjectionMatrix();
|
updateProjectionMatrix();
|
||||||
}
|
}
|
||||||
|
else if (it->first == "General" && (it->second == "texture filtering" || it->second == "anisotropy"))
|
||||||
|
updateTextureFiltering();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ namespace MWRender
|
||||||
class RenderingManager : public MWRender::RenderingInterface
|
class RenderingManager : public MWRender::RenderingInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RenderingManager(osgViewer::Viewer& viewer, osg::ref_ptr<osg::Group> rootNode, Resource::ResourceSystem* resourceSystem);
|
RenderingManager(osgViewer::Viewer* viewer, osg::ref_ptr<osg::Group> rootNode, Resource::ResourceSystem* resourceSystem);
|
||||||
~RenderingManager();
|
~RenderingManager();
|
||||||
|
|
||||||
MWRender::Objects& getObjects();
|
MWRender::Objects& getObjects();
|
||||||
|
@ -99,8 +99,9 @@ namespace MWRender
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateProjectionMatrix();
|
void updateProjectionMatrix();
|
||||||
|
void updateTextureFiltering();
|
||||||
|
|
||||||
osgViewer::Viewer& mViewer;
|
osg::ref_ptr<osgViewer::Viewer> mViewer;
|
||||||
osg::ref_ptr<osg::Group> mRootNode;
|
osg::ref_ptr<osg::Group> mRootNode;
|
||||||
osg::ref_ptr<osg::Group> mLightRoot;
|
osg::ref_ptr<osg::Group> mLightRoot;
|
||||||
Resource::ResourceSystem* mResourceSystem;
|
Resource::ResourceSystem* mResourceSystem;
|
||||||
|
|
|
@ -143,7 +143,7 @@ namespace MWWorld
|
||||||
}
|
}
|
||||||
|
|
||||||
World::World (
|
World::World (
|
||||||
osgViewer::Viewer& viewer,
|
osgViewer::Viewer* viewer,
|
||||||
osg::ref_ptr<osg::Group> rootNode,
|
osg::ref_ptr<osg::Group> rootNode,
|
||||||
Resource::ResourceSystem* resourceSystem,
|
Resource::ResourceSystem* resourceSystem,
|
||||||
const Files::Collections& fileCollections,
|
const Files::Collections& fileCollections,
|
||||||
|
|
|
@ -162,7 +162,7 @@ namespace MWWorld
|
||||||
public:
|
public:
|
||||||
|
|
||||||
World (
|
World (
|
||||||
osgViewer::Viewer& viewer,
|
osgViewer::Viewer* viewer,
|
||||||
osg::ref_ptr<osg::Group> rootNode,
|
osg::ref_ptr<osg::Group> rootNode,
|
||||||
Resource::ResourceSystem* resourceSystem,
|
Resource::ResourceSystem* resourceSystem,
|
||||||
const Files::Collections& fileCollections,
|
const Files::Collections& fileCollections,
|
||||||
|
|
|
@ -36,6 +36,9 @@ namespace Resource
|
||||||
|
|
||||||
TextureManager::TextureManager(const VFS::Manager *vfs)
|
TextureManager::TextureManager(const VFS::Manager *vfs)
|
||||||
: mVFS(vfs)
|
: mVFS(vfs)
|
||||||
|
, mMinFilter(osg::Texture::LINEAR_MIPMAP_LINEAR)
|
||||||
|
, mMagFilter(osg::Texture::LINEAR)
|
||||||
|
, mMaxAnisotropy(1)
|
||||||
, mWarningTexture(createWarningTexture())
|
, mWarningTexture(createWarningTexture())
|
||||||
, mUnRefImageDataAfterApply(false)
|
, mUnRefImageDataAfterApply(false)
|
||||||
{
|
{
|
||||||
|
@ -52,6 +55,21 @@ namespace Resource
|
||||||
mUnRefImageDataAfterApply = unref;
|
mUnRefImageDataAfterApply = unref;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextureManager::setFilterSettings(osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter, int maxAnisotropy)
|
||||||
|
{
|
||||||
|
mMinFilter = minFilter;
|
||||||
|
mMagFilter = magFilter;
|
||||||
|
mMaxAnisotropy = std::max(1, maxAnisotropy);
|
||||||
|
|
||||||
|
for (std::map<MapKey, osg::ref_ptr<osg::Texture2D> >::iterator it = mTextures.begin(); it != mTextures.end(); ++it)
|
||||||
|
{
|
||||||
|
osg::ref_ptr<osg::Texture2D> tex = it->second;
|
||||||
|
tex->setFilter(osg::Texture::MIN_FILTER, mMinFilter);
|
||||||
|
tex->setFilter(osg::Texture::MAG_FILTER, mMagFilter);
|
||||||
|
tex->setMaxAnisotropy(static_cast<float>(mMaxAnisotropy));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
osg::ref_ptr<osg::Image> TextureManager::getImage(const std::string &filename)
|
osg::ref_ptr<osg::Image> TextureManager::getImage(const std::string &filename)
|
||||||
{
|
{
|
||||||
|
@ -110,6 +128,9 @@ namespace Resource
|
||||||
texture->setImage(image);
|
texture->setImage(image);
|
||||||
texture->setWrap(osg::Texture::WRAP_S, wrapS);
|
texture->setWrap(osg::Texture::WRAP_S, wrapS);
|
||||||
texture->setWrap(osg::Texture::WRAP_T, wrapT);
|
texture->setWrap(osg::Texture::WRAP_T, wrapT);
|
||||||
|
texture->setFilter(osg::Texture::MIN_FILTER, mMinFilter);
|
||||||
|
texture->setFilter(osg::Texture::MAG_FILTER, mMagFilter);
|
||||||
|
texture->setMaxAnisotropy(mMaxAnisotropy);
|
||||||
|
|
||||||
texture->setUnRefImageDataAfterApply(mUnRefImageDataAfterApply);
|
texture->setUnRefImageDataAfterApply(mUnRefImageDataAfterApply);
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,8 @@ namespace Resource
|
||||||
TextureManager(const VFS::Manager* vfs);
|
TextureManager(const VFS::Manager* vfs);
|
||||||
~TextureManager();
|
~TextureManager();
|
||||||
|
|
||||||
// TODO: texture filtering settings
|
/// @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);
|
||||||
|
|
||||||
/// 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.
|
||||||
|
@ -40,6 +41,10 @@ namespace Resource
|
||||||
private:
|
private:
|
||||||
const VFS::Manager* mVFS;
|
const VFS::Manager* mVFS;
|
||||||
|
|
||||||
|
osg::Texture::FilterMode mMinFilter;
|
||||||
|
osg::Texture::FilterMode mMagFilter;
|
||||||
|
int mMaxAnisotropy;
|
||||||
|
|
||||||
typedef std::pair<std::pair<int, int>, std::string> MapKey;
|
typedef std::pair<std::pair<int, int>, std::string> MapKey;
|
||||||
|
|
||||||
std::map<std::string, osg::observer_ptr<osg::Image> > mImages;
|
std::map<std::string, osg::observer_ptr<osg::Image> > mImages;
|
||||||
|
|
|
@ -322,7 +322,6 @@
|
||||||
<Widget type="ComboBox" skin="MW_ComboBox" position="14 28 110 24" align="Left Top" name="TextureFilteringButton">
|
<Widget type="ComboBox" skin="MW_ComboBox" position="14 28 110 24" align="Left Top" name="TextureFilteringButton">
|
||||||
<Property key="AddItem" value="Bilinear"/>
|
<Property key="AddItem" value="Bilinear"/>
|
||||||
<Property key="AddItem" value="Trilinear"/>
|
<Property key="AddItem" value="Trilinear"/>
|
||||||
<Property key="AddItem" value="Anisotropic"/>
|
|
||||||
</Widget>
|
</Widget>
|
||||||
<Widget type="Widget" skin="" position="184 4 300 50" align="Left Top" name="AnisotropyBox">
|
<Widget type="Widget" skin="" position="184 4 300 50" align="Left Top" name="AnisotropyBox">
|
||||||
<Widget type="TextBox" skin="SandText" position="0 0 300 24" align="Left Top" name="AnisotropyLabel">
|
<Widget type="TextBox" skin="SandText" position="0 0 300 24" align="Left Top" name="AnisotropyLabel">
|
||||||
|
|
|
@ -48,13 +48,10 @@ stretch menu background = false
|
||||||
field of view = 55
|
field of view = 55
|
||||||
|
|
||||||
# Texture filtering mode. valid values:
|
# Texture filtering mode. valid values:
|
||||||
# none
|
|
||||||
# anisotropic
|
|
||||||
# bilinear
|
# bilinear
|
||||||
# trilinear
|
# trilinear
|
||||||
texture filtering = anisotropic
|
texture filtering =
|
||||||
|
|
||||||
# Has no effect when texture filtering is not anisotropic
|
|
||||||
anisotropy = 4
|
anisotropy = 4
|
||||||
|
|
||||||
# Number of texture mipmaps to generate
|
# Number of texture mipmaps to generate
|
||||||
|
|
Loading…
Reference in a new issue