diff options
Diffstat (limited to 'gfx')
-rw-r--r-- | gfx/models/mesh.cpp | 13 | ||||
-rw-r--r-- | gfx/models/mesh.h | 16 |
2 files changed, 7 insertions, 22 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
{
diff --git a/gfx/models/mesh.h b/gfx/models/mesh.h index c9f1204..4e6cec8 100644 --- a/gfx/models/mesh.h +++ b/gfx/models/mesh.h @@ -2,30 +2,22 @@ #define MESH_INCLUDED_H
#include <GL/glew.h>
-#include <array>
+#include <glBuffers.h>
+#include <glVertexArrays.h>
#include <memory>
#include <span>
-#include <special_members.hpp>
class Vertex;
-enum MeshBufferPositions { POSITION_VB, TEXCOORD_VB, NORMAL_VB, INDEX_VB };
-
class Mesh {
public:
Mesh(const std::span<const Vertex> vertices, const std::span<const unsigned int> indices, GLenum = GL_TRIANGLES);
- virtual ~Mesh();
-
- NO_COPY(Mesh);
- NO_MOVE(Mesh);
void Draw() const;
private:
- static constexpr unsigned int NUM_BUFFERS {4};
-
- GLuint m_vertexArrayObject;
- std::array<GLuint, NUM_BUFFERS> m_vertexArrayBuffers;
+ glVertexArray m_vertexArrayObject;
+ glBuffers<2> m_vertexArrayBuffers;
GLsizei m_numIndices;
GLenum mode;
};
|