diff --git a/libs/gfx/include/psemek/gfx/attribs.hpp b/libs/gfx/include/psemek/gfx/attribs.hpp index e2d91997..57ab373f 100644 --- a/libs/gfx/include/psemek/gfx/attribs.hpp +++ b/libs/gfx/include/psemek/gfx/attribs.hpp @@ -24,7 +24,22 @@ namespace psemek::gfx GLuint divisor; }; - using attribs_description = std::vector; + struct attribs_description + { + std::vector attribs; + GLuint index_count; + }; + + inline attribs_description operator + (attribs_description d1, attribs_description const & d2) + { + for (auto a : d2.attribs) + { + a.index += d1.index_count; + d1.attribs.push_back(a); + } + d1.index_count += d2.index_count; + return d1; + } template struct normalized @@ -283,8 +298,10 @@ namespace psemek::gfx static void make(attribs_description &) {} - static void make_impl(attribs_description &, std::size_t, std::size_t, std::size_t) - { } + static void make_impl(attribs_description & result, std::size_t index, std::size_t, std::size_t) + { + result.index_count = index; + } }; template @@ -326,7 +343,7 @@ namespace psemek::gfx attr.pointer = reinterpret_cast(offset + row * attr::columns * sizeof(T)); attr.divisor = Instance ? 1 : 0; - result.push_back(attr); + result.attribs.push_back(attr); } make_attribs_description_impl::make_impl(result, index + attr::rows, offset + attr_size(), stride); @@ -345,7 +362,7 @@ namespace psemek::gfx attr.pointer = reinterpret_cast(offset); attr.divisor = Instance ? 1 : 0; - result.push_back(attr); + result.attribs.push_back(attr); make_attribs_description_impl::make_impl(result, index + 1, offset + attr_size(), stride); } diff --git a/libs/gfx/source/mesh.cpp b/libs/gfx/source/mesh.cpp index 2d61cbfd..99387889 100644 --- a/libs/gfx/source/mesh.cpp +++ b/libs/gfx/source/mesh.cpp @@ -31,7 +31,7 @@ namespace psemek::gfx void mesh::setup(attribs_description const & attribs) { - assert(!attribs.empty()); + assert(!attribs.attribs.empty()); array_.bind(); @@ -43,7 +43,7 @@ namespace psemek::gfx std::size_t stride = 0; std::size_t instance_stride = 0; - for (auto const & a : attribs) + for (auto const & a : attribs.attribs) { max_index = std::max(max_index, a.index); @@ -67,7 +67,7 @@ namespace psemek::gfx if (!vertex_buffer_) vertex_buffer_ = buffer{}; vertex_buffer_.bind(); - for (auto const & a : attribs) + for (auto const & a : attribs.attribs) { if (a.divisor != 0) continue; @@ -80,7 +80,7 @@ namespace psemek::gfx if (!instance_buffer_) instance_buffer_ = buffer{}; instance_buffer_.bind(); - for (auto const & a : attribs) + for (auto const & a : attribs.attribs) { if (a.divisor == 0) continue;