vrheights

annotate 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
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@8 49 public:
nuclear@8 50 Mesh();
nuclear@8 51 ~Mesh();
nuclear@8 52
nuclear@8 53 void clear();
nuclear@8 54
nuclear@8 55 void set_primitive(int prim = -1);
nuclear@8 56 void set_attrib_location(int attr, int loc);
nuclear@8 57
nuclear@8 58 float *set_vertex_data(int attr, int nelem, int count, float *data = 0);
nuclear@8 59 unsigned int *set_index_data(int count, unsigned int *data = 0);
nuclear@8 60
nuclear@8 61 int get_vertex_count() const;
nuclear@8 62 float *get_vertex_data(int attr);
nuclear@8 63 const float *get_vertex_data(int attr) const;
nuclear@8 64
nuclear@8 65 int get_index_count() const;
nuclear@8 66 unsigned int *get_index_data();
nuclear@8 67 const unsigned int *get_index_data() const;
nuclear@8 68
nuclear@8 69 int get_face_count() const;
nuclear@8 70 MeshFace get_face(int idx) const;
nuclear@8 71
nuclear@8 72 void begin(int prim = -1);
nuclear@8 73 void end();
nuclear@8 74
nuclear@8 75 void vertex(float x, float y, float z);
nuclear@8 76 void normal(float x, float y, float z);
nuclear@8 77 void texcoord(float x, float y);
nuclear@8 78 void tangent(float x, float y, float z);
nuclear@8 79
nuclear@8 80 void draw() const;
nuclear@8 81 };
nuclear@8 82
nuclear@8 83 #endif // MESH_H_