From e5cc4d4f87aa419a8befa3768d96323c9ea8dac4 Mon Sep 17 00:00:00 2001 From: clayjohn Date: Sun, 19 Jul 2020 14:44:42 -0700 Subject: [PATCH] Allow nearest neighbor lookup when using mipmaps --- drivers/gles2/rasterizer_storage_gles2.cpp | 12 ++++++++++-- drivers/gles3/rasterizer_storage_gles3.cpp | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp index ec043e94450..c0edbed780b 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/gles2/rasterizer_storage_gles2.cpp @@ -711,7 +711,11 @@ void RasterizerStorageGLES2::texture_set_data(RID p_texture, const Ref &p texture->ignore_mipmaps = compressed && !img->has_mipmaps(); if ((texture->flags & VS::TEXTURE_FLAG_MIPMAPS) && !texture->ignore_mipmaps) - glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, config.use_fast_texture_filter ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR_MIPMAP_LINEAR); + if (texture->flags & VS::TEXTURE_FLAG_FILTER) { + glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, config.use_fast_texture_filter ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR_MIPMAP_LINEAR); + } else { + glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, config.use_fast_texture_filter ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST_MIPMAP_LINEAR); + } else { if (texture->flags & VS::TEXTURE_FLAG_FILTER) { glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -957,7 +961,11 @@ void RasterizerStorageGLES2::texture_set_flags(RID p_texture, uint32_t p_flags) if (!had_mipmaps && texture->mipmaps == 1) { glGenerateMipmap(texture->target); } - glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, config.use_fast_texture_filter ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR_MIPMAP_LINEAR); + if (texture->flags & VS::TEXTURE_FLAG_FILTER) { + glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, config.use_fast_texture_filter ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR_MIPMAP_LINEAR); + } else { + glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, config.use_fast_texture_filter ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST_MIPMAP_LINEAR); + } } else { if (texture->flags & VS::TEXTURE_FLAG_FILTER) { diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index 5ff8028eed0..6f76dd013f8 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -841,7 +841,11 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Ref &p texture->ignore_mipmaps = compressed && !img->has_mipmaps(); if ((texture->flags & VS::TEXTURE_FLAG_MIPMAPS) && !texture->ignore_mipmaps) - glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, config.use_fast_texture_filter ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR_MIPMAP_LINEAR); + if (texture->flags & VS::TEXTURE_FLAG_FILTER) { + glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, config.use_fast_texture_filter ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR_MIPMAP_LINEAR); + } else { + glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, config.use_fast_texture_filter ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST_MIPMAP_LINEAR); + } else { if (texture->flags & VS::TEXTURE_FLAG_FILTER) { glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -1420,7 +1424,11 @@ void RasterizerStorageGLES3::texture_set_flags(RID p_texture, uint32_t p_flags) if (!had_mipmaps && texture->mipmaps == 1) { glGenerateMipmap(texture->target); } - glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, config.use_fast_texture_filter ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR_MIPMAP_LINEAR); + if (texture->flags & VS::TEXTURE_FLAG_FILTER) { + glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, config.use_fast_texture_filter ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR_MIPMAP_LINEAR); + } else { + glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, config.use_fast_texture_filter ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST_MIPMAP_LINEAR); + } } else { if (texture->flags & VS::TEXTURE_FLAG_FILTER) {