vrheights

annotate 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
rev   line source
nuclear@8 1 #ifndef MESH_H_
nuclear@8 2 #define MESH_H_
nuclear@8 3
nuclear@8 4 #include <vector>
nuclear@8 5 #include <vmath/vmath.h>
nuclear@8 6
nuclear@8 7 enum MeshAttrib {
nuclear@8 8 MESH_VERTEX,
nuclear@8 9 MESH_NORMAL,
nuclear@8 10 MESH_TEXCOORD,
nuclear@8 11 MESH_TANGENT,
nuclear@8 12
nuclear@8 13 NUM_MESH_ATTRIBS
nuclear@8 14 };
nuclear@8 15
nuclear@8 16 struct MeshAttribData {
nuclear@8 17 std::vector<float> data;
nuclear@8 18 int nelems;
nuclear@8 19 int sdrloc;
nuclear@8 20
nuclear@8 21 int vbo_size;
nuclear@8 22 unsigned int vbo;
nuclear@8 23 bool vbo_valid;
nuclear@8 24 };
nuclear@8 25
nuclear@8 26 struct MeshFace {
nuclear@8 27 int vcount;
nuclear@8 28 Vector3 v[4];
nuclear@8 29 };
nuclear@8 30
nuclear@8 31 class Mesh {
nuclear@8 32 private:
nuclear@8 33 int prim, prim_verts;
nuclear@8 34 MeshAttribData attrib[NUM_MESH_ATTRIBS];
nuclear@8 35 int num_verts;
nuclear@8 36
nuclear@8 37 std::vector<unsigned int> index;
nuclear@8 38 int num_idx;
nuclear@8 39 unsigned int ibo;
nuclear@8 40 int ibo_size;
nuclear@8 41 bool ibo_valid;
nuclear@8 42
nuclear@8 43 unsigned int vbo_usage, ibo_usage;
nuclear@8 44
nuclear@8 45 Vector3 cur_norm, cur_tang;
nuclear@8 46 Vector2 cur_tc;
nuclear@8 47 bool cur_norm_valid, cur_tc_valid, cur_tang_valid;
nuclear@8 48
nuclear@14 49 void update_buffers();
nuclear@14 50
nuclear@8 51 public:
nuclear@8 52 Mesh();
nuclear@8 53 ~Mesh();
nuclear@8 54
nuclear@8 55 void clear();
nuclear@8 56
nuclear@8 57 void set_primitive(int prim = -1);
nuclear@8 58 void set_attrib_location(int attr, int loc);
nuclear@8 59
nuclear@8 60 float *set_vertex_data(int attr, int nelem, int count, float *data = 0);
nuclear@8 61 unsigned int *set_index_data(int count, unsigned int *data = 0);
nuclear@8 62
nuclear@8 63 int get_vertex_count() const;
nuclear@8 64 float *get_vertex_data(int attr);
nuclear@8 65 const float *get_vertex_data(int attr) const;
nuclear@8 66
nuclear@8 67 int get_index_count() const;
nuclear@8 68 unsigned int *get_index_data();
nuclear@8 69 const unsigned int *get_index_data() const;
nuclear@8 70
nuclear@8 71 int get_face_count() const;
nuclear@8 72 MeshFace get_face(int idx) const;
nuclear@8 73
nuclear@8 74 void begin(int prim = -1);
nuclear@8 75 void end();
nuclear@8 76
nuclear@8 77 void vertex(float x, float y, float z);
nuclear@8 78 void normal(float x, float y, float z);
nuclear@8 79 void texcoord(float x, float y);
nuclear@8 80 void tangent(float x, float y, float z);
nuclear@8 81
nuclear@8 82 void draw() const;
nuclear@8 83 };
nuclear@8 84
nuclear@8 85 #endif // MESH_H_