-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
20 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: maldavid <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/11 00:11:56 by maldavid #+# #+# */ | ||
/* Updated: 2024/01/18 13:56:50 by maldavid ### ########.fr */ | ||
/* Updated: 2024/02/25 09:01:46 by maldavid ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -19,6 +19,8 @@ namespace mlx | |
void Text::init(std::string text, FontID font, std::vector<Vertex> vbo_data, std::vector<std::uint16_t> ibo_data) | ||
{ | ||
MLX_PROFILE_FUNCTION(); | ||
if(_is_init) | ||
return; | ||
_text = std::move(text); | ||
_font = font; | ||
#ifdef DEBUG | ||
|
@@ -36,26 +38,39 @@ namespace mlx | |
_vbo[i].create(sizeof(Vertex) * vbo_data.size(), static_cast<const void*>(vbo_data.data()), nullptr); | ||
_ibo.create(sizeof(std::uint16_t) * ibo_data.size(), ibo_data.data(), nullptr); | ||
#endif | ||
_is_init = true; | ||
} | ||
|
||
void Text::bind(Renderer& renderer) noexcept | ||
{ | ||
MLX_PROFILE_FUNCTION(); | ||
if(!_is_init) | ||
return; | ||
_vbo[renderer.getActiveImageIndex()].bind(renderer); | ||
_ibo.bind(renderer); | ||
} | ||
|
||
void Text::updateVertexData(int frame, std::vector<Vertex> vbo_data) | ||
{ | ||
MLX_PROFILE_FUNCTION(); | ||
if(!_is_init) | ||
return; | ||
_vbo[frame].setData(sizeof(Vertex) * vbo_data.size(), static_cast<const void*>(vbo_data.data())); | ||
} | ||
|
||
void Text::destroy() noexcept | ||
{ | ||
MLX_PROFILE_FUNCTION(); | ||
if(!_is_init) | ||
return; | ||
for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) | ||
_vbo[i].destroy(); | ||
_ibo.destroy(); | ||
_is_init = false; | ||
} | ||
|
||
Text::~Text() | ||
{ | ||
destroy(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: maldavid <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/11 00:09:04 by maldavid #+# #+# */ | ||
/* Updated: 2024/01/18 09:37:42 by maldavid ### ########.fr */ | ||
/* Updated: 2024/02/25 09:00:26 by maldavid ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -35,13 +35,14 @@ namespace mlx | |
inline const std::string& getText() const { return _text; } | ||
void destroy() noexcept; | ||
|
||
~Text() = default; | ||
~Text(); | ||
|
||
private: | ||
std::array<D_VBO, MAX_FRAMES_IN_FLIGHT> _vbo; | ||
C_IBO _ibo; | ||
std::string _text; | ||
FontID _font = nullfont; | ||
bool _is_init = false; | ||
}; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: maldavid <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/04/06 16:41:13 by maldavid #+# #+# */ | ||
/* Updated: 2024/02/24 21:39:12 by maldavid ### ########.fr */ | ||
/* Updated: 2024/02/25 08:17:09 by maldavid ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -53,7 +53,6 @@ namespace mlx | |
if(_font_in_use != text_ptr->getFontInUse()) | ||
{ | ||
// TODO : update text vertex buffers rather than destroying it and recreating it | ||
std::cout << "test" << std::endl; | ||
TextLibrary::get().removeTextFromLibrary(res.first->id); | ||
const_cast<TextDrawDescriptor&>(*res.first).init(_font_in_use); | ||
} | ||
|