Apply texture filter setting changes

c++11
scrawl 10 years ago
parent 5442bf23a6
commit 24bb2e152c

@ -419,6 +419,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_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
// 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
mEnvironment.setWorld( new MWWorld::World (*mViewer, rootNode, mResourceSystem.get(),
mEnvironment.setWorld( new MWWorld::World (mViewer, rootNode, mResourceSystem.get(),
mFileCollections, mContentFiles, mEncoder, mFallbackMap,
mActivationDistanceOverride, mCellName, mStartupScript));
MWBase::Environment::get().getWorld()->setupPlayer();

@ -38,12 +38,10 @@ namespace
std::string textureFilteringToStr(const std::string& val)
{
if (val == "anisotropic")
return "Anisotropic";
else if (val == "bilinear")
return "Bilinear";
else
if (val == "trilinear")
return "Trilinear";
else
return "Bilinear";
}
void parseResolution (int &x, int &y, const std::string& str)

@ -14,6 +14,7 @@
#include <osgViewer/Viewer>
#include <components/resource/resourcesystem.hpp>
#include <components/resource/texturemanager.hpp>
#include <components/settings/settings.hpp>
@ -82,7 +83,7 @@ namespace MWRender
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)
, mRootNode(rootNode)
, mResourceSystem(resourceSystem)
@ -97,13 +98,13 @@ namespace MWRender
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));
mViewer.setLightingMode(osgViewer::View::NO_LIGHT);
mViewer->setLightingMode(osgViewer::View::NO_LIGHT);
osg::ref_ptr<osg::LightSource> source = new osg::LightSource;
mSunLight = new osg::Light;
@ -133,10 +134,10 @@ namespace MWRender
else
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()->setCullingMode(cullingMode);
mViewer->getCamera()->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
mViewer->getCamera()->setCullingMode(cullingMode);
mViewDistance = Settings::Manager::getFloat("viewing distance", "Viewing distance");
mFieldOfView = Settings::Manager::getFloat("field of view", "General");
@ -184,7 +185,7 @@ namespace MWRender
osg::Vec3f RenderingManager::getEyePos()
{
osg::Vec3d eye = mViewer.getCameraManipulator()->getMatrix().getTrans();
osg::Vec3d eye = mViewer->getCameraManipulator()->getMatrix().getTrans();
return eye;
}
@ -232,7 +233,7 @@ namespace MWRender
void RenderingManager::configureFog(float /* fogDepth */, const osg::Vec4f &colour)
{
mViewer.getCamera()->setClearColor(colour);
mViewer->getCamera()->setClearColor(colour);
mStateUpdater->setFogColor(colour);
mStateUpdater->setFogEnd(mViewDistance);
@ -325,11 +326,26 @@ namespace MWRender
void RenderingManager::updateProjectionMatrix()
{
double fovy, aspect, zNear, zFar;
mViewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspect, zNear, zFar);
mViewer->getCamera()->getProjectionMatrixAsPerspective(fovy, aspect, zNear, zFar);
fovy = mFieldOfView;
zNear = 5.f;
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)
@ -346,6 +362,8 @@ namespace MWRender
mViewDistance = Settings::Manager::getFloat("viewing distance", "Viewing distance");
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
{
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();
MWRender::Objects& getObjects();
@ -99,8 +99,9 @@ namespace MWRender
private:
void updateProjectionMatrix();
void updateTextureFiltering();
osgViewer::Viewer& mViewer;
osg::ref_ptr<osgViewer::Viewer> mViewer;
osg::ref_ptr<osg::Group> mRootNode;
osg::ref_ptr<osg::Group> mLightRoot;
Resource::ResourceSystem* mResourceSystem;

@ -143,7 +143,7 @@ namespace MWWorld
}
World::World (
osgViewer::Viewer& viewer,
osgViewer::Viewer* viewer,
osg::ref_ptr<osg::Group> rootNode,
Resource::ResourceSystem* resourceSystem,
const Files::Collections& fileCollections,

@ -162,7 +162,7 @@ namespace MWWorld
public:
World (
osgViewer::Viewer& viewer,
osgViewer::Viewer* viewer,
osg::ref_ptr<osg::Group> rootNode,
Resource::ResourceSystem* resourceSystem,
const Files::Collections& fileCollections,

@ -36,6 +36,9 @@ namespace Resource
TextureManager::TextureManager(const VFS::Manager *vfs)
: mVFS(vfs)
, mMinFilter(osg::Texture::LINEAR_MIPMAP_LINEAR)
, mMagFilter(osg::Texture::LINEAR)
, mMaxAnisotropy(1)
, mWarningTexture(createWarningTexture())
, mUnRefImageDataAfterApply(false)
{
@ -52,6 +55,21 @@ namespace Resource
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)
{
@ -110,6 +128,9 @@ namespace Resource
texture->setImage(image);
texture->setWrap(osg::Texture::WRAP_S, wrapS);
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);

@ -23,7 +23,8 @@ namespace Resource
TextureManager(const VFS::Manager* vfs);
~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,
/// otherwise should be disabled to reduce memory usage.
@ -40,6 +41,10 @@ namespace Resource
private:
const VFS::Manager* mVFS;
osg::Texture::FilterMode mMinFilter;
osg::Texture::FilterMode mMagFilter;
int mMaxAnisotropy;
typedef std::pair<std::pair<int, int>, std::string> MapKey;
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">
<Property key="AddItem" value="Bilinear"/>
<Property key="AddItem" value="Trilinear"/>
<Property key="AddItem" value="Anisotropic"/>
</Widget>
<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">

@ -48,13 +48,10 @@ stretch menu background = false
field of view = 55
# Texture filtering mode. valid values:
# none
# anisotropic
# bilinear
# trilinear
texture filtering = anisotropic
texture filtering =
# Has no effect when texture filtering is not anisotropic
anisotropy = 4
# Number of texture mipmaps to generate

Loading…
Cancel
Save