From 902e5cddf76e941af8bd506cef34176d080184e6 Mon Sep 17 00:00:00 2001 From: EmptyChaos Date: Thu, 24 Mar 2016 02:23:56 +0000 Subject: VideoBackends: Do not use Anisotropy on Point filtered textures. The D3D backend was always forcing Anisotropic filtering when that is enabled regardless of how the game chose to configure the texture filtering registers; this causes the same issues as "Force Filtering" without Anisotropy, such as causing game UI elements to no longer line up adjacent correctly. Historically, OpenGL's Anisotropy support has always worked "better" than D3D's due to seeming to not have this problem; unfortunately, OpenGL's Anisotropy specification only gives GL_LINEAR based filtering modes defined behavior, with only the mipmap setting being required to be considered. Some OpenGL implementations were implicitly disabling Anisotropy when the min/mag filters were set to GL_NEAREST, but this behavior is not required by the spec so cannot be relied on. --- Source/Core/VideoBackends/OGL/SamplerCache.cpp | 28 ++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/SamplerCache.cpp') diff --git a/Source/Core/VideoBackends/OGL/SamplerCache.cpp b/Source/Core/VideoBackends/OGL/SamplerCache.cpp index 0eeae5ee38..5f809825d5 100644 --- a/Source/Core/VideoBackends/OGL/SamplerCache.cpp +++ b/Source/Core/VideoBackends/OGL/SamplerCache.cpp @@ -8,6 +8,7 @@ #include "Common/CommonTypes.h" #include "Common/GL/GLInterfaceBase.h" #include "VideoBackends/OGL/SamplerCache.h" +#include "VideoCommon/SamplerCommon.h" #include "VideoCommon/VideoConfig.h" namespace OGL @@ -59,8 +60,8 @@ void SamplerCache::SetSamplerState(int stage, const TexMode0& tm0, const TexMode // take equivalent forced linear when bForceFiltering if (g_ActiveConfig.bForceFiltering) { - params.tm0.min_filter |= 0x4; - params.tm0.mag_filter |= 0x1; + params.tm0.min_filter = (tm0.min_filter & 3) == TexMode0::TEXF_NONE ? 4 : 6; + params.tm0.mag_filter = 1; } // custom textures may have higher resolution, so disable the max_lod @@ -122,9 +123,6 @@ void SamplerCache::SetParameters(GLuint sampler_id, const Params& params) auto& tm0 = params.tm0; auto& tm1 = params.tm1; - glSamplerParameteri(sampler_id, GL_TEXTURE_MIN_FILTER, min_filters[tm0.min_filter % ArraySize(min_filters)]); - glSamplerParameteri(sampler_id, GL_TEXTURE_MAG_FILTER, tm0.mag_filter ? GL_LINEAR : GL_NEAREST); - glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_S, wrap_settings[tm0.wrap_s]); glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_T, wrap_settings[tm0.wrap_t]); @@ -134,8 +132,26 @@ void SamplerCache::SetParameters(GLuint sampler_id, const Params& params) if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL) glSamplerParameterf(sampler_id, GL_TEXTURE_LOD_BIAS, (s32)tm0.lod_bias / 32.f); - if (g_ActiveConfig.iMaxAnisotropy > 0 && g_ogl_config.bSupportsAniso) + GLint min_filter = min_filters[tm0.min_filter]; + GLint mag_filter = tm0.mag_filter ? GL_LINEAR : GL_NEAREST; + + if (g_ActiveConfig.iMaxAnisotropy > 0 && g_ogl_config.bSupportsAniso && + !IsBpTexMode0PointFiltering(tm0)) + { + // https://www.opengl.org/registry/specs/EXT/texture_filter_anisotropic.txt + // For predictable results on all hardware/drivers, only use one of: + // GL_LINEAR + GL_LINEAR (No Mipmaps [Bilinear]) + // GL_LINEAR + GL_LINEAR_MIPMAP_LINEAR (w/ Mipmaps [Trilinear]) + // Letting the game set other combinations will have varying arbitrary results; + // possibly being interpreted as equal to bilinear/trilinear, implicitly + // disabling anisotropy, or changing the anisotropic algorithm employed. + min_filter = (tm0.min_filter & 3) == TexMode0::TEXF_NONE ? GL_LINEAR : GL_LINEAR_MIPMAP_LINEAR; + mag_filter = GL_LINEAR; glSamplerParameterf(sampler_id, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)(1 << g_ActiveConfig.iMaxAnisotropy)); + } + + glSamplerParameteri(sampler_id, GL_TEXTURE_MIN_FILTER, min_filter); + glSamplerParameteri(sampler_id, GL_TEXTURE_MAG_FILTER, mag_filter); } void SamplerCache::Clear() -- cgit v1.2.3 From 0b9a72a62d38481ff08f742b2318d07f29ff5dff Mon Sep 17 00:00:00 2001 From: EmptyChaos Date: Thu, 24 Mar 2016 02:42:08 +0000 Subject: VideoCommon: Refactor TexMode0 mipmaps disabled test into a helper function --- Source/Core/VideoBackends/OGL/SamplerCache.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/SamplerCache.cpp') diff --git a/Source/Core/VideoBackends/OGL/SamplerCache.cpp b/Source/Core/VideoBackends/OGL/SamplerCache.cpp index 5f809825d5..d9a2008a50 100644 --- a/Source/Core/VideoBackends/OGL/SamplerCache.cpp +++ b/Source/Core/VideoBackends/OGL/SamplerCache.cpp @@ -60,7 +60,7 @@ void SamplerCache::SetSamplerState(int stage, const TexMode0& tm0, const TexMode // take equivalent forced linear when bForceFiltering if (g_ActiveConfig.bForceFiltering) { - params.tm0.min_filter = (tm0.min_filter & 3) == TexMode0::TEXF_NONE ? 4 : 6; + params.tm0.min_filter = SamplerCommon::AreBpTexMode0MipmapsEnabled(tm0) ? 6 : 4; params.tm0.mag_filter = 1; } @@ -136,7 +136,7 @@ void SamplerCache::SetParameters(GLuint sampler_id, const Params& params) GLint mag_filter = tm0.mag_filter ? GL_LINEAR : GL_NEAREST; if (g_ActiveConfig.iMaxAnisotropy > 0 && g_ogl_config.bSupportsAniso && - !IsBpTexMode0PointFiltering(tm0)) + !SamplerCommon::IsBpTexMode0PointFiltering(tm0)) { // https://www.opengl.org/registry/specs/EXT/texture_filter_anisotropic.txt // For predictable results on all hardware/drivers, only use one of: @@ -145,7 +145,7 @@ void SamplerCache::SetParameters(GLuint sampler_id, const Params& params) // Letting the game set other combinations will have varying arbitrary results; // possibly being interpreted as equal to bilinear/trilinear, implicitly // disabling anisotropy, or changing the anisotropic algorithm employed. - min_filter = (tm0.min_filter & 3) == TexMode0::TEXF_NONE ? GL_LINEAR : GL_LINEAR_MIPMAP_LINEAR; + min_filter = SamplerCommon::AreBpTexMode0MipmapsEnabled(tm0) ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR; mag_filter = GL_LINEAR; glSamplerParameterf(sampler_id, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)(1 << g_ActiveConfig.iMaxAnisotropy)); } -- cgit v1.2.3