summaryrefslogtreecommitdiff
path: root/gfx/models/mesh.h
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/models/mesh.h')
-rw-r--r--gfx/models/mesh.h30
1 files changed, 24 insertions, 6 deletions
diff --git a/gfx/models/mesh.h b/gfx/models/mesh.h
index f022c2a..972fe30 100644
--- a/gfx/models/mesh.h
+++ b/gfx/models/mesh.h
@@ -1,5 +1,6 @@
#pragma once
+#include "gfx/gl/vertexArrayObject.h"
#include <GL/glew.h>
#include <glArrays.h>
#include <memory>
@@ -7,19 +8,36 @@
#include <stdTypeDefs.h>
class Vertex;
-class VertexArrayObject;
-class Mesh : public ConstTypeDefs<Mesh> {
+class MeshBase {
public:
- Mesh(const std::span<const Vertex> vertices, const std::span<const unsigned int> indices, GLenum = GL_TRIANGLES);
-
void Draw() const;
void DrawInstanced(GLuint vao, GLsizei count) const;
- VertexArrayObject & configureVAO(VertexArrayObject &&) const;
-private:
+protected:
+ MeshBase(GLsizei m_numIndices, GLenum mode);
+
glVertexArray m_vertexArrayObject;
glBuffers<2> m_vertexArrayBuffers;
GLsizei m_numIndices;
GLenum mode;
};
+
+template<typename V> class MeshT : public MeshBase, public ConstTypeDefs<MeshT<V>> {
+public:
+ MeshT(const std::span<const V> vertices, const std::span<const unsigned int> indices, GLenum mode = GL_TRIANGLES) :
+ MeshBase {static_cast<GLsizei>(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<V>(m_vertexArrayBuffers[0]).addIndices(m_vertexArrayBuffers[1]);
+ }
+};
+
+using Mesh = MeshT<Vertex>;