#pragma once #include #include #include #include #include #include "../Common/Sizes.hpp" #include "../Math/Common.hpp" namespace MC::GFX { class Mesh { public: struct Attribute { template Attribute( std::vector v ) : data_size(v.size()), attribute_size(1), type_size(sizeof(T)) { data = copy(v.data(), v.size() * type_size); } template Attribute( std::vector> v ) : data_size(v.size()), attribute_size(S), type_size(sizeof(T)) { data = copy(v.data(), v.size() * S * type_size); } Attribute( const Attribute& other ) : data(copy(other.data, other.data_size * other.attribute_size * other.type_size)), data_size(other.data_size), attribute_size(other.attribute_size), type_size(other.type_size) {} static void* copy(void* ptr, U32 size) { auto* buffer = new U8[size]; std::copy_n((U8*)ptr, size, buffer); return buffer; } void* data; USize data_size; USize attribute_size; USize type_size; }; Mesh( std::vector attributes, std::vector indices ) : m_attributes(std::move(attributes)), m_indices(std::move(indices)) {} explicit Mesh( std::vector attributes ) : m_attributes(std::move(attributes)) {} USize size() const; void bind(); void unbind() const; private: void upload(); static GLuint create_vao(); static void unbind_vao(); static void store_in_attribute_list(U32 attribute, Int attribute_size, Int type_size, const void* data, long data_size); static void store_indices(const U32* indices, USize indices_size); std::vector m_attributes; std::vector m_indices; std::optional m_vao; }; }