vrheights

view src/mesh.h @ 16:7f6d68d95c22

updated to new version of goatvr
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 30 Oct 2015 06:34:31 +0200
parents 3f221bdc9bab
children
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 void update_buffers();
51 public:
52 Mesh();
53 ~Mesh();
55 void clear();
57 void set_primitive(int prim = -1);
58 void set_attrib_location(int attr, int loc);
60 float *set_vertex_data(int attr, int nelem, int count, float *data = 0);
61 unsigned int *set_index_data(int count, unsigned int *data = 0);
63 int get_vertex_count() const;
64 float *get_vertex_data(int attr);
65 const float *get_vertex_data(int attr) const;
67 int get_index_count() const;
68 unsigned int *get_index_data();
69 const unsigned int *get_index_data() const;
71 int get_face_count() const;
72 MeshFace get_face(int idx) const;
74 void begin(int prim = -1);
75 void end();
77 void vertex(float x, float y, float z);
78 void normal(float x, float y, float z);
79 void texcoord(float x, float y);
80 void tangent(float x, float y, float z);
82 void draw() const;
83 };
85 #endif // MESH_H_