fixing allocation issues with texts

This commit is contained in:
2024-01-18 13:57:41 +01:00
parent 208b0e4710
commit dd0599c088
28 changed files with 303 additions and 134 deletions

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/11 22:06:09 by kbz_8 #+# #+# */
/* Updated: 2024/01/16 09:11:26 by maldavid ### ########.fr */
/* Updated: 2024/01/18 13:16:18 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,51 +19,43 @@ constexpr const int RANGE = 1024;
namespace mlx
{
Font::Font(Renderer& renderer, const std::filesystem::path& path, float scale) : _name(path.string()), _scale(scale)
Font::Font(Renderer& renderer, const std::filesystem::path& path, float scale) : _name(path.string()), _renderer(renderer), _scale(scale)
{
MLX_PROFILE_FUNCTION();
std::vector<uint8_t> tmp_bitmap(RANGE * RANGE);
std::vector<uint8_t> vulkan_bitmap(RANGE * RANGE * 4);
std::ifstream file(path, std::ios::binary);
if(!file.is_open())
{
core::error::report(e_kind::error, "Font load : cannot open font file, %s", _name.c_str());
return;
}
std::ifstream::pos_type fileSize = std::filesystem::file_size(path);
file.seekg(0, std::ios::beg);
std::vector<uint8_t> bytes(fileSize);
file.read(reinterpret_cast<char*>(bytes.data()), fileSize);
file.close();
stbtt_pack_context pc;
stbtt_PackBegin(&pc, tmp_bitmap.data(), RANGE, RANGE, RANGE, 1, nullptr);
stbtt_PackFontRange(&pc, bytes.data(), 0, scale, 32, 96, _cdata.data());
stbtt_PackEnd(&pc);
for(int i = 0, j = 0; i < RANGE * RANGE; i++, j += 4)
{
vulkan_bitmap[j + 0] = tmp_bitmap[i];
vulkan_bitmap[j + 1] = tmp_bitmap[i];
vulkan_bitmap[j + 2] = tmp_bitmap[i];
vulkan_bitmap[j + 3] = tmp_bitmap[i];
}
#ifdef DEBUG
_atlas.create(vulkan_bitmap.data(), RANGE, RANGE, VK_FORMAT_R8G8B8A8_UNORM, std::string(_name + "_font_altas").c_str(), true);
#else
_atlas.create(vulkan_bitmap.data(), RANGE, RANGE, VK_FORMAT_R8G8B8A8_UNORM, nullptr, true);
#endif
_atlas.setDescriptor(renderer.getFragDescriptorSet().duplicate());
_build_data = path;
}
Font::Font(class Renderer& renderer, const std::string& name, const std::vector<uint8_t>& ttf_data, float scale) : _name(name), _scale(scale)
Font::Font(class Renderer& renderer, const std::string& name, const std::vector<uint8_t>& ttf_data, float scale) : _name(name), _renderer(renderer), _scale(scale)
{
_build_data = ttf_data;
}
void Font::buildFont()
{
MLX_PROFILE_FUNCTION();
std::vector<uint8_t> file_bytes;
if(std::holds_alternative<std::filesystem::path>(_build_data))
{
std::ifstream file(std::get<std::filesystem::path>(_build_data), std::ios::binary);
if(!file.is_open())
{
core::error::report(e_kind::error, "Font load : cannot open font file, %s", _name.c_str());
return;
}
std::ifstream::pos_type fileSize = std::filesystem::file_size(std::get<std::filesystem::path>(_build_data));
file.seekg(0, std::ios::beg);
file_bytes.resize(fileSize);
file.read(reinterpret_cast<char*>(file_bytes.data()), fileSize);
file.close();
}
std::vector<uint8_t> tmp_bitmap(RANGE * RANGE);
std::vector<uint8_t> vulkan_bitmap(RANGE * RANGE * 4);
stbtt_pack_context pc;
stbtt_PackBegin(&pc, tmp_bitmap.data(), RANGE, RANGE, RANGE, 1, nullptr);
stbtt_PackFontRange(&pc, ttf_data.data(), 0, scale, 32, 96, _cdata.data());
if(std::holds_alternative<std::filesystem::path>(_build_data))
stbtt_PackFontRange(&pc, file_bytes.data(), 0, _scale, 32, 96, _cdata.data());
else
stbtt_PackFontRange(&pc, std::get<std::vector<uint8_t>>(_build_data).data(), 0, _scale, 32, 96, _cdata.data());
stbtt_PackEnd(&pc);
for(int i = 0, j = 0; i < RANGE * RANGE; i++, j += 4)
{
@@ -77,12 +69,20 @@ namespace mlx
#else
_atlas.create(vulkan_bitmap.data(), RANGE, RANGE, VK_FORMAT_R8G8B8A8_UNORM, nullptr, true);
#endif
_atlas.setDescriptor(renderer.getFragDescriptorSet().duplicate());
_atlas.setDescriptor(_renderer.getFragDescriptorSet().duplicate());
_is_init = true;
}
void Font::destroy()
{
MLX_PROFILE_FUNCTION();
_atlas.destroy();
_is_init = false;
}
Font::~Font()
{
MLX_PROFILE_FUNCTION();
_atlas.destroy();
if(_is_init)
destroy();
}
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/11 21:17:04 by kbz_8 #+# #+# */
/* Updated: 2024/01/16 09:14:53 by maldavid ### ########.fr */
/* Updated: 2024/01/18 13:15:55 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,28 +17,39 @@
#include <stb_truetype.h>
#include <renderer/images/texture_atlas.h>
#include <utils/combine_hash.h>
#include <variant>
namespace mlx
{
class Font
{
friend class FontLibrary;
public:
Font() = delete;
Font(class Renderer& renderer, const std::filesystem::path& path, float scale);
Font(class Renderer& renderer, const std::string& name, const std::vector<uint8_t>& ttf_data, float scale);
inline const std::string& getName() const { return _name; }
inline float getScale() const noexcept { return _scale; }
inline const std::array<stbtt_packedchar, 96>& getCharData() const { return _cdata; }
inline const TextureAtlas& getAtlas() const noexcept { return _atlas; }
inline bool operator==(const Font& rhs) const { return rhs._name == _name && rhs._scale == _scale; }
inline bool operator!=(const Font& rhs) const { return rhs._name != _name || rhs._scale != _scale; }
void destroy();
~Font();
private:
void buildFont();
private:
std::array<stbtt_packedchar, 96> _cdata;
TextureAtlas _atlas;
std::variant<std::filesystem::path, std::vector<uint8_t>> _build_data;
std::string _name;
class Renderer& _renderer;
float _scale = 0;
bool _is_init = false;
};
}

69
src/renderer/texts/font_library.cpp git.filemode.normal_file
View File

@@ -0,0 +1,69 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* font_library.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/18 09:28:14 by maldavid #+# #+# */
/* Updated: 2024/01/18 13:07:48 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <renderer/texts/font_library.h>
#include <renderer/texts/font.h>
#include <core/errors.h>
#include <renderer/renderer.h>
#include <algorithm>
#include <core/profiler.h>
namespace mlx
{
std::shared_ptr<Font> FontLibrary::getFontData(FontID id)
{
MLX_PROFILE_FUNCTION();
if(!_cache.count(id) || std::find(_invalid_ids.begin(), _invalid_ids.end(), id) != _invalid_ids.end())
core::error::report(e_kind::fatal_error, "Font Library : wrong font ID '%d'", id);
return _cache[id];
}
FontID FontLibrary::addFontToLibrary(std::shared_ptr<Font> font)
{
MLX_PROFILE_FUNCTION();
auto it = std::find_if(_cache.begin(), _cache.end(), [&](const std::pair<FontID, std::shared_ptr<Font>>& v)
{
return v.second->getScale() == font->getScale() &&
v.second->getName() == font->getName() &&
std::find(_invalid_ids.begin(), _invalid_ids.end(), v.first) == _invalid_ids.end();
});
if(it != _cache.end())
return it->first;
font->buildFont();
_cache[_current_id] = font;
_current_id++;
return _current_id - 1;
}
void FontLibrary::removeFontFromLibrary(FontID id)
{
MLX_PROFILE_FUNCTION();
if(!_cache.count(id) || std::find(_invalid_ids.begin(), _invalid_ids.end(), id) != _invalid_ids.end())
{
core::error::report(e_kind::warning, "Font Library : trying to remove a font with an unkown or invalid ID '%d'", id);
return;
}
_cache[id]->destroy();
_invalid_ids.push_back(id);
}
void FontLibrary::clearLibrary()
{
MLX_PROFILE_FUNCTION();
for(auto& [id, font] : _cache)
{
font->destroy();
_invalid_ids.push_back(id);
}
// do not `_cache.clear();` as it releases the fonts and may not destroy the texture atlas that is in use by command buffers
}
}

52
src/renderer/texts/font_library.h git.filemode.normal_file
View File

@@ -0,0 +1,52 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* font_library.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/18 09:26:03 by maldavid #+# #+# */
/* Updated: 2024/01/18 09:33:30 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_FONT_LIBRARY__
#define __MLX_FONT_LIBRARY__
#include <unordered_map>
#include <memory>
#include <vector>
#include <cstdint>
#include <mlx_profile.h>
#include <renderer/texts/font.h>
#include <renderer/core/render_core.h>
#include <utils/singleton.h>
namespace mlx
{
using FontID = uint32_t;
constexpr FontID nullfont = 0;
class FontLibrary : public Singleton<FontLibrary>
{
friend class Singleton<FontLibrary>;
public:
std::shared_ptr<class Font> getFontData(FontID id);
FontID addFontToLibrary(std::shared_ptr<Font> font);
void removeFontFromLibrary(FontID id);
void clearLibrary();
private:
FontLibrary() = default;
~FontLibrary() = default;
private:
std::unordered_map<FontID, std::shared_ptr<class Font>> _cache;
std::vector<FontID> _invalid_ids;
FontID _current_id = 1;
};
}
#endif

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 00:11:56 by maldavid #+# #+# */
/* Updated: 2024/01/11 03:31:57 by maldavid ### ########.fr */
/* Updated: 2024/01/18 13:56:50 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,15 +16,21 @@
namespace mlx
{
void Text::init(std::string text, Font const* font, std::vector<Vertex> vbo_data, std::vector<uint16_t> ibo_data)
void Text::init(std::string text, FontID font, std::vector<Vertex> vbo_data, std::vector<uint16_t> ibo_data)
{
MLX_PROFILE_FUNCTION();
_text = std::move(text);
_font = font;
#ifdef DEBUG
std::string debug_name = _text;
for(char& c : debug_name)
{
if(c == ' ' || c == '"' || c == '\'')
c = '_';
}
for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
_vbo[i].create(sizeof(Vertex) * vbo_data.size(), static_cast<const void*>(vbo_data.data()), _text.c_str());
_ibo.create(sizeof(uint16_t) * ibo_data.size(), ibo_data.data(), _text.c_str());
_vbo[i].create(sizeof(Vertex) * vbo_data.size(), static_cast<const void*>(vbo_data.data()), debug_name.c_str());
_ibo.create(sizeof(uint16_t) * ibo_data.size(), ibo_data.data(), debug_name.c_str());
#else
for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
_vbo[i].create(sizeof(Vertex) * vbo_data.size(), static_cast<const void*>(vbo_data.data()), nullptr);

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 00:09:04 by maldavid #+# #+# */
/* Updated: 2024/01/11 00:13:25 by maldavid ### ########.fr */
/* Updated: 2024/01/18 09:37:42 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,6 +16,7 @@
#include <string>
#include <vector>
#include <renderer/texts/font.h>
#include <renderer/texts/font_library.h>
#include <renderer/buffers/vk_ibo.h>
#include <renderer/buffers/vk_vbo.h>
@@ -26,9 +27,9 @@ namespace mlx
public:
Text() = default;
void init(std::string text, Font const* font, std::vector<Vertex> vbo_data, std::vector<uint16_t> ibo_data);
void init(std::string text, FontID font, std::vector<Vertex> vbo_data, std::vector<uint16_t> ibo_data);
void bind(class Renderer& renderer) noexcept;
inline const Font& getFontInUse() const noexcept { return *_font; }
inline FontID getFontInUse() const noexcept { return _font; }
void updateVertexData(int frame, std::vector<Vertex> vbo_data);
inline uint32_t getIBOsize() noexcept { return _ibo.getSize(); }
inline const std::string& getText() const { return _text; }
@@ -40,7 +41,7 @@ namespace mlx
std::array<D_VBO, MAX_FRAMES_IN_FLIGHT> _vbo;
C_IBO _ibo;
std::string _text;
Font const* _font = nullptr;
FontID _font = nullfont;
};
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 00:23:11 by maldavid #+# #+# */
/* Updated: 2024/01/11 03:40:54 by maldavid ### ########.fr */
/* Updated: 2024/01/18 09:44:54 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -33,7 +33,7 @@ namespace mlx
TextDrawDescriptor::TextDrawDescriptor(std::string text, uint32_t _color, int _x, int _y) : color(_color), x(_x), y(_y), _text(std::move(text))
{}
void TextDrawDescriptor::init(Font* const font) noexcept
void TextDrawDescriptor::init(FontID font) noexcept
{
MLX_PROFILE_FUNCTION();
std::vector<Vertex> vertexData;
@@ -42,34 +42,38 @@ namespace mlx
float stb_x = 0.0f;
float stb_y = 0.0f;
for(char c : _text)
{
if(c < 32)
continue;
std::shared_ptr<Font> font_data = FontLibrary::get().getFontData(font);
stbtt_aligned_quad q;
stbtt_GetPackedQuad(font->getCharData().data(), RANGE, RANGE, c - 32, &stb_x, &stb_y, &q, 1);
for(char c : _text)
{
if(c < 32)
continue;
std::size_t index = vertexData.size();
stbtt_aligned_quad q;
stbtt_GetPackedQuad(font_data->getCharData().data(), RANGE, RANGE, c - 32, &stb_x, &stb_y, &q, 1);
glm::vec4 vertex_color = {
static_cast<float>((color & 0x000000FF)) / 255.f,
static_cast<float>((color & 0x0000FF00) >> 8) / 255.f,
static_cast<float>((color & 0x00FF0000) >> 16) / 255.f,
static_cast<float>((color & 0xFF000000) >> 24) / 255.f
};
std::size_t index = vertexData.size();
vertexData.emplace_back(glm::vec2{q.x0, q.y0}, vertex_color, glm::vec2{q.s0, q.t0});
vertexData.emplace_back(glm::vec2{q.x1, q.y0}, vertex_color, glm::vec2{q.s1, q.t0});
vertexData.emplace_back(glm::vec2{q.x1, q.y1}, vertex_color, glm::vec2{q.s1, q.t1});
vertexData.emplace_back(glm::vec2{q.x0, q.y1}, vertex_color, glm::vec2{q.s0, q.t1});
glm::vec4 vertex_color = {
static_cast<float>((color & 0x000000FF)) / 255.f,
static_cast<float>((color & 0x0000FF00) >> 8) / 255.f,
static_cast<float>((color & 0x00FF0000) >> 16) / 255.f,
static_cast<float>((color & 0xFF000000) >> 24) / 255.f
};
indexData.emplace_back(index + 0);
indexData.emplace_back(index + 1);
indexData.emplace_back(index + 2);
indexData.emplace_back(index + 2);
indexData.emplace_back(index + 3);
indexData.emplace_back(index + 0);
vertexData.emplace_back(glm::vec2{q.x0, q.y0}, vertex_color, glm::vec2{q.s0, q.t0});
vertexData.emplace_back(glm::vec2{q.x1, q.y0}, vertex_color, glm::vec2{q.s1, q.t0});
vertexData.emplace_back(glm::vec2{q.x1, q.y1}, vertex_color, glm::vec2{q.s1, q.t1});
vertexData.emplace_back(glm::vec2{q.x0, q.y1}, vertex_color, glm::vec2{q.s0, q.t1});
indexData.emplace_back(index + 0);
indexData.emplace_back(index + 1);
indexData.emplace_back(index + 2);
indexData.emplace_back(index + 2);
indexData.emplace_back(index + 3);
indexData.emplace_back(index + 0);
}
}
std::shared_ptr<Text> text_data = std::make_shared<Text>();
text_data->init(_text, font, std::move(vertexData), std::move(indexData));
@@ -84,13 +88,14 @@ namespace mlx
{
MLX_PROFILE_FUNCTION();
std::shared_ptr<Text> draw_data = TextLibrary::get().getTextData(id);
TextureAtlas& atlas = const_cast<TextureAtlas&>(draw_data->getFontInUse().getAtlas());
std::shared_ptr<Font> font_data = FontLibrary::get().getFontData(draw_data->getFontInUse());
TextureAtlas& atlas = const_cast<TextureAtlas&>(font_data->getAtlas());
draw_data->bind(renderer);
if(atlas.getSet() == VK_NULL_HANDLE)
if(!atlas.getSet().isInit())
atlas.setDescriptor(renderer.getFragDescriptorSet().duplicate());
if(!atlas.hasBeenUpdated())
atlas.updateSet(0);
sets[1] = const_cast<TextureAtlas&>(atlas).getSet();
sets[1] = const_cast<TextureAtlas&>(atlas).getVkSet();
vkCmdBindDescriptorSets(renderer.getActiveCmdBuffer().get(), VK_PIPELINE_BIND_POINT_GRAPHICS, renderer.getPipeline().getPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
atlas.render(renderer, x, y, draw_data->getIBOsize());
}
@@ -98,7 +103,8 @@ namespace mlx
void TextDrawDescriptor::resetUpdate()
{
std::shared_ptr<Text> draw_data = TextLibrary::get().getTextData(id);
TextureAtlas& atlas = const_cast<TextureAtlas&>(draw_data->getFontInUse().getAtlas());
std::shared_ptr<Font> font_data = FontLibrary::get().getFontData(draw_data->getFontInUse());
TextureAtlas& atlas = const_cast<TextureAtlas&>(font_data->getAtlas());
atlas.resetUpdate();
}
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 00:13:34 by maldavid #+# #+# */
/* Updated: 2024/01/11 04:28:58 by maldavid ### ########.fr */
/* Updated: 2024/01/18 09:40:06 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,6 +19,7 @@
#include <utils/combine_hash.h>
#include <renderer/core/drawable_resource.h>
#include <renderer/texts/text_library.h>
#include <renderer/texts/font_library.h>
#include <array>
namespace mlx
@@ -36,7 +37,7 @@ namespace mlx
public:
TextDrawDescriptor(std::string text, uint32_t _color, int _x, int _y);
void init(Font* const font) noexcept;
void init(FontID font) noexcept;
bool operator==(const TextDrawDescriptor& rhs) const { return _text == rhs._text && x == rhs.x && y == rhs.y && color == rhs.color; }
void render(std::array<VkDescriptorSet, 2>& sets, Renderer& renderer) override;
void resetUpdate() override;

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/10 11:59:57 by maldavid #+# #+# */
/* Updated: 2024/01/16 08:54:22 by maldavid ### ########.fr */
/* Updated: 2024/01/18 08:02:31 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/06 16:41:13 by maldavid #+# #+# */
/* Updated: 2024/01/17 03:47:46 by maldavid ### ########.fr */
/* Updated: 2024/01/18 09:45:24 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -29,19 +29,13 @@ namespace mlx
void TextManager::loadFont(Renderer& renderer, const std::filesystem::path& filepath, float scale)
{
MLX_PROFILE_FUNCTION();
for(Font& font : _font_set)
{
if(filepath == font.getName() && scale == font.getScale())
{
_font_in_use = &font;
return;
}
}
std::shared_ptr<Font> font;
if(filepath.string() == "default")
_font_in_use = &_font_set.emplace_back(renderer, "default", dogica_ttf, scale);
font = std::make_shared<Font>(renderer, "default", dogica_ttf, scale);
else
_font_in_use = &_font_set.emplace_back(renderer, filepath, scale);
font = std::make_shared<Font>(renderer, filepath, scale);
_font_in_use = FontLibrary::get().addFontToLibrary(font);
}
std::pair<DrawableResource*, bool> TextManager::registerText(int x, int y, uint32_t color, std::string str)
@@ -55,8 +49,9 @@ namespace mlx
}
auto text_ptr = TextLibrary::get().getTextData(res.first->id);
if(*_font_in_use != text_ptr->getFontInUse())
if(_font_in_use != text_ptr->getFontInUse())
{
// TODO : update text vertex buffers rather than destroying it and recreating it
TextLibrary::get().removeTextFromLibrary(res.first->id);
const_cast<TextDrawDescriptor&>(*res.first).init(_font_in_use);
}
@@ -67,6 +62,5 @@ namespace mlx
{
MLX_PROFILE_FUNCTION();
_text_descriptors.clear();
_font_set.clear();
}
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/06 16:24:11 by maldavid #+# #+# */
/* Updated: 2024/01/16 09:04:05 by maldavid ### ########.fr */
/* Updated: 2024/01/18 13:52:01 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,6 +23,8 @@
#include <mlx_profile.h>
#include <renderer/texts/text_descriptor.h>
#include <renderer/texts/text_library.h>
#include <renderer/texts/font_library.h>
#include <memory>
namespace mlx
{
@@ -33,7 +35,7 @@ namespace mlx
void init(Renderer& renderer) noexcept;
std::pair<DrawableResource*, bool> registerText(int x, int y, uint32_t color, std::string str);
inline void clear() { _text_descriptors.clear(); /*TextLibrary::get().clearLibrary();*/ }
inline void clear() { _text_descriptors.clear(); TextLibrary::get().clearLibrary(); }
void loadFont(Renderer& renderer, const std::filesystem::path& filepath, float scale);
void destroy() noexcept;
@@ -41,8 +43,7 @@ namespace mlx
private:
std::unordered_set<TextDrawDescriptor> _text_descriptors;
std::vector<Font> _font_set;
Font* _font_in_use = nullptr;
FontID _font_in_use = nullfont;
};
}