summaryrefslogtreecommitdiff
path: root/gfx/models/mesh.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-12-22 14:10:34 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-12-22 14:10:34 +0000
commit20646758939562c0fbad4d52774efcfacf7e22fc (patch)
tree9bd582b749640206a5e38389117d6c931dcf1f5f /gfx/models/mesh.cpp
parentInitial commit with some basic UI (diff)
downloadilt-20646758939562c0fbad4d52774efcfacf7e22fc.tar.bz2
ilt-20646758939562c0fbad4d52774efcfacf7e22fc.tar.xz
ilt-20646758939562c0fbad4d52774efcfacf7e22fc.zip
RAII for glVertex and glBuffer
Diffstat (limited to 'gfx/models/mesh.cpp')
-rw-r--r--gfx/models/mesh.cpp13
1 files changed, 3 insertions, 10 deletions
diff --git a/gfx/models/mesh.cpp b/gfx/models/mesh.cpp
index 82eafbc..28cd021 100644
--- a/gfx/models/mesh.cpp
+++ b/gfx/models/mesh.cpp
@@ -1,17 +1,16 @@
#include "mesh.h"
+#include "glBuffers.h"
+#include "glVertexArrays.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_vertexArrayObject {}, m_vertexArrayBuffers {}, m_numIndices {static_cast<GLsizei>(indices.size())}, mode {m}
+ m_vertexArrayBuffers {}, m_numIndices {static_cast<GLsizei>(indices.size())}, mode {m}
{
- glGenVertexArrays(1, &m_vertexArrayObject);
glBindVertexArray(m_vertexArrayObject);
- glGenBuffers(2, m_vertexArrayBuffers.data());
-
glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffers[0]);
glBufferData(GL_ARRAY_BUFFER, static_cast<GLsizeiptr>(sizeof(Vertex) * vertices.size()), vertices.data(),
GL_STATIC_DRAW);
@@ -32,12 +31,6 @@ Mesh::Mesh(const std::span<const Vertex> vertices, const std::span<const unsigne
glBindVertexArray(0);
}
-Mesh::~Mesh()
-{
- glDeleteBuffers(NUM_BUFFERS, m_vertexArrayBuffers.data());
- glDeleteVertexArrays(1, &m_vertexArrayObject);
-}
-
void
Mesh::Draw() const
{