From 0a8ea7e597fac904ed7fd8da4d9370a9f0711e7a Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 13 Nov 2024 12:00:55 +0300 Subject: [PATCH] disable mip-mapping in fonts --- src/assets/assetload_funcs.cpp | 4 +++- src/graphics/core/GLTexture.cpp | 16 +++++++++++++++- src/graphics/core/GLTexture.hpp | 2 ++ src/graphics/core/Texture.hpp | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/assets/assetload_funcs.cpp b/src/assets/assetload_funcs.cpp index ed4f076fb..b73a3882e 100644 --- a/src/assets/assetload_funcs.cpp +++ b/src/assets/assetload_funcs.cpp @@ -151,7 +151,9 @@ assetload::postfunc assetload::font( if (page == nullptr) { textures.emplace_back(nullptr); } else { - textures.emplace_back(Texture::from(page.get())); + auto texture = Texture::from(page.get()); + texture->setMipMapping(false); + textures.emplace_back(std::move(texture)); } } assets->store( diff --git a/src/graphics/core/GLTexture.cpp b/src/graphics/core/GLTexture.cpp index 4781536ef..3756d7580 100644 --- a/src/graphics/core/GLTexture.cpp +++ b/src/graphics/core/GLTexture.cpp @@ -59,7 +59,9 @@ std::unique_ptr GLTexture::readData() { glBindTexture(GL_TEXTURE_2D, id); glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data.get()); glBindTexture(GL_TEXTURE_2D, 0); - return std::make_unique(ImageFormat::rgba8888, width, height, data.release()); + return std::make_unique( + ImageFormat::rgba8888, width, height, data.release() + ); } void GLTexture::setNearestFilter() { @@ -69,6 +71,18 @@ void GLTexture::setNearestFilter() { glBindTexture(GL_TEXTURE_2D, 0); } +void GLTexture::setMipMapping(bool flag) { + bind(); + if (flag) { + glTexParameteri( + GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST + ); + } else { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + } + glBindTexture(GL_TEXTURE_2D, 0); +} + std::unique_ptr GLTexture::from(const ImageData* image) { uint width = image->getWidth(); uint height = image->getHeight(); diff --git a/src/graphics/core/GLTexture.hpp b/src/graphics/core/GLTexture.hpp index b5f82384b..85d7f85dc 100644 --- a/src/graphics/core/GLTexture.hpp +++ b/src/graphics/core/GLTexture.hpp @@ -18,6 +18,8 @@ class GLTexture : public Texture { virtual void reload(const ImageData& image) override; + virtual void setMipMapping(bool flag) override; + virtual std::unique_ptr readData() override; virtual uint getId() const override; diff --git a/src/graphics/core/Texture.hpp b/src/graphics/core/Texture.hpp index ba5b066e3..bc7b73f0a 100644 --- a/src/graphics/core/Texture.hpp +++ b/src/graphics/core/Texture.hpp @@ -34,5 +34,7 @@ class Texture { virtual uint getId() const = 0; + virtual void setMipMapping(bool flag) = 0; + static std::unique_ptr from(const ImageData* image); };