vrheights

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/mesh.h	Fri Oct 03 04:16:16 2014 +0300
     1.3 @@ -0,0 +1,83 @@
     1.4 +#ifndef MESH_H_
     1.5 +#define MESH_H_
     1.6 +
     1.7 +#include <vector>
     1.8 +#include <vmath/vmath.h>
     1.9 +
    1.10 +enum MeshAttrib {
    1.11 +	MESH_VERTEX,
    1.12 +	MESH_NORMAL,
    1.13 +	MESH_TEXCOORD,
    1.14 +	MESH_TANGENT,
    1.15 +
    1.16 +	NUM_MESH_ATTRIBS
    1.17 +};
    1.18 +
    1.19 +struct MeshAttribData {
    1.20 +	std::vector<float> data;
    1.21 +	int nelems;
    1.22 +	int sdrloc;
    1.23 +
    1.24 +	int vbo_size;
    1.25 +	unsigned int vbo;
    1.26 +	bool vbo_valid;
    1.27 +};
    1.28 +
    1.29 +struct MeshFace {
    1.30 +	int vcount;
    1.31 +	Vector3 v[4];
    1.32 +};
    1.33 +
    1.34 +class Mesh {
    1.35 +private:
    1.36 +	int prim, prim_verts;
    1.37 +	MeshAttribData attrib[NUM_MESH_ATTRIBS];
    1.38 +	int num_verts;
    1.39 +
    1.40 +	std::vector<unsigned int> index;
    1.41 +	int num_idx;
    1.42 +	unsigned int ibo;
    1.43 +	int ibo_size;
    1.44 +	bool ibo_valid;
    1.45 +
    1.46 +	unsigned int vbo_usage, ibo_usage;
    1.47 +
    1.48 +	Vector3 cur_norm, cur_tang;
    1.49 +	Vector2 cur_tc;
    1.50 +	bool cur_norm_valid, cur_tc_valid, cur_tang_valid;
    1.51 +
    1.52 +public:
    1.53 +	Mesh();
    1.54 +	~Mesh();
    1.55 +
    1.56 +	void clear();
    1.57 +
    1.58 +	void set_primitive(int prim = -1);
    1.59 +	void set_attrib_location(int attr, int loc);
    1.60 +
    1.61 +	float *set_vertex_data(int attr, int nelem, int count, float *data = 0);
    1.62 +	unsigned int *set_index_data(int count, unsigned int *data = 0);
    1.63 +
    1.64 +	int get_vertex_count() const;
    1.65 +	float *get_vertex_data(int attr);
    1.66 +	const float *get_vertex_data(int attr) const;
    1.67 +
    1.68 +	int get_index_count() const;
    1.69 +	unsigned int *get_index_data();
    1.70 +	const unsigned int *get_index_data() const;
    1.71 +
    1.72 +	int get_face_count() const;
    1.73 +	MeshFace get_face(int idx) const;
    1.74 +
    1.75 +	void begin(int prim = -1);
    1.76 +	void end();
    1.77 +
    1.78 +	void vertex(float x, float y, float z);
    1.79 +	void normal(float x, float y, float z);
    1.80 +	void texcoord(float x, float y);
    1.81 +	void tangent(float x, float y, float z);
    1.82 +
    1.83 +	void draw() const;
    1.84 +};
    1.85 +
    1.86 +#endif	// MESH_H_