summaryrefslogtreecommitdiff
path: root/mesh.h
blob: aceaafe4cc25b2905ccc265a272e16e24ee8e4d1 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef MESH_INCLUDED_H
#define MESH_INCLUDED_H

#include "obj_loader.h"
#include <GL/glew.h>
#include <glm/glm.hpp>
#include <string>
#include <vector>

struct Vertex {
public:
	Vertex(const glm::vec3 & pos, const glm::vec2 & texCoord, const glm::vec3 & normal)
	{
		this->pos = pos;
		this->texCoord = texCoord;
		this->normal = normal;
	}

	glm::vec3 *
	GetPos()
	{
		return &pos;
	}
	glm::vec2 *
	GetTexCoord()
	{
		return &texCoord;
	}
	glm::vec3 *
	GetNormal()
	{
		return &normal;
	}

private:
	glm::vec3 pos;
	glm::vec2 texCoord;
	glm::vec3 normal;
};

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

class Mesh {
public:
	Mesh(const std::string & fileName);
	Mesh(Vertex * vertices, unsigned int numVertices, unsigned int * indices, unsigned int numIndices);

	void Draw();

	virtual ~Mesh();

protected:
private:
	static const unsigned int NUM_BUFFERS = 4;
	void
	operator=(const Mesh & mesh)
	{
	}
	Mesh(const Mesh & mesh) { }

	void InitMesh(const IndexedModel & model);

	GLuint m_vertexArrayObject;
	GLuint m_vertexArrayBuffers[NUM_BUFFERS];
	unsigned int m_numIndices;
};

#endif