-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmesh.h
82 lines (64 loc) · 1.7 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
#ifndef MESH_H
#define MESH_H
/* Mesh asset: a indexed, triangular Mesh
*
* Used for rendering only (graphic coating).
*
* Like many assets, two classes:
* - CpuMesh ("stored in system ram")
* - GpuMesh ("stored in graphic card RAM")
*
* MeshComponent:
* - a mesh + a texture (will be: a material) + a transform
*
*/
#include <glm/vec3.hpp>
#include <glm/vec2.hpp>
#include <vector>
using namespace glm;
#include "transform.h"
#include "texture.h"
struct Vertex{
vec3 pos;
vec3 norm;
vec2 uv;
};
struct Tri{
int i,j,k;
Tri(int _i, int _j, int _k):i(_i),j(_j),k(_k){}
};
/* (ids of) a mesh structure in GPU ram */
struct GpuMesh{
void render() const;
uint geomBufferId = 666; // "name" of GPU buffer for vertices
uint connBufferId = 666; // "name" of GPU buffer for triangles
int nElements = 0;
};
/* a mesh structure in CPU ram */
struct CpuMesh{
std::vector< Vertex > verts;
std::vector< Tri > tris;
bool import(const std::string& filename);
void renderDeprecated(); // uses immediate mode
// todo: a bit of geometry processing...
void updateNormals();
void resize( float scale );
void flipYZ();
void apply(Transform t);
// procedural constructions..
void buildTorus(int ni, int nj, float innerRadius, float outerRadius);
GpuMesh uploadToGPU();
private:
void addQuad(int i, int j, int k, int h);
};
struct MeshComponent{
Transform t; /* local trasform, for the looks only
* useful for: convert unity of measures between assets and game,
* add small "graphic only" animations,
* fix axis orientations between assets and game
*/
GpuTexture texture; // TODO: meglio un MATERIAL (che contiene una GpuTexture)
GpuMesh mesh;
// textures, materials...
};
#endif // MESH_H