From 7f9a3973eb4bbba60fd831d2d5f79a167673b32b Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Thu, 7 May 2015 15:40:34 +0600 Subject: [PATCH] Do not use textureLod for fetching normal textures. It kills anisotropic filtering: https://www.opengl.org/wiki/Sampler_(GLSL) Also need to keep in mind issue #232 and not allow mip-mapping for combiners, which do not use it. Fixed anisotropic filtering not working #505 --- src/Shaders.h | 8 ++------ src/Textures.cpp | 12 +++++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Shaders.h b/src/Shaders.h index 0e358d5b..12b22922 100644 --- a/src/Shaders.h +++ b/src/Shaders.h @@ -453,14 +453,10 @@ static const char* fragment_shader_readtex = SHADER_VERSION #endif "uniform lowp int uTextureFilterMode; \n" -"lowp vec4 filterNearest(in sampler2D tex, in mediump vec2 texCoord)\n" -"{ \n" -" return textureLod(tex, texCoord, 0.0); \n" -"} \n" // 3 point texture filtering. // Original author: ArthurCarvalho // GLSL implementation: twinaphex, mupen64plus-libretro project. -"#define TEX_OFFSET(off) textureLod(tex, texCoord - (off)/texSize, 0.0) \n" +"#define TEX_OFFSET(off) texture(tex, texCoord - (off)/texSize) \n" "lowp vec4 filter3point(in sampler2D tex, in mediump vec2 texCoord) \n" "{ \n" " mediump vec2 texSize = vec2(textureSize(tex,0)); \n" @@ -473,7 +469,7 @@ SHADER_VERSION "} \n" "lowp vec4 readTex(in sampler2D tex, in mediump vec2 texCoord, in bool fb8bit, in bool fbFixedAlpha) \n" "{ \n" -" lowp vec4 texColor = uTextureFilterMode == 0 ? filterNearest(tex, texCoord) : filter3point(tex, texCoord); \n" +" lowp vec4 texColor = uTextureFilterMode == 0 ? texture(tex, texCoord) : filter3point(tex, texCoord); \n" " if (fb8bit) texColor = vec4(texColor.r); \n" " if (fbFixedAlpha) texColor.a = 0.825; \n" " return texColor; \n" diff --git a/src/Textures.cpp b/src/Textures.cpp index a713a084..e8950456 100644 --- a/src/Textures.cpp +++ b/src/Textures.cpp @@ -1086,24 +1086,26 @@ void TextureCache::activateTexture(u32 _t, CachedTexture *_pTexture) } const bool bUseBilinear = (gDP.otherMode.textureFilter | (gSP.objRendermode&G_OBJRM_BILERP)) != 0; + const bool bUseLOD = currentCombiner()->usesLOD(); + const GLint texLevel = bUseLOD ? _pTexture->max_level : 0; - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, _pTexture->max_level); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texLevel); if (config.texture.bilinearMode == BILINEAR_STANDARD) { if (bUseBilinear) { - if (_pTexture->max_level > 0) + if (texLevel > 0) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); else glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } else { - if (_pTexture->max_level > 0) + if (texLevel > 0) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); else glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); } } else { // 3 point filter - if (_pTexture->max_level > 0) { // Apply standard bilinear to mipmap textures + if (texLevel > 0) { // Apply standard bilinear to mipmap textures if (bUseBilinear) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -1111,7 +1113,7 @@ void TextureCache::activateTexture(u32 _t, CachedTexture *_pTexture) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); } - } else if (bUseBilinear && config.generalEmulation.enableLOD != 0 && currentCombiner()->usesLOD()) { // Apply standard bilinear to first tile of mipmap texture + } else if (bUseBilinear && config.generalEmulation.enableLOD != 0 && bUseLOD) { // Apply standard bilinear to first tile of mipmap texture glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } else { // Don't use texture filter. Texture will be filtered by 3 point filter shader