#pragma once #include "gfx/gl/vertexArrayObject.h" #include #include #include #include class Vertex; class MeshBase { public: void Draw() const; void DrawInstanced(GLuint vao, GLsizei count) const; protected: MeshBase(GLsizei m_numIndices, GLenum mode); glVertexArray m_vertexArrayObject; glBuffers<2> m_vertexArrayBuffers; GLsizei m_numIndices; GLenum mode; }; template class MeshT : public MeshBase, public ConstTypeDefs> { public: MeshT(const std::span vertices, const std::span indices, GLenum mode = GL_TRIANGLES) : MeshBase {static_cast(indices.size()), mode} { VertexArrayObject::data(vertices, m_vertexArrayBuffers[0], GL_ARRAY_BUFFER); VertexArrayObject::data(indices, m_vertexArrayBuffers[1], GL_ARRAY_BUFFER); configureVAO(m_vertexArrayObject); } VertexArrayObject & configureVAO(VertexArrayObject && vao) const { return vao.addAttribsFor(m_vertexArrayBuffers[0]).addIndices(m_vertexArrayBuffers[1]); } }; using Mesh = MeshT;