summaryrefslogtreecommitdiff
path: root/gfx/models/mesh.h
blob: 498214521148abf1c064c4a7fef78d106e016f64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef MESH_INCLUDED_H
#define MESH_INCLUDED_H

#include <GL/glew.h>
#include <array>
#include <cstddef>
#include <filesystem>
#include <gfx/models/vertex.hpp>
#include <span>
#include <special_members.hpp>
#include <utility>
#include <vector>

class ObjParser;

enum MeshBufferPositions { POSITION_VB, TEXCOORD_VB, NORMAL_VB, INDEX_VB };

class Mesh {
public:
	using Data = std::pair<std::vector<Vertex>, std::vector<unsigned int>>;
	explicit Mesh(const std::filesystem::path & fileName);
	explicit Mesh(const ObjParser & obj);
	Mesh(std::span<Vertex> vertices, std::span<unsigned int> indices, GLenum = GL_TRIANGLES);
	virtual ~Mesh();

	NO_COPY(Mesh);
	NO_MOVE(Mesh);

	void Draw() const;

private:
	explicit Mesh(Data && vandi, GLenum = GL_TRIANGLES);

	static Data packObjParser(const ObjParser &);

	static constexpr unsigned int NUM_BUFFERS {4};

	GLuint m_vertexArrayObject;
	std::array<GLuint, NUM_BUFFERS> m_vertexArrayBuffers;
	size_t m_numIndices;
	GLenum mode;
};

#endif