From 07f478ba964464ff6a6f6bc6855acc8353b4594b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 2 Jan 2023 15:10:27 +0000 Subject: Add helper for configuring vertex array objects/buffers of arbitrary things --- gfx/models/mesh.cpp | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) (limited to 'gfx/models') diff --git a/gfx/models/mesh.cpp b/gfx/models/mesh.cpp index f13e242..85be84c 100644 --- a/gfx/models/mesh.cpp +++ b/gfx/models/mesh.cpp @@ -1,33 +1,14 @@ #include "mesh.h" +#include "gfx/gl/vertexArrayObject.hpp" #include "glArrays.h" #include "vertex.hpp" #include -#define offset_ptr(T, m) ((reinterpret_cast(1)) + offsetof(T, m) - 1) - Mesh::Mesh(const std::span vertices, const std::span indices, GLenum m) : m_numIndices {static_cast(indices.size())}, mode {m} { - glBindVertexArray(m_vertexArrayObject); - - glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffers[0]); - glBufferData(GL_ARRAY_BUFFER, static_cast(sizeof(Vertex) * vertices.size()), vertices.data(), - GL_STATIC_DRAW); - - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), offset_ptr(Vertex, pos)); - - glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), offset_ptr(Vertex, texCoord)); - - glEnableVertexAttribArray(2); - glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), offset_ptr(Vertex, normal)); - - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_vertexArrayBuffers[1]); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, static_cast(sizeof(indices[0]) * indices.size()), indices.data(), - GL_STATIC_DRAW); - - glBindVertexArray(0); + VertexArrayObject::configure<&Vertex::pos, &Vertex::texCoord, &Vertex::normal>( + m_vertexArrayObject, m_vertexArrayBuffers[0], m_vertexArrayBuffers[1], vertices, indices); } void @@ -35,7 +16,7 @@ Mesh::Draw() const { glBindVertexArray(m_vertexArrayObject); - glDrawElementsBaseVertex(mode, m_numIndices, GL_UNSIGNED_INT, nullptr, 0); + glDrawElements(mode, m_numIndices, GL_UNSIGNED_INT, nullptr); glBindVertexArray(0); } -- cgit v1.2.3