5 #include "cgmath/cgmath.h"
13 CMESH_ATTR_BONEWEIGHTS,
32 struct cmesh_texture {
37 struct cmesh_material {
39 cgm_vec3 color, specular, emissive;
42 struct cmesh_texture tex[CMESH_NUM_TEX];
46 void cmesh_set_attrib_sdrloc(int attr, int loc);
47 int cmesh_get_attrib_sdrloc(int attr);
48 void cmesh_clear_attrib_sdrloc(void);
50 /* cmesh_bind_sdrloc will bind default attribute names (if they exist in the
51 * shader program) to locations used by cmesh_draw:
52 * attr_vertex, attr_normal, attr_tangent, attr_texcoord, attr_color,
53 * attr_boneweights, attr_boneidx, attr_texcoord2
55 void cmesh_bind_sdrloc(unsigned int sdr);
58 struct cmesh *cmesh_alloc(void);
59 void cmesh_free(struct cmesh *cm);
61 int cmesh_init(struct cmesh *cm);
62 void cmesh_destroy(struct cmesh *cm);
64 void cmesh_clear(struct cmesh *cm);
65 int cmesh_clone(struct cmesh *cmdest, struct cmesh *cmsrc);
67 int cmesh_set_name(struct cmesh *cm, const char *name);
68 const char *cmesh_name(struct cmesh *cm);
70 struct cmesh_material *cmesh_material(struct cmesh *cm);
71 struct cmesh_material *cmesh_submesh_material(struct cmesh *cm, int subidx);
72 int cmesh_load_textures(struct cmesh *cm);
74 int cmesh_has_attrib(struct cmesh *cm, int attr);
75 int cmesh_indexed(struct cmesh *cm);
77 /* vdata can be 0, in which case only memory is allocated
78 * returns pointer to the attribute array
80 float *cmesh_set_attrib(struct cmesh *cm, int attr, int nelem, unsigned int num,
82 float *cmesh_attrib(struct cmesh *cm, int attr); /* invalidates VBO */
83 const float *cmesh_attrib_ro(struct cmesh *cm, int attr); /* doesn't invalidate */
84 float *cmesh_attrib_at(struct cmesh *cm, int attr, int idx);
85 const float *cmesh_attrib_at_ro(struct cmesh *cm, int attr, int idx);
86 int cmesh_attrib_count(struct cmesh *cm, int attr);
87 int cmesh_push_attrib(struct cmesh *cm, int attr, float *v);
88 int cmesh_push_attrib1f(struct cmesh *cm, int attr, float x);
89 int cmesh_push_attrib2f(struct cmesh *cm, int attr, float x, float y);
90 int cmesh_push_attrib3f(struct cmesh *cm, int attr, float x, float y, float z);
91 int cmesh_push_attrib4f(struct cmesh *cm, int attr, float x, float y, float z, float w);
93 /* indices can be 0, in which case only memory is allocated
94 * returns pointer to the index array
96 unsigned int *cmesh_set_index(struct cmesh *cm, int num, const unsigned int *indices);
97 unsigned int *cmesh_index(struct cmesh *cm); /* invalidates IBO */
98 const unsigned int *cmesh_index_ro(struct cmesh *cm); /* doesn't invalidate */
99 int cmesh_index_count(struct cmesh *cm);
100 int cmesh_push_index(struct cmesh *cm, unsigned int idx);
102 int cmesh_poly_count(struct cmesh *cm);
104 /* attr can be -1 to invalidate all attributes */
105 void cmesh_invalidate_vbo(struct cmesh *cm, int attr);
106 void cmesh_invalidate_ibo(struct cmesh *cm);
108 int cmesh_append(struct cmesh *cmdest, struct cmesh *cmsrc);
111 void cmesh_clear_submeshes(struct cmesh *cm);
112 /* a submesh is defined as a consecutive range of faces */
113 int cmesh_submesh(struct cmesh *cm, const char *name, int fstart, int fcount);
114 int cmesh_remove_submesh(struct cmesh *cm, int idx);
115 int cmesh_find_submesh(struct cmesh *cm, const char *name);
116 int cmesh_submesh_count(struct cmesh *cm);
117 int cmesh_clone_submesh(struct cmesh *cmdest, struct cmesh *cm, int subidx);
118 const char *cmesh_submesh_name(struct cmesh *cm, int idx);
120 /* immediate-mode style mesh construction interface */
121 int cmesh_vertex(struct cmesh *cm, float x, float y, float z);
122 void cmesh_normal(struct cmesh *cm, float nx, float ny, float nz);
123 void cmesh_tangent(struct cmesh *cm, float tx, float ty, float tz);
124 void cmesh_texcoord(struct cmesh *cm, float u, float v, float w);
125 void cmesh_boneweights(struct cmesh *cm, float w1, float w2, float w3, float w4);
126 void cmesh_boneidx(struct cmesh *cm, int idx1, int idx2, int idx3, int idx4);
128 /* dir_xform can be null, in which case it's calculated from xform */
129 void cmesh_apply_xform(struct cmesh *cm, float *xform, float *dir_xform);
131 void cmesh_flip(struct cmesh *cm); /* flip faces (winding) and normals */
132 void cmesh_flip_faces(struct cmesh *cm);
133 void cmesh_flip_normals(struct cmesh *cm);
135 int cmesh_explode(struct cmesh *cm); /* undo all vertex sharing */
137 /* this is only guaranteed to work on an exploded mesh */
138 void cmesh_calc_face_normals(struct cmesh *cm);
140 void cmesh_draw(struct cmesh *cm);
141 void cmesh_draw_range(struct cmesh *cm, int start, int count);
142 void cmesh_draw_submesh(struct cmesh *cm, int subidx); /* XXX only for indexed meshes currently */
143 void cmesh_draw_wire(struct cmesh *cm, float linesz);
144 void cmesh_draw_vertices(struct cmesh *cm, float ptsz);
145 void cmesh_draw_normals(struct cmesh *cm, float len);
146 void cmesh_draw_tangents(struct cmesh *cm, float len);
148 /* get the bounding box in local space. The result will be cached and subsequent
149 * calls will return the same box. The cache gets invalidated by any functions that
150 * can affect the vertex data
152 void cmesh_aabbox(struct cmesh *cm, cgm_vec3 *vmin, cgm_vec3 *vmax);
154 /* get the bounding sphere in local space. The result will be cached ... see above */
155 float cmesh_bsphere(struct cmesh *cm, cgm_vec3 *center, float *rad);
156 float cmesh_submesh_bsphere(struct cmesh *cm, int subidx, cgm_vec3 *center, float *rad);
158 /* texture coordinate manipulation */
159 void cmesh_texcoord_apply_xform(struct cmesh *cm, float *xform);
160 void cmesh_texcoord_gen_plane(struct cmesh *cm, cgm_vec3 *norm, cgm_vec3 *tang);
161 void cmesh_texcoord_gen_box(struct cmesh *cm);
162 void cmesh_texcoord_gen_cylinder(struct cmesh *cm);
165 int cmesh_load(struct cmesh *cm, const char *fname);
167 int cmesh_dump(struct cmesh *cm, const char *fname);
168 int cmesh_dump_file(struct cmesh *cm, FILE *fp);
169 int cmesh_dump_obj(struct cmesh *cm, const char *fname);
170 int cmesh_dump_obj_file(struct cmesh *cm, FILE *fp, int voffs);
174 #endif /* CMESH_H_ */