-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMesh.h
124 lines (90 loc) · 2.78 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#ifndef _Mesh_H_
#define _Mesh_H_
/*
Mesh: One Mesh, One Texture, One Shader
MAYBE DO:
1. Multiple Texture Support
2. Map<Texture, Shader>
*/
#include <string>
#include <vector>
#include <glm/glm.hpp>
#include <memory>
#include "Shader.h"
#include "GLFunctions.h"
#define MAX_NUM_OF_INDICES 2147483647
enum class MESH_TYPE
{
STATIC,
DYNAMIC,
STREAM
};
class Mesh : public std::enable_shared_from_this<Mesh>
{
public:
Mesh();
Mesh(const Mesh&);
~Mesh();
bool Initialize(std::shared_ptr<Shader> shader);
void Release();
void Render();
//void Update();
/*Set VAO and VBO (including GenBuffer)*/
void SetupGLBuffers();
/*
bool LoadFromFile(std::string path);
bool LoadFromFileAssimp(std::string path);
*/
void ComputeSmoothNormal(unsigned int normal_type);
//reset functions (Large changes)
void ResetPositions(std::vector<glm::vec3>& pos);
void ResetNormals(std::vector<glm::vec3>& normals);
void ResetTexCoord(std::vector<glm::vec2>& texcoords);
void ResetIndices(std::vector<unsigned int>& indices);
//setter
void setPositions(std::vector<glm::vec3> pos);
void setNormals(std::vector<glm::vec3>& normals);
void setTexCoord(std::vector<glm::vec2>& texcoords);
void setIndices(std::vector<unsigned int>& indices);
void setShader(std::shared_ptr<Shader> shader);
//void setRenderOption(RENDER_ENUM render_option);
void setName(std::string name);
// getters
inline std::vector<unsigned int>& getIndices() { return m_indices; };
inline std::vector<glm::vec3>& getPositions() { return m_positions; };
inline std::string getName() { return m_name; };
inline const std::shared_ptr<Shader>& getShader() { return m_shader; };
inline const GLuint& getShaderProgram() { return m_shader->getProgram(); };
inline const size_t getNumberOfIndices() { return m_indices.size(); };
inline const GLuint& getVAO() { return m_vao; };
inline const GLuint& getEBO() { return m_ebo; };
GLuint textureID;
protected: // for inheritance? why use protected?
// Basic attributes
std::vector<glm::vec3> m_positions;
std::vector<glm::vec3> m_normals;
std::vector<unsigned int> m_indices;
std::vector<glm::vec3> m_colors;
std::vector<glm::vec2> m_texcoord;
std::shared_ptr<Shader> m_shader;
std::vector<unsigned int> m_triangleNormalIndex;
bool m_useSmoothNormal;
std::string m_name;
// OpenGL parameters
GLuint m_vao; //vertex buffer
GLuint m_vbo[3]; //pos, normal, text
GLuint m_ebo; // element buffer -- indices
private:
//RENDER_ENUM m_render_option;
/*Upload all VBO datas*/
void UploadToGPU();
/* OpenGL VBO/EBO update */
void UpdatePositions();
void UpdateNormals();
void UpdateTextcoords();
void UpdateIndices();
void ComputeVNormalByFace();
void ComputeVNormalByEdge();
void RegistToManager();
};
#endif