From ed6f36020e9388de546fca3a7ea791b195f24664 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Tue, 12 Nov 2024 20:47:18 -0500 Subject: [PATCH] silly --- CMakeLists.txt | 2 +- include/blt/gfx/renderer/font_renderer.h | 22 ++++++++++++++++++---- src/blt/gfx/renderer/font_renderer.cpp | 8 +++++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d3c35e6..21978ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.25) include(FetchContent) -set(BLT_GRAPHICS_VERSION 1.0.9) +set(BLT_GRAPHICS_VERSION 1.0.10) set(BLT_GRAPHICS_TEST_VERSION 0.0.1) project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION}) diff --git a/include/blt/gfx/renderer/font_renderer.h b/include/blt/gfx/renderer/font_renderer.h index d81f42a..6935868 100644 --- a/include/blt/gfx/renderer/font_renderer.h +++ b/include/blt/gfx/renderer/font_renderer.h @@ -69,15 +69,25 @@ namespace blt::gfx class font_generator_t { public: + + struct size_bounds_t + { + float min_size, max_size; + blt::u64 min_char, max_char; + }; + struct bounded_font_t { std::unique_ptr atlas; - float min_size, max_size; - blt::u64 min_char, max_char; +// float min_size, max_size; +// blt::u64 min_char, max_char; + std::vector size_limits; - bounded_font_t(std::unique_ptr atlas, float minSize, float maxSize, u64 minChar, u64 maxChar): - atlas(std::move(atlas)), min_size(minSize), max_size(maxSize), min_char(minChar), max_char(maxChar) + explicit bounded_font_t(std::unique_ptr atlas): atlas(std::move(atlas)) {} +// bounded_font_t(std::unique_ptr atlas, float minSize, float maxSize, u64 minChar, u64 maxChar): +// atlas(std::move(atlas)), min_size(minSize), max_size(maxSize), min_char(minChar), max_char(maxChar) +// {} }; public: @@ -89,6 +99,7 @@ namespace blt::gfx { for (auto& atlas : atlases) { + BLT_TRACE("(%f %ld), %f %f, %ld %ld", size, c, atlas.min_size, atlas.max_size, atlas.min_char, atlas.max_char); if (!(size >= atlas.min_size && size <= atlas.max_size)) continue; if (c >= atlas.min_char && c <= atlas.max_char) @@ -188,18 +199,21 @@ namespace blt::gfx }; font_generator_t& generator; + std::string contents; vertex_array_t vao{}; std::vector renders; blt::vec2f position; blt::vec2f scale = {1, 1}; blt::vec4 color = blt::make_color(1, 1, 1); float z_index = 0; + float current_size = 0; }; public: explicit font_renderer_t(); void create_default(blt::i32 dimensions = 0); + void create(const std::vector& generated_font_sizes, blt::i32 dimensions = 0); void cleanup(); diff --git a/src/blt/gfx/renderer/font_renderer.cpp b/src/blt/gfx/renderer/font_renderer.cpp index d71bd50..f03d0c9 100644 --- a/src/blt/gfx/renderer/font_renderer.cpp +++ b/src/blt/gfx/renderer/font_renderer.cpp @@ -220,7 +220,7 @@ namespace blt::gfx void font_renderer_t::create_default(blt::i32 dimensions) { - create({9, 11, 12, 13, 14, 16, 18, 24, 32, 36, 40, 48, 52, 64, 72, 96, 106}, dimensions); + create({9, 11, 12, 13, 14, 16, 18, 24, 32, 36, 40, 48, 52, 64, 72, 96, 106, 250}, dimensions); add_default_font(reinterpret_cast(font::default_font_compressed_data), font::default_font_compressed_size, true); } @@ -241,6 +241,10 @@ namespace blt::gfx void font_renderer_t::compiled_text_t::change_text(std::string_view str, float size) { + if (str == contents) + return; + contents = str; + current_size = size; static std::vector vertices; vertices.clear(); renders.clear(); @@ -325,4 +329,6 @@ namespace blt::gfx glDrawArrays(GL_TRIANGLES, static_cast(render.render_start), static_cast(render.render_count)); } } + + } \ No newline at end of file