summaryrefslogtreecommitdiff
path: root/gfx/models/mesh.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-05-10 00:02:50 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-05-10 00:02:50 +0100
commitef00fc9ae1323b64d5e167d04a987887c60c6ec0 (patch)
treea214a04fca7969d5c892422cc462e0bf31e80ee9 /gfx/models/mesh.cpp
parentSupport for tessellation shaders (diff)
downloadilt-ef00fc9ae1323b64d5e167d04a987887c60c6ec0.tar.bz2
ilt-ef00fc9ae1323b64d5e167d04a987887c60c6ec0.tar.xz
ilt-ef00fc9ae1323b64d5e167d04a987887c60c6ec0.zip
Make Mesh into a template to support any vertex type
Customisation point VertexArrayObject to define the layout for the type
Diffstat (limited to 'gfx/models/mesh.cpp')
-rw-r--r--gfx/models/mesh.cpp22
1 files changed, 3 insertions, 19 deletions
diff --git a/gfx/models/mesh.cpp b/gfx/models/mesh.cpp
index a1ce991..1f4dc09 100644
--- a/gfx/models/mesh.cpp
+++ b/gfx/models/mesh.cpp
@@ -1,28 +1,12 @@
#include "mesh.h"
-#include "gfx/gl/vertexArrayObject.h"
#include "glArrays.h"
#include "vertex.h"
#include <cstddef>
-Mesh::Mesh(const std::span<const Vertex> vertices, const std::span<const unsigned int> indices, GLenum m) :
- m_numIndices {static_cast<GLsizei>(indices.size())}, mode {m}
-{
- VertexArrayObject::data(vertices, m_vertexArrayBuffers[0], GL_ARRAY_BUFFER);
- VertexArrayObject::data(indices, m_vertexArrayBuffers[1], GL_ARRAY_BUFFER);
- configureVAO(m_vertexArrayObject);
-}
-
-VertexArrayObject &
-Mesh::configureVAO(VertexArrayObject && vao) const
-{
- return vao
- .addAttribs<Vertex, &Vertex::pos, &Vertex::texCoord, &Vertex::normal, &Vertex::colour, &Vertex::material>(
- m_vertexArrayBuffers[0])
- .addIndices(m_vertexArrayBuffers[1]);
-}
+MeshBase::MeshBase(GLsizei m_numIndices, GLenum mode) : m_numIndices {m_numIndices}, mode {mode} { }
void
-Mesh::Draw() const
+MeshBase::Draw() const
{
glBindVertexArray(m_vertexArrayObject);
@@ -32,7 +16,7 @@ Mesh::Draw() const
}
void
-Mesh::DrawInstanced(GLuint vao, GLsizei count) const
+MeshBase::DrawInstanced(GLuint vao, GLsizei count) const
{
glBindVertexArray(vao);