Support binding gfx::mesh

This commit is contained in:
Nikita Lisitsa 2020-10-24 19:39:28 +03:00
parent d9f06efb57
commit 131f06b012
2 changed files with 12 additions and 5 deletions

View file

@ -115,6 +115,8 @@ namespace psemek::gfx
mesh(mesh const &) = delete; mesh(mesh const &) = delete;
mesh & operator = (mesh const &) = delete; mesh & operator = (mesh const &) = delete;
void bind() const;
void setup(attribs_description const & attribs); void setup(attribs_description const & attribs);
template <typename ... Attribs> template <typename ... Attribs>

View file

@ -29,11 +29,16 @@ namespace psemek::gfx
return *this; return *this;
} }
void mesh::bind() const
{
array_.bind();
}
void mesh::setup(attribs_description const & attribs) void mesh::setup(attribs_description const & attribs)
{ {
assert(!attribs.attribs.empty()); assert(!attribs.attribs.empty());
array_.bind(); bind();
for (std::size_t i = 0; i < info_.max_attribute_index_; ++i) for (std::size_t i = 0; i < info_.max_attribute_index_; ++i)
gl::DisableVertexAttribArray(i); gl::DisableVertexAttribArray(i);
@ -108,7 +113,7 @@ namespace psemek::gfx
if (count != 0 && instance_count != 0) if (count != 0 && instance_count != 0)
{ {
array_.bind(); bind();
gl::DrawElementsInstanced(primitive_type(), count, index_type(), reinterpret_cast<char const *>(detail::index_size(index_type()) * first), instance_count); gl::DrawElementsInstanced(primitive_type(), count, index_type(), reinterpret_cast<char const *>(detail::index_size(index_type()) * first), instance_count);
} }
} }
@ -116,7 +121,7 @@ namespace psemek::gfx
{ {
if (count != 0) if (count != 0)
{ {
array_.bind(); bind();
gl::DrawElements(primitive_type(), count, index_type(), reinterpret_cast<char const *>(detail::index_size(index_type()) * first)); gl::DrawElements(primitive_type(), count, index_type(), reinterpret_cast<char const *>(detail::index_size(index_type()) * first));
} }
} }
@ -131,7 +136,7 @@ namespace psemek::gfx
if (count != 0 && instance_count != 0) if (count != 0 && instance_count != 0)
{ {
array_.bind(); bind();
gl::DrawArraysInstanced(primitive_type(), first, count, instance_count); gl::DrawArraysInstanced(primitive_type(), first, count, instance_count);
} }
} }
@ -139,7 +144,7 @@ namespace psemek::gfx
{ {
if (count != 0) if (count != 0)
{ {
array_.bind(); bind();
gl::DrawArrays(primitive_type(), first, count); gl::DrawArrays(primitive_type(), first, count);
} }
} }