-
Notifications
You must be signed in to change notification settings - Fork 0
/
mesh.hpp
47 lines (33 loc) · 1.39 KB
/
mesh.hpp
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
/*
mesh.hpp
author: Telo PHILIPPE
A Mesh class, to load and render meshes, with proper deletion.
Also a function to generate a cube sphere mesh.
*/
#ifndef MESH_H
#define MESH_H
#include "gl_includes.hpp"
#include <memory>
#include <vector>
class Mesh {
public:
void initGPUGeometry(const std::vector<float> &vertexPositions, const std::vector<float> &vertexNormals, const std::vector<float> &vertexUVs, const std::vector<unsigned int> &triangleIndices);
void setGPUGeometry(GLuint posVbo, GLuint normalVbo, GLuint uvVbo, GLuint ibo, GLuint vao, size_t numIndices);
void render() const;
static std::shared_ptr<Mesh> genSphere(const size_t resolution = 16); // Should generate a unit sphere
static std::shared_ptr<Mesh> genPlane(); // Should generate a unit plane
static std::shared_ptr<Mesh> genSubdividedPlane(int resolution); // Should generate a unit plane
void bind() const {
glBindVertexArray(m_vao);
}
~Mesh();
GLuint m_vao = 0;
size_t m_numIndices = 0;
private:
GLuint m_posVbo = 0;
GLuint m_normalVbo = 0;
GLuint m_uvVbo = 0;
GLuint m_ibo = 0;
static void genFace(std::vector<float>& vertexPositions, std::vector<float>& vertexNormals, std::vector<float> &vertexUVs, std::vector<unsigned int>& triangleIndices, const size_t resolution, const glm::vec3& dir1, const glm::vec3& dir2);
};
#endif // MESH_H