diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-01-02 15:10:27 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-01-02 15:10:27 +0000 |
commit | 07f478ba964464ff6a6f6bc6855acc8353b4594b (patch) | |
tree | 796d4383c57ae73e4206dfc9acdf542d5e4e4c46 /gfx/models/mesh.cpp | |
parent | Add a traits struct to lookup sizes/type enums for passing to OpenGL (diff) | |
download | ilt-07f478ba964464ff6a6f6bc6855acc8353b4594b.tar.bz2 ilt-07f478ba964464ff6a6f6bc6855acc8353b4594b.tar.xz ilt-07f478ba964464ff6a6f6bc6855acc8353b4594b.zip |
Add helper for configuring vertex array objects/buffers of arbitrary things
Diffstat (limited to 'gfx/models/mesh.cpp')
-rw-r--r-- | gfx/models/mesh.cpp | 27 |
1 files changed, 4 insertions, 23 deletions
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 <cstddef>
-#define offset_ptr(T, m) ((reinterpret_cast<char *>(1)) + offsetof(T, m) - 1)
-
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}
{
- glBindVertexArray(m_vertexArrayObject);
-
- glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffers[0]);
- glBufferData(GL_ARRAY_BUFFER, static_cast<GLsizeiptr>(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<GLsizeiptr>(sizeof(indices[0]) * indices.size()), indices.data(),
- GL_STATIC_DRAW);
-
- glBindVertexArray(0);
+ VertexArrayObject<Vertex>::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);
}
|