Support merging attrib descriptions
This commit is contained in:
parent
e5c869f27b
commit
ec36942f7d
2 changed files with 26 additions and 9 deletions
|
|
@ -24,7 +24,22 @@ namespace psemek::gfx
|
|||
GLuint divisor;
|
||||
};
|
||||
|
||||
using attribs_description = std::vector<attrib_description>;
|
||||
struct attribs_description
|
||||
{
|
||||
std::vector<attrib_description> 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 <typename T>
|
||||
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 <bool Instance, typename Attr1, typename ... Attribs>
|
||||
|
|
@ -326,7 +343,7 @@ namespace psemek::gfx
|
|||
attr.pointer = reinterpret_cast<char const *>(offset + row * attr::columns * sizeof(T));
|
||||
attr.divisor = Instance ? 1 : 0;
|
||||
|
||||
result.push_back(attr);
|
||||
result.attribs.push_back(attr);
|
||||
}
|
||||
|
||||
make_attribs_description_impl<Instance, Attribs...>::make_impl(result, index + attr::rows, offset + attr_size<Attr1>(), stride);
|
||||
|
|
@ -345,7 +362,7 @@ namespace psemek::gfx
|
|||
attr.pointer = reinterpret_cast<char const *>(offset);
|
||||
attr.divisor = Instance ? 1 : 0;
|
||||
|
||||
result.push_back(attr);
|
||||
result.attribs.push_back(attr);
|
||||
|
||||
make_attribs_description_impl<Instance, Attribs...>::make_impl(result, index + 1, offset + attr_size<Attr1>(), stride);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<std::size_t>(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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue