#include #include namespace psemek::gfx { mesh::mesh(mesh && other) : array_{std::move(other.array_)} , vertex_buffer_{std::move(other.vertex_buffer_)} , index_buffer_{std::move(other.index_buffer_)} , instance_buffer_{std::move(other.instance_buffer_)} , info_{other.info_} { other.info_ = mesh_info{}; } mesh & mesh::operator = (mesh && other) { if (this == &other) return *this; array_ = std::move(other.array_); vertex_buffer_ = std::move(other.vertex_buffer_); index_buffer_ = std::move(other.index_buffer_); instance_buffer_ = std::move(other.instance_buffer_); info_ = other.info_; other.info_ = mesh_info{}; return *this; } void mesh::draw() const { draw(0, is_indexed() ? index_count() : vertex_count(), instance_count()); } void mesh::draw(std::size_t first, std::size_t count, std::size_t instance_count) const { if (is_indexed()) { assert(first + count <= index_count()); if (is_instanced()) { assert(instance_count <= this->instance_count()); if (count != 0 && instance_count != 0) { array_.bind(); gl::DrawElementsInstanced(primitive_type(), count, index_type(), reinterpret_cast(detail::index_size(index_type()) * first), instance_count); } } else { if (count != 0) { array_.bind(); gl::DrawElements(primitive_type(), count, index_type(), reinterpret_cast(detail::index_size(index_type()) * first)); } } } else { assert(first + count <= vertex_count()); if (is_instanced()) { assert(instance_count <= this->instance_count()); if (count != 0 && instance_count != 0) { array_.bind(); gl::DrawArraysInstanced(primitive_type(), first, count, instance_count); } } else { if (count != 0) { array_.bind(); gl::DrawArrays(primitive_type(), first, count); } } } } }