diff --git a/libs/gfx/include/psemek/gfx/mesh.hpp b/libs/gfx/include/psemek/gfx/mesh.hpp index 0ede75f9..bbc024c9 100644 --- a/libs/gfx/include/psemek/gfx/mesh.hpp +++ b/libs/gfx/include/psemek/gfx/mesh.hpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -336,6 +337,6 @@ namespace psemek::gfx load_instance(instances.data(), instances.size(), usage); } - void load_mesh(mesh & m, std::string_view data); + std::tuple, util::span> load_mesh(std::string_view data); } diff --git a/libs/gfx/source/mesh.cpp b/libs/gfx/source/mesh.cpp index 609e7e5b..7dbe09a6 100644 --- a/libs/gfx/source/mesh.cpp +++ b/libs/gfx/source/mesh.cpp @@ -198,7 +198,7 @@ namespace psemek::gfx } } - void load_mesh(mesh & m, std::string_view data) + std::tuple, util::span> load_mesh(std::string_view data) { // These should be in sync with convert-mesh.py static std::uint32_t const POSITION_MASK = 1; @@ -227,10 +227,12 @@ namespace psemek::gfx auto vertex_ptr = s.read_raw(vertex_count * attrs.vertex_size); auto index_count = s.read(); - auto index_ptr = s.read_raw(index_count * sizeof(std::uint32_t)); + auto index_ptr = reinterpret_cast(s.read_raw(index_count * sizeof(std::uint32_t))); - m.setup(attrs); - m.load_raw(vertex_ptr, attrs.vertex_size, vertex_count, index_ptr, gl::UNSIGNED_INT, index_count, gl::TRIANGLES, gl::STATIC_DRAW); + util::span vertices{vertex_ptr, vertex_ptr + vertex_count * attrs.vertex_size}; + util::span indices{index_ptr, index_ptr + index_count}; + + return {attrs, vertices, indices}; } }