still working on code refactoring

This commit is contained in:
2024-04-23 22:59:33 +02:00
parent ace4c98945
commit 1d9a51e4f7
16 changed files with 560 additions and 518 deletions

View File

@@ -1,48 +1,47 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* font.cpp :+: :+: :+: */
/* Font.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/11 22:06:09 by kbz_8 #+# #+# */
/* Updated: 2024/03/25 19:03:54 by maldavid ### ########.fr */
/* Updated: 2024/04/23 22:48:30 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <pre_compiled.h>
#include <PreCompiled.h>
#include <renderer/texts/font.h>
#include <renderer/renderer.h>
#include <core/profiler.h>
#include <Renderer/Texts/Font.h>
#include <Renderer/Renderer.h>
constexpr const int RANGE = 1024;
namespace mlx
{
Font::Font(Renderer& renderer, const std::filesystem::path& path, float scale) : _name(path.string()), _renderer(renderer), _scale(scale)
Font::Font(Renderer& renderer, const std::filesystem::path& path, float scale) : m_name(path.string()), m_renderer(renderer), m_scale(scale)
{
_build_data = path;
m_build_data = path;
}
Font::Font(class Renderer& renderer, const std::string& name, const std::vector<std::uint8_t>& ttf_data, float scale) : _name(name), _renderer(renderer), _scale(scale)
Font::Font(class Renderer& renderer, const std::string& name, const std::vector<std::uint8_t>& ttf_data, float scale) : m_name(name), m_renderer(renderer), m_scale(scale)
{
_build_data = ttf_data;
m_build_data = ttf_data;
}
void Font::buildFont()
void Font::BuildFont()
{
MLX_PROFILE_FUNCTION();
std::vector<std::uint8_t> file_bytes;
if(std::holds_alternative<std::filesystem::path>(_build_data))
if(std::holds_alternative<std::filesystem::path>(m_build_data))
{
std::ifstream file(std::get<std::filesystem::path>(_build_data), std::ios::binary);
std::ifstream file(std::get<std::filesystem::path>(m_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());
Error("Font load : cannot open font file, %", m_name.c_str());
return;
}
std::ifstream::pos_type fileSize = std::filesystem::file_size(std::get<std::filesystem::path>(_build_data));
std::ifstream::pos_type fileSize = std::filesystem::file_size(std::get<std::filesystem::path>(m_build_data));
file.seekg(0, std::ios::beg);
file_bytes.resize(fileSize);
file.read(reinterpret_cast<char*>(file_bytes.data()), fileSize);
@@ -53,10 +52,10 @@ namespace mlx
std::vector<std::uint8_t> vulkan_bitmap(RANGE * RANGE * 4);
stbtt_pack_context pc;
stbtt_PackBegin(&pc, tmp_bitmap.data(), RANGE, RANGE, RANGE, 1, nullptr);
if(std::holds_alternative<std::filesystem::path>(_build_data))
stbtt_PackFontRange(&pc, file_bytes.data(), 0, _scale, 32, 96, _cdata.data());
if(std::holds_alternative<std::filesystem::path>(m_build_data))
stbtt_PackFontRange(&pc, file_bytes.data(), 0, m_scale, 32, 96, m_cdata.data());
else
stbtt_PackFontRange(&pc, std::get<std::vector<std::uint8_t>>(_build_data).data(), 0, _scale, 32, 96, _cdata.data());
stbtt_PackFontRange(&pc, std::get<std::vector<std::uint8_t>>(m_build_data).data(), 0, m_scale, 32, 96, m_cdata.data());
stbtt_PackEnd(&pc);
for(int i = 0, j = 0; i < RANGE * RANGE; i++, j += 4)
{
@@ -66,24 +65,24 @@ namespace mlx
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);
m_atlas.Create(vulkan_bitmap.data(), RANGE, RANGE, VK_FORMAT_R8G8B8A8_UNORM, std::string(m_name + "_font_altas").c_str(), true);
#else
_atlas.create(vulkan_bitmap.data(), RANGE, RANGE, VK_FORMAT_R8G8B8A8_UNORM, nullptr, true);
m_atlas.Create(vulkan_bitmap.data(), RANGE, RANGE, VK_FORMAT_R8G8B8A8_UNORM, nullptr, true);
#endif
_atlas.setDescriptor(_renderer.getFragDescriptorSet().duplicate());
_is_init = true;
m_atlas.SetDescriptor(m_renderer.GetFragDescriptorSet().Duplicate());
m_is_init = true;
}
void Font::destroy()
void Font::Destroy()
{
MLX_PROFILE_FUNCTION();
_atlas.destroy();
_is_init = false;
m_atlas.Destroy();
m_is_init = false;
}
Font::~Font()
{
if(_is_init)
if(m_is_init)
destroy();
}
}

View File

@@ -1,16 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* font_library.cpp :+: :+: :+: */
/* FontLibrary.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/18 09:28:14 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:03:57 by maldavid ### ########.fr */
/* Updated: 2024/04/23 22:59:16 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <pre_compiled.h>
#include <PreCompiled.h>
#include <renderer/texts/font_library.h>
#include <renderer/texts/font.h>