working text pipeline

This commit is contained in:
Kbz-8
2023-04-11 13:21:11 +02:00
parent 77d71adc1f
commit 026f83ca81
9 changed files with 217 additions and 96 deletions

66
src/renderer/text_library.cpp git.filemode.normal_file
View File

@@ -0,0 +1,66 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* text_library.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/10 11:59:57 by maldavid #+# #+# */
/* Updated: 2023/04/11 12:28:42 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <renderer/text_library.h>
#include <core/errors.h>
#include <renderer/renderer.h>
namespace mlx
{
void TextData::init(std::vector<Vertex> vbo_data, std::vector<uint16_t> ibo_data)
{
_vbo.create(sizeof(Vertex) * vbo_data.size(), vbo_data.data());
_ibo.create(sizeof(uint16_t) * ibo_data.size(), ibo_data.data());
}
void TextData::bind(Renderer& renderer) noexcept
{
_vbo.bind(renderer);
_ibo.bind(renderer);
}
void TextData::destroy() noexcept
{
_vbo.destroy();
_ibo.destroy();
}
std::shared_ptr<TextData> TextLibrary::getTextData(TextID id)
{
if(!_cache.count(id))
core::error::report(e_kind::fatal_error, "Text Library : wrong text ID '%d'", id);
return _cache[id];
}
TextID TextLibrary::addTextToLibrary(std::shared_ptr<TextData> text)
{
_cache[_current_id] = text;
_current_id++;
return _current_id - 1;
}
void TextLibrary::removeTextFromLibrary(TextID id)
{
if(_cache.count(id))
{
_cache[id]->destroy();
_cache.erase(id);
}
}
void TextLibrary::clearLibrary()
{
for(auto [id, text] : _cache)
text->destroy();
_cache.clear();
}
}