-
Notifications
You must be signed in to change notification settings - Fork 0
/
mesh.h
73 lines (63 loc) · 2.51 KB
/
mesh.h
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
69
70
71
72
73
#ifndef MESH_H
#define MESH_H
#include <glad/glad.h> // holds all OpenGL type declarations
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include "geometry.h"
#include "shader.h"
#include "texture.h"
#include <string>
#include <vector>
using namespace std;
class Mesh {
public:
// mesh Data
vector<Vertex> vertices;
vector<unsigned int> indices;
unsigned int VAO{};
unsigned int materialIndex{};
// constructor
Mesh() = default;
Mesh(vector<Vertex> vertices, vector<unsigned int> indices, unsigned int materialIndex);
static std::shared_ptr<Mesh> GetUnitCubeInstance(){
if(Mesh::UnitCubeInstance== nullptr){
Mesh::UnitCubeInstance = make_shared<Mesh>();
ComputeBox(Mesh::UnitCubeInstance->vertices,Mesh::UnitCubeInstance->indices,glm::vec3(1),false,false);
Mesh::UnitCubeInstance->SetupGL();
}
return Mesh::UnitCubeInstance;
};
static std::shared_ptr<Mesh> GetUnitSphereInstance(){
if(Mesh::UnitSphereInstance== nullptr){
Mesh::UnitSphereInstance = make_shared<Mesh>();
ComputeSphere(Mesh::UnitSphereInstance->vertices,Mesh::UnitSphereInstance->indices,1,32,false,false);
Mesh::UnitSphereInstance->SetupGL();
}
return Mesh::UnitSphereInstance;
};
static std::shared_ptr<Mesh> GetUnitQuadInstance(){
if(Mesh::UnitSphereInstance== nullptr){
Mesh::UnitQuadInstance = make_shared<Mesh>();
Mesh::UnitQuadInstance->vertices.push_back({glm::vec3(1.0f, 1.0f, 0.0f),glm::vec3(0,0,-1),glm::vec2(1,1)});
Mesh::UnitQuadInstance->vertices.push_back({glm::vec3(1.0f, -1.0f, 0.0f),glm::vec3(0,0,-1),glm::vec2(1,0)});
Mesh::UnitQuadInstance->vertices.push_back({glm::vec3(-1.0f, -1.0f, 0.0f),glm::vec3(0,0,-1),glm::vec2(0,0)});
Mesh::UnitQuadInstance->vertices.push_back({glm::vec3(-1.0f, 1.0f, 0.0f),glm::vec3(0,0,-1),glm::vec2(0,1)});
Mesh::UnitQuadInstance->indices.push_back(0);
Mesh::UnitQuadInstance->indices.push_back(1);
Mesh::UnitQuadInstance->indices.push_back(3);
Mesh::UnitQuadInstance->indices.push_back(1);
Mesh::UnitQuadInstance->indices.push_back(2);
Mesh::UnitQuadInstance->indices.push_back(3);
Mesh::UnitQuadInstance->SetupGL();
}
return Mesh::UnitQuadInstance;
};
// initializes all the buffer objects/arrays
void SetupGL();
void Draw() const;
private:
// render data
unsigned int VBO{}, EBO{};
static std::shared_ptr<Mesh> UnitCubeInstance,UnitSphereInstance,UnitQuadInstance;
};
#endif