Skip to content

Commit

Permalink
fixing new gcc warning in GPU allocator, fixing #55
Browse files Browse the repository at this point in the history
  • Loading branch information
Kbz-8 committed Mar 25, 2024
1 parent be52578 commit 60d3df7
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 25 deletions.
14 changes: 9 additions & 5 deletions example/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */
/* Updated: 2024/03/14 20:01:01 by maldavid ### ########.fr */
/* Updated: 2024/03/25 16:16:07 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -23,7 +23,7 @@ typedef struct
void* img;
} mlx_t;

void* img = NULL;
//void* img = NULL;

int update(void* param)
{
Expand All @@ -32,13 +32,13 @@ int update(void* param)

if(i == 200)
mlx_clear_window(mlx->mlx, mlx->win);

/*
if(img)
mlx_destroy_image(mlx->mlx,img);
img = mlx_new_image(mlx->mlx, 800, 800);
mlx_set_image_pixel(mlx->mlx, img, 4, 4, 0xFF00FF00);
mlx_put_image_to_window(mlx->mlx, mlx->win, img, 0, 0);

*/
if(i >= 250)
mlx_set_font_scale(mlx->mlx, mlx->win, "default", 16.f);
else
Expand Down Expand Up @@ -157,7 +157,11 @@ int main(void)
mlx_put_image_to_window(mlx.mlx, mlx.win, mlx.logo_png, 10, 190);

mlx.img = create_image(&mlx);



mlx_string_put(mlx.mlx, mlx.win, 0, 10, 0xFFFFFF00, "fps:");
mlx_string_put(mlx.mlx, mlx.win, 0, 20, 0xFFFFFFFF, "fps:");

mlx_set_font_scale(mlx.mlx, mlx.win, "font.ttf", 16.f);
mlx_string_put(mlx.mlx, mlx.win, 20, 20, 0xFF0020FF, "that text will disappear");

Expand Down
6 changes: 3 additions & 3 deletions src/renderer/core/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/20 02:13:03 by maldavid #+# #+# */
/* Updated: 2024/01/03 15:25:56 by maldavid ### ########.fr */
/* Updated: 2024/03/25 16:01:06 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -44,8 +44,8 @@ namespace mlx

private:
VmaAllocator _allocator;
std::uint32_t _active_buffers_allocations = 0;
std::uint32_t _active_images_allocations = 0;
std::int32_t _active_buffers_allocations = 0;
std::int32_t _active_images_allocations = 0;
};
}

Expand Down
5 changes: 3 additions & 2 deletions src/renderer/texts/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 00:11:56 by maldavid #+# #+# */
/* Updated: 2024/02/25 09:01:46 by maldavid ### ########.fr */
/* Updated: 2024/03/25 16:13:08 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -16,12 +16,13 @@

namespace mlx
{
void Text::init(std::string text, FontID font, std::vector<Vertex> vbo_data, std::vector<std::uint16_t> ibo_data)
void Text::init(std::string text, FontID font, std::uint32_t color, std::vector<Vertex> vbo_data, std::vector<std::uint16_t> ibo_data)
{
MLX_PROFILE_FUNCTION();
if(_is_init)
return;
_text = std::move(text);
_color = color;
_font = font;
#ifdef DEBUG
std::string debug_name = _text;
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/texts/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 00:09:04 by maldavid #+# #+# */
/* Updated: 2024/02/25 09:00:26 by maldavid ### ########.fr */
/* Updated: 2024/03/25 16:16:48 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -27,12 +27,13 @@ namespace mlx
public:
Text() = default;

void init(std::string text, FontID font, std::vector<Vertex> vbo_data, std::vector<std::uint16_t> ibo_data);
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;

~Text();
Expand All @@ -41,6 +42,7 @@ namespace mlx
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;
};
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/texts/text_descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 00:23:11 by maldavid #+# #+# */
/* Updated: 2024/02/25 07:58:21 by maldavid ### ########.fr */
/* Updated: 2024/03/25 16:13:48 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -76,7 +76,7 @@ namespace mlx
}
}
std::shared_ptr<Text> text_data = std::make_shared<Text>();
text_data->init(_text, font, std::move(vertexData), std::move(indexData));
text_data->init(_text, font, color, std::move(vertexData), std::move(indexData));
id = TextLibrary::get().addTextToLibrary(text_data);

#ifdef DEBUG
Expand Down
13 changes: 5 additions & 8 deletions src/renderer/texts/text_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/10 11:59:57 by maldavid #+# #+# */
/* Updated: 2024/03/14 17:31:55 by maldavid ### ########.fr */
/* Updated: 2024/03/25 16:17:06 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -22,7 +22,7 @@ namespace mlx
std::shared_ptr<Text> TextLibrary::getTextData(TextID id)
{
MLX_PROFILE_FUNCTION();
if(!_cache.count(id) || std::find(_invalid_ids.begin(), _invalid_ids.end(), id) != _invalid_ids.end())
if(!_cache.count(id))
core::error::report(e_kind::fatal_error, "Text Library : wrong text ID '%d'", id);
return _cache[id];
}
Expand All @@ -32,7 +32,7 @@ namespace mlx
MLX_PROFILE_FUNCTION();
auto it = std::find_if(_cache.begin(), _cache.end(), [&](const std::pair<TextID, std::shared_ptr<Text>>& v)
{
return v.second->getText() == text->getText() && std::find(_invalid_ids.begin(), _invalid_ids.end(), v.first) == _invalid_ids.end();
return v.second->getText() == text->getText() && v.second->getColor() == text->getColor();
});
if(it != _cache.end())
return it->first;
Expand All @@ -44,23 +44,20 @@ namespace mlx
void TextLibrary::removeTextFromLibrary(TextID id)
{
MLX_PROFILE_FUNCTION();
if(!_cache.count(id) || std::find(_invalid_ids.begin(), _invalid_ids.end(), id) != _invalid_ids.end())
if(!_cache.count(id))
{
core::error::report(e_kind::warning, "Text Library : trying to remove a text with an unkown or invalid ID '%d'", id);
return;
}
_cache[id]->destroy();
_invalid_ids.push_back(id);
_cache.erase(id);
}

void TextLibrary::clearLibrary()
{
MLX_PROFILE_FUNCTION();
for(auto& [id, text] : _cache)
{
text->destroy();
_invalid_ids.push_back(id);
}
_cache.clear();
}
}
4 changes: 1 addition & 3 deletions src/renderer/texts/text_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/10 11:52:30 by maldavid #+# #+# */
/* Updated: 2024/01/16 08:54:15 by maldavid ### ########.fr */
/* Updated: 2024/03/25 16:04:47 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -17,7 +17,6 @@
#include <renderer/buffers/vk_ibo.h>
#include <unordered_map>
#include <memory>
#include <vector>
#include <cstdint>
#include <mlx_profile.h>
#include <renderer/texts/font.h>
Expand Down Expand Up @@ -46,7 +45,6 @@ namespace mlx

private:
std::unordered_map<TextID, std::shared_ptr<class Text>> _cache;
std::vector<TextID> _invalid_ids;
TextID _current_id = 1;
};
}
Expand Down

0 comments on commit 60d3df7

Please sign in to comment.