This commit is contained in:
2024-04-21 18:10:36 +02:00
parent 6bbf1e196d
commit 215a0dc2c3
28 changed files with 558 additions and 375 deletions

View File

@@ -1,52 +1,54 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* font.h :+: :+: :+: */
/* Font.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/11 21:17:04 by kbz_8 #+# #+# */
/* Updated: 2024/03/25 19:08:21 by maldavid ### ########.fr */
/* Updated: 2024/03/28 22:19:39 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_FONT__
#define __MLX_FONT__
#include <renderer/images/texture_atlas.h>
#include <utils/combine_hash.h>
#include <Renderer/Images/TextureAtlas.h>
#include <Utils/CombineHash.h>
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<std::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();
inline const std::string& GetName() const { return m_name; }
inline float GetScale() const noexcept { return m_scale; }
inline const std::array<stbtt_packedchar, 96>& GetCharData() const { return m_cdata; }
inline const TextureAtlas& GetAtlas() const noexcept { return m_atlas; }
inline bool operator==(const Font& rhs) const { return rhs._name == m_name && rhs._scale == m_scale; }
inline bool operator!=(const Font& rhs) const { return rhs._name != m_name || rhs._scale != m_scale; }
void Destroy();
~Font();
private:
void buildFont();
void BuildFont();
private:
std::array<stbtt_packedchar, 96> _cdata;
TextureAtlas _atlas;
std::variant<std::filesystem::path, std::vector<std::uint8_t>> _build_data;
std::string _name;
class Renderer& _renderer;
float _scale = 0;
bool _is_init = false;
std::array<stbtt_packedchar, 96> m_cdata;
TextureAtlas m_atlas;
std::variant<std::filesystem::path, std::vector<std::uint8_t>> m_build_data;
std::string m_name;
class Renderer& m_renderer;
float m_scale = 0;
bool m_is_init = false;
};
}

View File

@@ -1,21 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* font_library.h :+: :+: :+: */
/* FontLibrary.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/18 09:26:03 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:08:18 by maldavid ### ########.fr */
/* Updated: 2024/03/28 22:21:53 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_FONT_LIBRARY__
#define __MLX_FONT_LIBRARY__
#include <renderer/texts/font.h>
#include <renderer/core/render_core.h>
#include <utils/singleton.h>
#include <Renderer/Texts/Font.h>
#include <Renderer/Core/RenderCore.h>
#include <Utils/Singleton.h>
namespace mlx
{
@@ -27,20 +27,20 @@ namespace mlx
friend class Singleton<FontLibrary>;
public:
std::shared_ptr<class Font> getFontData(FontID id);
FontID addFontToLibrary(std::shared_ptr<Font> font);
void removeFontFromLibrary(FontID id);
std::shared_ptr<class Font> GetFontData(FontID id);
FontID AddFontToLibrary(std::shared_ptr<Font> font);
void RemoveFontFromLibrary(FontID id);
void clearLibrary();
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;
std::unordered_map<FontID, std::shared_ptr<class Font>> m_cache;
std::vector<FontID> m_invalid_ids;
FontID m_current_id = 1;
};
}

View File

@@ -1,22 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* text.h :+: :+: :+: */
/* Text.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 00:09:04 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:08:15 by maldavid ### ########.fr */
/* Updated: 2024/03/28 22:23:50 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_TEXT__
#define __MLX_TEXT__
#include <renderer/texts/font.h>
#include <renderer/texts/font_library.h>
#include <renderer/buffers/vk_ibo.h>
#include <renderer/buffers/vk_vbo.h>
#include <Renderer/Texts/Font.h>
#include <Renderer/Texts/FontLibrary.h>
#include <Renderer/Buffers/IndexBuffer.h>
#include <Renderer/Buffers/VertexBuffer.h>
namespace mlx
{
@@ -25,24 +25,24 @@ namespace mlx
public:
Text() = default;
void init(std::string text, FontID font, std::uint32_t color, std::vector<Vertex> vbo_data, std::vector<std::uint16_t> ibo_data);
void bind(class Renderer& renderer) noexcept;
inline FontID getFontInUse() const noexcept { return _font; }
void updateVertexData(int frame, std::vector<Vertex> vbo_data);
inline std::uint32_t getIBOsize() noexcept { return _ibo.getSize(); }
inline const std::string& getText() const { return _text; }
inline std::uint32_t getColor() const noexcept { return _color; }
void destroy() noexcept;
void Init(std::string text, FontID font, std::uint32_t color, std::vector<Vertex> vbo_data, std::vector<std::uint16_t> ibo_data);
void Bind(class Renderer& renderer) noexcept;
inline FontID GetFontInUse() const noexcept { return m_font; }
void UpdateVertexData(int frame, std::vector<Vertex> vbo_data);
inline std::uint32_t GetIBOsize() noexcept { return m_ibo.GetSize(); }
inline const std::string& GetText() const { return m_text; }
inline std::uint32_t GetColor() const noexcept { return m_color; }
void Destroy() noexcept;
~Text();
private:
std::array<D_VBO, MAX_FRAMES_IN_FLIGHT> _vbo;
C_IBO _ibo;
std::string _text;
std::uint32_t _color;
FontID _font = nullfont;
bool _is_init = false;
std::array<DeviceVertexBuffer, MAX_FRAMES_IN_FLIGHT> m_vbo;
ConstantIndexBuffer m_ibo;
std::string m_text;
std::uint32_t m_color;
FontID m_font = nullfont;
bool m_is_init = false;
};
}

View File

@@ -1,22 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* text_descriptor.h :+: :+: :+: */
/* TextDescriptor.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 00:13:34 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:08:11 by maldavid ### ########.fr */
/* Updated: 2024/03/28 22:25:09 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_TEXT_DESCRIPTOR__
#define __MLX_TEXT_DESCRIPTOR__
#include <utils/combine_hash.h>
#include <renderer/core/drawable_resource.h>
#include <renderer/texts/text_library.h>
#include <renderer/texts/font_library.h>
#include <Utils/CombineHash.h>
#include <Renderer/Core/DrawableResource.h>
#include <Renderer/Texts/TextLibrary.h>
#include <Renderer/Texts/FontLibrary.h>
namespace mlx
{
@@ -33,15 +33,15 @@ namespace mlx
public:
TextDrawDescriptor(std::string text, std::uint32_t _color, int _x, int _y);
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;
void Init(FontID font) noexcept;
bool operator==(const TextDrawDescriptor& rhs) const { return m_text == rhs.m_text && x == rhs.x && y == rhs.y && color == rhs.color; }
void Render(std::array<VkDescriptorSet, 2>& sets, Renderer& renderer) override;
void ResetUpdate() override;
TextDrawDescriptor() = default;
private:
std::string _text;
std::string m_text;
};
}
@@ -53,7 +53,7 @@ namespace std
std::size_t operator()(const mlx::TextDrawDescriptor& d) const noexcept
{
std::size_t hash = 0;
mlx::hashCombine(hash, d.x, d.y, d.color, d._text);
mlx::HashCombine(hash, d.x, d.y, d.color, d.m_text);
return hash;
}
};

View File

@@ -1,23 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* text_library.h :+: :+: :+: */
/* TextLibrary.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/10 11:52:30 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:08:03 by maldavid ### ########.fr */
/* Updated: 2024/03/28 22:26:10 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_TEXT_LIBRARY__
#define __MLX_TEXT_LIBRARY__
#include <renderer/buffers/vk_vbo.h>
#include <renderer/buffers/vk_ibo.h>
#include <renderer/texts/font.h>
#include <renderer/core/render_core.h>
#include <utils/singleton.h>
#include <Renderer/Buffers/VertexBuffer.h>
#include <Renderer/Buffers/IndexBuffer.h>
#include <Renderer/Texts/Font.h>
#include <Renderer/Core/RenderCore.h>
#include <Utils/Singleton.h>
namespace mlx
{
@@ -29,19 +29,19 @@ namespace mlx
friend class Singleton<TextLibrary>;
public:
std::shared_ptr<class Text> getTextData(TextID id);
TextID addTextToLibrary(std::shared_ptr<Text> text);
void removeTextFromLibrary(TextID id);
std::shared_ptr<class Text> GetTextData(TextID id);
TextID AddTextToLibrary(std::shared_ptr<Text> text);
void RemoveTextFromLibrary(TextID id);
void clearLibrary();
void ClearLibrary();
private:
TextLibrary() = default;
~TextLibrary() = default;
private:
std::unordered_map<TextID, std::shared_ptr<class Text>> _cache;
TextID _current_id = 1;
std::unordered_map<TextID, std::shared_ptr<class Text>> m_cache;
TextID m_current_id = 1;
};
}

View File

@@ -1,23 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* text_manager.h :+: :+: :+: */
/* TextManager.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/06 16:24:11 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:08:00 by maldavid ### ########.fr */
/* Updated: 2024/03/28 22:27:32 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_TEXT_MANAGER__
#define __MLX_TEXT_MANAGER__
#include <renderer/renderer.h>
#include <renderer/images/texture_atlas.h>
#include <renderer/texts/text_descriptor.h>
#include <renderer/texts/text_library.h>
#include <renderer/texts/font_library.h>
#include <Renderer/Renderer.h>
#include <Renderer/Images/TextureAtlas.h>
#include <Renderer/Texts/TextDescriptor.h>
#include <Renderer/Texts/TextLibrary.h>
#include <Renderer/Texts/FontLibrary.h>
namespace mlx
{
@@ -26,17 +26,17 @@ namespace mlx
public:
TextManager() = default;
void init(Renderer& renderer) noexcept;
std::pair<DrawableResource*, bool> registerText(int x, int y, std::uint32_t color, std::string str);
inline void clear() { _text_descriptors.clear(); }
void loadFont(Renderer& renderer, const std::filesystem::path& filepath, float scale);
void destroy() noexcept;
void Init(Renderer& renderer) noexcept;
std::pair<NonOwningPtr<DrawableResource>, bool> RegisterText(int x, int y, std::uint32_t color, std::string str);
inline void Clear() { m_text_descriptors.clear(); }
void LoadFont(Renderer& renderer, const std::filesystem::path& filepath, float scale);
void Destroy() noexcept;
~TextManager() = default;
private:
std::unordered_set<TextDrawDescriptor> _text_descriptors;
FontID _font_in_use = nullfont;
std::unordered_set<TextDrawDescriptor> m_text_descriptors;
FontID m_font_in_use = nullfont;
};
}