From b079421205c316d04b9813ce87b81f4c2529bb22 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 5 Sep 2022 22:36:33 +0200 Subject: [PATCH] Changed it so that only fonts of a certain minimum size gets linear texture magnification applied. --- es-core/src/resources/Font.cpp | 11 ++++++----- es-core/src/resources/Font.h | 4 +++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/es-core/src/resources/Font.cpp b/es-core/src/resources/Font.cpp index 9477473ce..1cfaecff9 100644 --- a/es-core/src/resources/Font.cpp +++ b/es-core/src/resources/Font.cpp @@ -587,11 +587,12 @@ bool Font::FontTexture::findEmpty(const glm::ivec2& size, glm::ivec2& cursor_out return true; } -void Font::FontTexture::initTexture() +void Font::FontTexture::initTexture(bool linearMagnification) { assert(textureId == 0); - textureId = Renderer::getInstance()->createTexture( - Renderer::TextureType::RED, true, true, false, textureSize.x, textureSize.y, nullptr); + textureId = Renderer::getInstance()->createTexture(Renderer::TextureType::RED, true, + linearMagnification, false, false, + textureSize.x, textureSize.y, nullptr); } void Font::FontTexture::deinitTexture() @@ -623,7 +624,7 @@ void Font::rebuildTextures() { // Recreate OpenGL textures. for (auto it = mTextures.begin(); it != mTextures.end(); ++it) - it->initTexture(); + it->initTexture(mSize > MIN_SIZE_LINEAR_MAGNIFICATION); // Re-upload the texture data. for (auto it = mGlyphMap.cbegin(); it != mGlyphMap.cend(); ++it) { @@ -678,7 +679,7 @@ void Font::getTextureForNewGlyph(const glm::ivec2& glyphSize, mTextures.push_back(FontTexture(mSize)); tex_out = &mTextures.back(); - tex_out->initTexture(); + tex_out->initTexture(mSize > MIN_SIZE_LINEAR_MAGNIFICATION); bool ok = tex_out->findEmpty(glyphSize, cursor_out); if (!ok) { diff --git a/es-core/src/resources/Font.h b/es-core/src/resources/Font.h index d7b54dc7f..1a67181f9 100644 --- a/es-core/src/resources/Font.h +++ b/es-core/src/resources/Font.h @@ -31,6 +31,8 @@ class TextCache; std::min(Renderer::getScreenHeight(), Renderer::getScreenWidth()))) // clang-format on +#define MIN_SIZE_LINEAR_MAGNIFICATION 30 + #define FONT_PATH_LIGHT ":/fonts/Akrobat-Regular.ttf" #define FONT_PATH_REGULAR ":/fonts/Akrobat-SemiBold.ttf" #define FONT_PATH_BOLD ":/fonts/Akrobat-Bold.ttf" @@ -131,7 +133,7 @@ private: // You must call initTexture() after creating a FontTexture to get a textureId. // Initializes the OpenGL texture according to this FontTexture's settings, // updating textureId. - void initTexture(); + void initTexture(bool linearMagnification); // Deinitializes the OpenGL texture if any exists, is automatically called // in the destructor.