goat3d
diff src/goat3d.h @ 15:f1b4c27382ce
blah
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 26 Sep 2013 14:06:14 +0300 |
parents | 798df5111b56 |
children | b35427826b60 |
line diff
1.1 --- a/src/goat3d.h Thu Sep 26 04:47:05 2013 +0300 1.2 +++ b/src/goat3d.h Thu Sep 26 14:06:14 2013 +0300 1.3 @@ -4,7 +4,46 @@ 1.4 #include <stdio.h> 1.5 #include <stdlib.h> 1.6 1.7 +#define GOAT3D_MAT_ATTR_DIFFUSE "diffuse" 1.8 +#define GOAT3D_MAT_ATTR_SPECULAR "specular" 1.9 +#define GOAT3D_MAT_ATTR_SHININESS "shininess" 1.10 +#define GOAT3D_MAT_ATTR_NORMAL "normal" 1.11 +#define GOAT3D_MAT_ATTR_BUMP "bump" 1.12 +#define GOAT3D_MAT_ATTR_REFLECTION "reflection" 1.13 +#define GOAT3D_MAT_ATTR_TRANSMISSION "transmission" 1.14 +#define GOAT3D_MAT_ATTR_IOR "ior" 1.15 + 1.16 +enum goat3d_mesh_attrib { 1.17 + GOAT3D_MESH_ATTR_VERTEX, 1.18 + GOAT3D_MESH_ATTR_NORMAL, 1.19 + GOAT3D_MESH_ATTR_TANGENT, 1.20 + GOAT3D_MESH_ATTR_TEXCOORD, 1.21 + GOAT3D_MESH_ATTR_SKIN_WEIGHT, 1.22 + GOAT3D_MESH_ATTR_SKIN_MATRIX, 1.23 + GOAT3D_MESH_ATTR_COLOR, 1.24 + 1.25 + NUM_GOAT3D_MESH_ATTRIBS 1.26 +}; 1.27 + 1.28 +/* immediate mode mesh construction primitive type */ 1.29 +enum goat3d_im_primitive { 1.30 + GOAT3D_TRIANGLES, 1.31 + GOAT3D_QUADS 1.32 +}; 1.33 + 1.34 + 1.35 +enum goat3d_option { 1.36 + GOAT3D_OPT_SAVEXML, /* save in XML format */ 1.37 + 1.38 + NUM_GOAT3D_OPTIONS 1.39 +}; 1.40 + 1.41 struct goat3d; 1.42 +struct goat3d_material; 1.43 +struct goat3d_mesh; 1.44 +struct goat3d_light; 1.45 +struct goat3d_camera; 1.46 +struct goat3d_node; 1.47 1.48 struct goat3d_io { 1.49 void *cls; /* closure data */ 1.50 @@ -14,18 +53,17 @@ 1.51 long (*seek)(long offs, int whence, void *uptr); 1.52 }; 1.53 1.54 -struct goat3d_vec3 { float x, y, z; }; 1.55 -struct goat3d_vec4 { float x, y, z, w; }; 1.56 - 1.57 - 1.58 #ifdef __cplusplus 1.59 extern "C" { 1.60 #endif 1.61 1.62 /* construction/destruction */ 1.63 -struct goat3d *goat3d_create(); 1.64 +struct goat3d *goat3d_create(void); 1.65 void goat3d_free(struct goat3d *g); 1.66 1.67 +void goat3d_setopt(struct goat3d *g, enum goat3d_option opt, int val); 1.68 +int goat3d_getopt(const struct goat3d *g, enum goat3d_option opt); 1.69 + 1.70 /* load/save */ 1.71 int goat3d_load(struct goat3d *g, const char *fname); 1.72 int goat3d_save(const struct goat3d *g, const char *fname); 1.73 @@ -40,12 +78,82 @@ 1.74 int goat3d_set_name(struct goat3d *g, const char *name); 1.75 const char *goat3d_get_name(const struct goat3d *g); 1.76 1.77 -void goat3d_set_ambient(struct goat3d *g, float x, float y, float z); 1.78 +void goat3d_set_ambient(struct goat3d *g, const float *ambient); 1.79 +void goat3d_set_ambient3f(struct goat3d *g, float ar, float ag, float ab); 1.80 +const float *goat3d_get_ambient(const struct goat3d *g); 1.81 1.82 -/* helpers */ 1.83 -struct goat3d_vec3 goat3d_vec3(float x, float y, float z); 1.84 -struct goat3d_vec4 goat3d_vec4(float x, float y, float z, float w); 1.85 +/* materials */ 1.86 +struct goat3d_material *goat3d_create_mtl(void); 1.87 +void goat3d_destroy_mtl(struct goat3d_material *mtl); 1.88 1.89 +void goat3d_set_mtl_name(struct goat3d_material *mtl, const char *name); 1.90 +const char *goat3d_get_mtl_name(const struct goat3d_material *mtl); 1.91 + 1.92 +void goat3d_set_mtl_attrib(struct goat3d_material *mtl, const char *attrib, const float *val); 1.93 +void goat3d_set_mtl_attrib1f(struct goat3d_material *mtl, const char *attrib, float val); 1.94 +void goat3d_set_mtl_attrib3f(struct goat3d_material *mtl, const char *attrib, float r, float g, float b); 1.95 +void goat3d_set_mtl_attrib4f(struct goat3d_material *mtl, const char *attrib, float r, float g, float b, float a); 1.96 +const float *goat3d_get_mtl_attrib(struct goat3d_material *mtl, const char *attrib); 1.97 + 1.98 +void goat3d_set_mtl_attrib_map(struct goat3d_material *mtl, const char *attrib, const char *mapname); 1.99 +const char *goat3d_get_mtl_attrib_map(struct goat3d_material *mtl, const char *attrib); 1.100 + 1.101 +void goat3d_add_mtl(struct goat3d *g, struct goat3d_material *mtl); 1.102 + 1.103 +/* meshes */ 1.104 +struct goat3d_mesh *goat3d_create_mesh(void); 1.105 +void goat3d_destroy_mesh(struct goat3d_mesh *mesh); 1.106 + 1.107 +void goat3d_set_mesh_name(struct goat3d_mesh *mesh, const char *name); 1.108 +const char *goat3d_get_mesh_name(const struct goat3d_mesh *mesh); 1.109 + 1.110 +void goat3d_set_mesh_mtl(struct goat3d_mesh *mesh, struct goat3d_material *mtl); 1.111 +struct goat3d_material *goat3d_get_mesh_mtl(struct goat3d_mesh *mesh); 1.112 + 1.113 +int goat3d_get_mesh_attrib_count(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib); 1.114 +int goat3d_get_mesh_face_count(struct goat3d_mesh *mesh); 1.115 + 1.116 +/* sets all the data for a single vertex attribute array in one go. 1.117 + * vnum is the number of *vertices* to be set, not the number of floats, ints or whatever 1.118 + * data is expected to be something different depending on the attribute: 1.119 + * - GOAT3D_MESH_ATTR_VERTEX - 3 floats per vertex 1.120 + * - GOAT3D_MESH_ATTR_NORMAL - 3 floats per vertex 1.121 + * - GOAT3D_MESH_ATTR_TANGENT - 3 floats per vertex 1.122 + * - GOAT3D_MESH_ATTR_TEXCOORD - 2 floats per vertex 1.123 + * - GOAT3D_MESH_ATTR_SKIN_WEIGHT - 4 floats per vertex 1.124 + * - GOAT3D_MESH_ATTR_SKIN_MATRIX - 4 ints per vertex 1.125 + * - GOAT3D_MESH_ATTR_COLOR - 4 floats per vertex 1.126 + */ 1.127 +void goat3d_set_mesh_attribs(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, const void *data, int vnum); 1.128 +/* returns a pointer to the beginning of the requested mesh attribute array */ 1.129 +void *goat3d_get_mesh_attribs(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib); 1.130 +/* returns a pointer to the requested mesh attribute */ 1.131 +void *goat3d_get_mesh_attrib(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, int idx); 1.132 + 1.133 +/* sets all the faces in one go. data is an array of 3 int vertex indices per face */ 1.134 +void goat3d_set_mesh_faces(struct goat3d_mesh *mesh, const int *data, int fnum); 1.135 +/* returns a pointer to the beginning of the face index array */ 1.136 +int *goat3d_get_mesh_faces(struct goat3d_mesh *mesh); 1.137 +/* returns a pointer to a face index */ 1.138 +int *goat3d_get_mesh_face(struct goat3d_mesh *mesh, int idx); 1.139 + 1.140 +/* immediate mode OpenGL-like interface for setting mesh data 1.141 + * NOTE: using this interface will result in no vertex sharing between faces 1.142 + * NOTE2: the immedate mode interface is not thread-safe, either use locks, or don't 1.143 + * use it at all in multithreaded situations. 1.144 + */ 1.145 +void goat3d_begin(struct goat3d_mesh *mesh, enum goat3d_im_primitive prim); 1.146 +void goat3d_end(void); 1.147 +void goat3d_vertex3f(float x, float y, float z); 1.148 +void goat3d_normal3f(float x, float y, float z); 1.149 +void goat3d_tangent3f(float x, float y, float z); 1.150 +void goat3d_texcoord2f(float x, float y); 1.151 +void goat3d_skin_weight4f(float x, float y, float z, float w); 1.152 +void goat3d_skin_matrix4i(int x, int y, int z, int w); 1.153 +void goat3d_color3f(float x, float y, float z); 1.154 +void goat3d_color4f(float x, float y, float z, float w); 1.155 + 1.156 +void goat3d_add_mesh(struct goat3d *g, struct goat3d_mesh *mesh); 1.157 1.158 #ifdef __cplusplus 1.159 }