vrheights

view src/mesh.h @ 8:3f221bdc9bab

mesh loading walk polys
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 03 Oct 2014 04:16:16 +0300
parents
children 25cab9e20c9c
line source
1 #ifndef MESH_H_
2 #define MESH_H_
4 #include <vector>
5 #include <vmath/vmath.h>
7 enum MeshAttrib {
8 MESH_VERTEX,
9 MESH_NORMAL,
10 MESH_TEXCOORD,
11 MESH_TANGENT,
13 NUM_MESH_ATTRIBS
14 };
16 struct MeshAttribData {
17 std::vector<float> data;
18 int nelems;
19 int sdrloc;
21 int vbo_size;
22 unsigned int vbo;
23 bool vbo_valid;
24 };
26 struct MeshFace {
27 int vcount;
28 Vector3 v[4];
29 };
31 class Mesh {
32 private:
33 int prim, prim_verts;
34 MeshAttribData attrib[NUM_MESH_ATTRIBS];
35 int num_verts;
37 std::vector<unsigned int> index;
38 int num_idx;
39 unsigned int ibo;
40 int ibo_size;
41 bool ibo_valid;
43 unsigned int vbo_usage, ibo_usage;
45 Vector3 cur_norm, cur_tang;
46 Vector2 cur_tc;
47 bool cur_norm_valid, cur_tc_valid, cur_tang_valid;
49 public:
50 Mesh();
51 ~Mesh();
53 void clear();
55 void set_primitive(int prim = -1);
56 void set_attrib_location(int attr, int loc);
58 float *set_vertex_data(int attr, int nelem, int count, float *data = 0);
59 unsigned int *set_index_data(int count, unsigned int *data = 0);
61 int get_vertex_count() const;
62 float *get_vertex_data(int attr);
63 const float *get_vertex_data(int attr) const;
65 int get_index_count() const;
66 unsigned int *get_index_data();
67 const unsigned int *get_index_data() const;
69 int get_face_count() const;
70 MeshFace get_face(int idx) const;
72 void begin(int prim = -1);
73 void end();
75 void vertex(float x, float y, float z);
76 void normal(float x, float y, float z);
77 void texcoord(float x, float y);
78 void tangent(float x, float y, float z);
80 void draw() const;
81 };
83 #endif // MESH_H_