From 11b1bd147d24275e64e72f2da1c7ebb180e292a6 Mon Sep 17 00:00:00 2001 From: Kbz-8 <kbz_8.dev@akel-engine.com> Date: Thu, 14 Dec 2023 13:51:17 +0100 Subject: [PATCH 1/2] fixing issues with texture rendering --- src/renderer/images/texture.h | 5 +++-- test/main.c | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/renderer/images/texture.h b/src/renderer/images/texture.h index 695e580..0390cc1 100644 --- a/src/renderer/images/texture.h +++ b/src/renderer/images/texture.h @@ -6,7 +6,7 @@ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/08 02:24:58 by maldavid #+# #+# */ -/* Updated: 2023/12/08 19:10:09 by kbz_8 ### ########.fr */ +/* Updated: 2023/12/14 13:47:03 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,6 +22,7 @@ #include <renderer/buffers/vk_ibo.h> #include <renderer/buffers/vk_vbo.h> #include <mlx_profile.h> +#include <string> namespace mlx { @@ -83,7 +84,7 @@ namespace std { size_t operator()(const mlx::TextureRenderData& td) const noexcept { - return std::hash<mlx::Texture*>()(td.texture) + std::hash<int>()(td.x) + std::hash<int>()(td.y); + return std::hash<mlx::Texture*>{}(td.texture) + std::hash<std::string>{}(std::to_string(td.x)) + std::hash<std::string>{}(std::to_string(td.y)); } }; } diff --git a/test/main.c b/test/main.c index 12e13a2..e618462 100644 --- a/test/main.c +++ b/test/main.c @@ -6,7 +6,7 @@ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */ -/* Updated: 2023/12/08 18:08:13 by kbz_8 ### ########.fr */ +/* Updated: 2023/12/14 13:49:22 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -107,7 +107,7 @@ int main(void) mlx_on_event(mlx.mlx, mlx.win, MLX_WINDOW_EVENT, window_hook, &mlx); mlx.logo = mlx_png_file_to_image(mlx.mlx, "42_logo.png", &w, &h); mlx_pixel_put(mlx.mlx, mlx.win, 200, 10, 0xFFFF00FF); - mlx_put_image_to_window(mlx.mlx, mlx.win, mlx.logo, 200, 200); + mlx_put_image_to_window(mlx.mlx, mlx.win, mlx.logo, 10, 190); mlx.img = create_image(&mlx); mlx_string_put(mlx.mlx, mlx.win, 20, 20, 0xFFFF2000, \ "that text will disappear"); From ac91253f51a9e43cbca6437c899ed6a38262fe63 Mon Sep 17 00:00:00 2001 From: Kbz-8 <kbz_8.dev@akel-engine.com> Date: Thu, 14 Dec 2023 14:39:00 +0100 Subject: [PATCH 2/2] removing buggy texture hash system --- src/core/graphics.inl | 7 +------ src/renderer/images/texture.h | 15 +-------------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/src/core/graphics.inl b/src/core/graphics.inl index 0a472c3..055a332 100644 --- a/src/core/graphics.inl +++ b/src/core/graphics.inl @@ -47,13 +47,8 @@ namespace mlx void GraphicsSupport::texturePut(Texture* texture, int x, int y) { _textures_to_render.emplace_back(texture, x, y); - std::size_t hash = std::hash<TextureRenderData>{}(_textures_to_render.back()); - _textures_to_render.back().hash = hash; - auto it = std::find_if(_textures_to_render.begin(), _textures_to_render.end() - 1, [=](const TextureRenderData& rhs) - { - return rhs.hash == hash; - }); + auto it = std::find(_textures_to_render.begin(), _textures_to_render.end() - 1, _textures_to_render.back()); if(it != _textures_to_render.end() - 1) _textures_to_render.erase(it); diff --git a/src/renderer/images/texture.h b/src/renderer/images/texture.h index 0390cc1..725b37a 100644 --- a/src/renderer/images/texture.h +++ b/src/renderer/images/texture.h @@ -6,7 +6,7 @@ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/08 02:24:58 by maldavid #+# #+# */ -/* Updated: 2023/12/14 13:47:03 by maldavid ### ########.fr */ +/* Updated: 2023/12/14 14:37:08 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -68,7 +68,6 @@ namespace mlx struct TextureRenderData { Texture* texture; - std::size_t hash = 0; int x; int y; @@ -77,16 +76,4 @@ namespace mlx }; } -namespace std -{ - template <> - struct hash<mlx::TextureRenderData> - { - size_t operator()(const mlx::TextureRenderData& td) const noexcept - { - return std::hash<mlx::Texture*>{}(td.texture) + std::hash<std::string>{}(std::to_string(td.x)) + std::hash<std::string>{}(std::to_string(td.y)); - } - }; -} - #endif