From 5cf965b9a1cb20705908f2bb0dfee0dae9448e18 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Thu, 31 Oct 2024 12:36:44 +0100 Subject: [PATCH] yes --- runtime/Sources/Graphics/Font.cpp | 18 +++++++++++------- runtime/Sources/Graphics/Text.cpp | 5 +---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/runtime/Sources/Graphics/Font.cpp b/runtime/Sources/Graphics/Font.cpp index 9875a72..b0b0a3d 100644 --- a/runtime/Sources/Graphics/Font.cpp +++ b/runtime/Sources/Graphics/Font.cpp @@ -3,6 +3,10 @@ #include #include +#define STBRP_ASSERT(x) mlx::Assert(x, "internal stb assertion") +#define STB_RECT_PACK_IMPLEMENTATION +#include + #define STB_TRUETYPE_IMPLEMENTATION #define STB_malloc(x, u) ((void)(u), MemManager::Get().Malloc(x)) #define STB_free(x, u) ((void)(u), MemManager::Get().Free(x)) @@ -29,24 +33,24 @@ namespace mlx file.close(); } - CPUBuffer tmp_bitmap(RANGE * RANGE); + CPUBuffer bitmap(RANGE * RANGE); stbtt_pack_context pc; - stbtt_PackBegin(&pc, tmp_bitmap.GetData(), RANGE, RANGE, RANGE, 1, nullptr); + stbtt_PackBegin(&pc, bitmap.GetData(), RANGE, RANGE, RANGE, 1, nullptr); if(std::holds_alternative(m_build_data)) stbtt_PackFontRange(&pc, file_bytes.data(), 0, m_scale, 32, 96, m_cdata.data()); else stbtt_PackFontRange(&pc, std::get>(m_build_data).data(), 0, m_scale, 32, 96, m_cdata.data()); stbtt_PackEnd(&pc); + // TODO : find better solution CPUBuffer vulkan_bitmap(RANGE * RANGE * 4); - for(int i = 0, j = 0; i < RANGE * RANGE; i++, j += 4) { - vulkan_bitmap.GetData()[j + 0] = tmp_bitmap.GetData()[i]; - vulkan_bitmap.GetData()[j + 1] = tmp_bitmap.GetData()[i]; - vulkan_bitmap.GetData()[j + 2] = tmp_bitmap.GetData()[i]; - vulkan_bitmap.GetData()[j + 3] = tmp_bitmap.GetData()[i]; + vulkan_bitmap.GetData()[j + 0] = bitmap.GetData()[i]; + vulkan_bitmap.GetData()[j + 1] = bitmap.GetData()[i]; + vulkan_bitmap.GetData()[j + 2] = bitmap.GetData()[i]; + vulkan_bitmap.GetData()[j + 3] = bitmap.GetData()[i]; } #ifdef DEBUG diff --git a/runtime/Sources/Graphics/Text.cpp b/runtime/Sources/Graphics/Text.cpp index d0deaf0..da0325c 100644 --- a/runtime/Sources/Graphics/Text.cpp +++ b/runtime/Sources/Graphics/Text.cpp @@ -2,9 +2,6 @@ #include -#define STB_RECT_PACK_IMPLEMENTATION -#include - namespace mlx { Text::Text(const std::string& text, std::shared_ptr font) : Drawable(DrawableType::Text) @@ -19,7 +16,7 @@ namespace mlx float stb_x = 0.0f; float stb_y = 0.0f; - auto char_data = font->GetCharData(); + const auto& char_data = font->GetCharData(); for(char c : text) { if(c < 32)