rev |
line source |
nuclear@0
|
1 #ifndef GOAT3D_H_
|
nuclear@0
|
2 #define GOAT3D_H_
|
nuclear@0
|
3
|
nuclear@0
|
4 #include <stdio.h>
|
nuclear@0
|
5 #include <stdlib.h>
|
nuclear@0
|
6
|
nuclear@15
|
7 #define GOAT3D_MAT_ATTR_DIFFUSE "diffuse"
|
nuclear@15
|
8 #define GOAT3D_MAT_ATTR_SPECULAR "specular"
|
nuclear@15
|
9 #define GOAT3D_MAT_ATTR_SHININESS "shininess"
|
nuclear@15
|
10 #define GOAT3D_MAT_ATTR_NORMAL "normal"
|
nuclear@15
|
11 #define GOAT3D_MAT_ATTR_BUMP "bump"
|
nuclear@15
|
12 #define GOAT3D_MAT_ATTR_REFLECTION "reflection"
|
nuclear@15
|
13 #define GOAT3D_MAT_ATTR_TRANSMISSION "transmission"
|
nuclear@15
|
14 #define GOAT3D_MAT_ATTR_IOR "ior"
|
nuclear@15
|
15
|
nuclear@15
|
16 enum goat3d_mesh_attrib {
|
nuclear@15
|
17 GOAT3D_MESH_ATTR_VERTEX,
|
nuclear@15
|
18 GOAT3D_MESH_ATTR_NORMAL,
|
nuclear@15
|
19 GOAT3D_MESH_ATTR_TANGENT,
|
nuclear@15
|
20 GOAT3D_MESH_ATTR_TEXCOORD,
|
nuclear@15
|
21 GOAT3D_MESH_ATTR_SKIN_WEIGHT,
|
nuclear@15
|
22 GOAT3D_MESH_ATTR_SKIN_MATRIX,
|
nuclear@15
|
23 GOAT3D_MESH_ATTR_COLOR,
|
nuclear@15
|
24
|
nuclear@15
|
25 NUM_GOAT3D_MESH_ATTRIBS
|
nuclear@15
|
26 };
|
nuclear@15
|
27
|
nuclear@15
|
28 /* immediate mode mesh construction primitive type */
|
nuclear@15
|
29 enum goat3d_im_primitive {
|
nuclear@15
|
30 GOAT3D_TRIANGLES,
|
nuclear@15
|
31 GOAT3D_QUADS
|
nuclear@15
|
32 };
|
nuclear@15
|
33
|
nuclear@15
|
34
|
nuclear@15
|
35 enum goat3d_option {
|
nuclear@15
|
36 GOAT3D_OPT_SAVEXML, /* save in XML format */
|
nuclear@15
|
37
|
nuclear@15
|
38 NUM_GOAT3D_OPTIONS
|
nuclear@15
|
39 };
|
nuclear@15
|
40
|
nuclear@0
|
41 struct goat3d;
|
nuclear@15
|
42 struct goat3d_material;
|
nuclear@15
|
43 struct goat3d_mesh;
|
nuclear@15
|
44 struct goat3d_light;
|
nuclear@15
|
45 struct goat3d_camera;
|
nuclear@15
|
46 struct goat3d_node;
|
nuclear@0
|
47
|
nuclear@0
|
48 struct goat3d_io {
|
nuclear@0
|
49 void *cls; /* closure data */
|
nuclear@0
|
50
|
nuclear@11
|
51 long (*read)(void *buf, size_t bytes, void *uptr);
|
nuclear@13
|
52 long (*write)(const void *buf, size_t bytes, void *uptr);
|
nuclear@0
|
53 long (*seek)(long offs, int whence, void *uptr);
|
nuclear@0
|
54 };
|
nuclear@0
|
55
|
nuclear@0
|
56 #ifdef __cplusplus
|
nuclear@0
|
57 extern "C" {
|
nuclear@0
|
58 #endif
|
nuclear@0
|
59
|
nuclear@0
|
60 /* construction/destruction */
|
nuclear@15
|
61 struct goat3d *goat3d_create(void);
|
nuclear@0
|
62 void goat3d_free(struct goat3d *g);
|
nuclear@0
|
63
|
nuclear@15
|
64 void goat3d_setopt(struct goat3d *g, enum goat3d_option opt, int val);
|
nuclear@15
|
65 int goat3d_getopt(const struct goat3d *g, enum goat3d_option opt);
|
nuclear@15
|
66
|
nuclear@0
|
67 /* load/save */
|
nuclear@0
|
68 int goat3d_load(struct goat3d *g, const char *fname);
|
nuclear@0
|
69 int goat3d_save(const struct goat3d *g, const char *fname);
|
nuclear@0
|
70
|
nuclear@0
|
71 int goat3d_load_file(struct goat3d *g, FILE *fp);
|
nuclear@0
|
72 int goat3d_save_file(const struct goat3d *g, FILE *fp);
|
nuclear@0
|
73
|
nuclear@0
|
74 int goat3d_load_io(struct goat3d *g, struct goat3d_io *io);
|
nuclear@0
|
75 int goat3d_save_io(const struct goat3d *g, struct goat3d_io *io);
|
nuclear@0
|
76
|
nuclear@0
|
77 /* misc scene properties */
|
nuclear@0
|
78 int goat3d_set_name(struct goat3d *g, const char *name);
|
nuclear@0
|
79 const char *goat3d_get_name(const struct goat3d *g);
|
nuclear@0
|
80
|
nuclear@15
|
81 void goat3d_set_ambient(struct goat3d *g, const float *ambient);
|
nuclear@15
|
82 void goat3d_set_ambient3f(struct goat3d *g, float ar, float ag, float ab);
|
nuclear@15
|
83 const float *goat3d_get_ambient(const struct goat3d *g);
|
nuclear@0
|
84
|
nuclear@15
|
85 /* materials */
|
nuclear@15
|
86 struct goat3d_material *goat3d_create_mtl(void);
|
nuclear@15
|
87 void goat3d_destroy_mtl(struct goat3d_material *mtl);
|
nuclear@0
|
88
|
nuclear@15
|
89 void goat3d_set_mtl_name(struct goat3d_material *mtl, const char *name);
|
nuclear@15
|
90 const char *goat3d_get_mtl_name(const struct goat3d_material *mtl);
|
nuclear@15
|
91
|
nuclear@15
|
92 void goat3d_set_mtl_attrib(struct goat3d_material *mtl, const char *attrib, const float *val);
|
nuclear@15
|
93 void goat3d_set_mtl_attrib1f(struct goat3d_material *mtl, const char *attrib, float val);
|
nuclear@15
|
94 void goat3d_set_mtl_attrib3f(struct goat3d_material *mtl, const char *attrib, float r, float g, float b);
|
nuclear@15
|
95 void goat3d_set_mtl_attrib4f(struct goat3d_material *mtl, const char *attrib, float r, float g, float b, float a);
|
nuclear@15
|
96 const float *goat3d_get_mtl_attrib(struct goat3d_material *mtl, const char *attrib);
|
nuclear@15
|
97
|
nuclear@15
|
98 void goat3d_set_mtl_attrib_map(struct goat3d_material *mtl, const char *attrib, const char *mapname);
|
nuclear@15
|
99 const char *goat3d_get_mtl_attrib_map(struct goat3d_material *mtl, const char *attrib);
|
nuclear@15
|
100
|
nuclear@15
|
101 void goat3d_add_mtl(struct goat3d *g, struct goat3d_material *mtl);
|
nuclear@15
|
102
|
nuclear@15
|
103 /* meshes */
|
nuclear@15
|
104 struct goat3d_mesh *goat3d_create_mesh(void);
|
nuclear@15
|
105 void goat3d_destroy_mesh(struct goat3d_mesh *mesh);
|
nuclear@15
|
106
|
nuclear@15
|
107 void goat3d_set_mesh_name(struct goat3d_mesh *mesh, const char *name);
|
nuclear@15
|
108 const char *goat3d_get_mesh_name(const struct goat3d_mesh *mesh);
|
nuclear@15
|
109
|
nuclear@15
|
110 void goat3d_set_mesh_mtl(struct goat3d_mesh *mesh, struct goat3d_material *mtl);
|
nuclear@15
|
111 struct goat3d_material *goat3d_get_mesh_mtl(struct goat3d_mesh *mesh);
|
nuclear@15
|
112
|
nuclear@15
|
113 int goat3d_get_mesh_attrib_count(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib);
|
nuclear@15
|
114 int goat3d_get_mesh_face_count(struct goat3d_mesh *mesh);
|
nuclear@15
|
115
|
nuclear@15
|
116 /* sets all the data for a single vertex attribute array in one go.
|
nuclear@15
|
117 * vnum is the number of *vertices* to be set, not the number of floats, ints or whatever
|
nuclear@15
|
118 * data is expected to be something different depending on the attribute:
|
nuclear@15
|
119 * - GOAT3D_MESH_ATTR_VERTEX - 3 floats per vertex
|
nuclear@15
|
120 * - GOAT3D_MESH_ATTR_NORMAL - 3 floats per vertex
|
nuclear@15
|
121 * - GOAT3D_MESH_ATTR_TANGENT - 3 floats per vertex
|
nuclear@15
|
122 * - GOAT3D_MESH_ATTR_TEXCOORD - 2 floats per vertex
|
nuclear@15
|
123 * - GOAT3D_MESH_ATTR_SKIN_WEIGHT - 4 floats per vertex
|
nuclear@15
|
124 * - GOAT3D_MESH_ATTR_SKIN_MATRIX - 4 ints per vertex
|
nuclear@15
|
125 * - GOAT3D_MESH_ATTR_COLOR - 4 floats per vertex
|
nuclear@15
|
126 */
|
nuclear@15
|
127 void goat3d_set_mesh_attribs(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, const void *data, int vnum);
|
nuclear@15
|
128 /* returns a pointer to the beginning of the requested mesh attribute array */
|
nuclear@15
|
129 void *goat3d_get_mesh_attribs(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib);
|
nuclear@15
|
130 /* returns a pointer to the requested mesh attribute */
|
nuclear@15
|
131 void *goat3d_get_mesh_attrib(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, int idx);
|
nuclear@15
|
132
|
nuclear@15
|
133 /* sets all the faces in one go. data is an array of 3 int vertex indices per face */
|
nuclear@15
|
134 void goat3d_set_mesh_faces(struct goat3d_mesh *mesh, const int *data, int fnum);
|
nuclear@15
|
135 /* returns a pointer to the beginning of the face index array */
|
nuclear@15
|
136 int *goat3d_get_mesh_faces(struct goat3d_mesh *mesh);
|
nuclear@15
|
137 /* returns a pointer to a face index */
|
nuclear@15
|
138 int *goat3d_get_mesh_face(struct goat3d_mesh *mesh, int idx);
|
nuclear@15
|
139
|
nuclear@15
|
140 /* immediate mode OpenGL-like interface for setting mesh data
|
nuclear@15
|
141 * NOTE: using this interface will result in no vertex sharing between faces
|
nuclear@15
|
142 * NOTE2: the immedate mode interface is not thread-safe, either use locks, or don't
|
nuclear@15
|
143 * use it at all in multithreaded situations.
|
nuclear@15
|
144 */
|
nuclear@15
|
145 void goat3d_begin(struct goat3d_mesh *mesh, enum goat3d_im_primitive prim);
|
nuclear@15
|
146 void goat3d_end(void);
|
nuclear@15
|
147 void goat3d_vertex3f(float x, float y, float z);
|
nuclear@15
|
148 void goat3d_normal3f(float x, float y, float z);
|
nuclear@15
|
149 void goat3d_tangent3f(float x, float y, float z);
|
nuclear@15
|
150 void goat3d_texcoord2f(float x, float y);
|
nuclear@15
|
151 void goat3d_skin_weight4f(float x, float y, float z, float w);
|
nuclear@15
|
152 void goat3d_skin_matrix4i(int x, int y, int z, int w);
|
nuclear@15
|
153 void goat3d_color3f(float x, float y, float z);
|
nuclear@15
|
154 void goat3d_color4f(float x, float y, float z, float w);
|
nuclear@15
|
155
|
nuclear@15
|
156 void goat3d_add_mesh(struct goat3d *g, struct goat3d_mesh *mesh);
|
nuclear@0
|
157
|
nuclear@19
|
158 int goat3d_get_mesh_count(struct goat3d *g);
|
nuclear@19
|
159 struct goat3d_mesh *goat3d_get_mesh(struct goat3d *g, int idx);
|
nuclear@19
|
160
|
nuclear@0
|
161 #ifdef __cplusplus
|
nuclear@0
|
162 }
|
nuclear@0
|
163 #endif
|
nuclear@0
|
164
|
nuclear@0
|
165 #endif /* GOAT3D_H_ */
|