b0a0a4bf063b23f9d9a50cee57dbb925e3a481d1
[vrlugburz] / src / mesh.h
1 #ifndef MESH_H_
2 #define MESH_H_
3
4 #include "cgmath/cgmath.h"
5 #include "geom.h"
6
7 enum {
8         MESH_ATTR_VERTEX,
9         MESH_ATTR_NORMAL,
10         MESH_ATTR_TANGENT,
11         MESH_ATTR_TEXCOORD
12 };
13
14 struct vertex {
15         cgm_vec3 pos;
16         cgm_vec3 norm;
17         cgm_vec3 tang;
18         cgm_vec2 tex;
19 };
20
21 enum {
22         TEX_DIFFUSE,
23         TEX_SPECULAR,
24         TEX_NORMAL,
25
26         NUM_TEX_SLOTS
27 };
28
29 struct material {
30         char *name;
31
32         cgm_vec3 color;
33         cgm_vec3 spec;
34         float shininess;
35
36         unsigned int tex[NUM_TEX_SLOTS];
37
38         struct material *next;
39 };
40
41 struct mesh {
42         struct vertex *varr;
43         unsigned int *iarr;
44         int num_verts, num_idx;
45         int max_verts, max_idx;
46
47         struct material *mtl;
48
49         struct aabox bb;
50         int bbvalid;
51
52         unsigned int vbo, ibo;
53         int vbovalid;
54
55         struct mesh *next;
56 };
57
58 struct meshgroup {
59         struct mesh **meshes;
60         int num_meshes, max_meshes;
61
62         struct aabox bb;
63         int bbvalid;
64
65         int num_verts, num_idx;
66         unsigned int vbo, ibo;
67         int vbovalid;
68 };
69
70 void init_mesh(struct mesh *m);
71 void destroy_mesh(struct mesh *m);
72 void clear_mesh(struct mesh *m);
73
74 void init_meshgroup(struct meshgroup *mg);
75 void destroy_meshgroup(struct meshgroup *mg);
76 void clear_meshgroup(struct meshgroup *mg);
77
78 void calc_mesh_bounds(struct mesh *m);
79
80 int add_mesh_vertex(struct mesh *m, struct vertex *v);
81 int add_mesh_index(struct mesh *m, int idx);
82 int add_mesh_face(struct mesh *m, int va, int vb, int vc);
83
84 int add_meshgroup_mesh(struct meshgroup *mg, struct mesh *m);
85
86 void draw_mesh(struct mesh *m);
87 void draw_meshgroup(struct meshgroup *mg);
88
89 #endif  /* MESH_H_ */