scenefile

view src/scene.h @ 3:b30f83409769

foo
author John Tsiombikas <nuclear@mutantstargoat.com>
date Sat, 21 Jan 2012 04:14:24 +0200
parents c15992cedec9
children
line source
1 #ifndef SCENE_H_
2 #define SCENE_H_
4 #include "mesh.h"
6 struct scenefile;
7 struct scnfile_io;
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
13 int scnfile_init(struct scenefile *scn);
14 void scnfile_destroy(struct scenefile *scn);
16 struct scenefile *scnfile_create(void);
17 void scnfile_free(struct scenefile *scn);
20 int scnfile_add_mesh(struct scenefile *scn, struct mesh *mesh);
23 int scnfile_load(struct scenefile *scn, const char *fname);
24 int scnfile_read_file(struct scenefile *scn, FILE *fp);
25 int scnfile_read(struct scenefile *scn, struct scnfile_io *io);
27 int scnfile_find_mesh(struct scenefile *scn, const char *fname);
28 struct mesh *scnfile_mesh(struct scenefile *scn, int idx);
29 int scnfile_count(struct scenefile *scn);
32 /* These functions can be used to fill an scnfile_io struct before it's passed to
33 * one of the user-defined i/o image reading/writing functions (scnfile_read/scnfile_write).
34 *
35 * User-defined i/o functions:
36 *
37 * - size_t read_func(void *buffer, size_t bytes, void *user_ptr)
38 * Must try to fill the buffer with the specified number of bytes, and return
39 * the number of bytes actually read.
40 *
41 * - size_t write_func(void *buffer, size_t bytes, void *user_ptr)
42 * Must write the specified number of bytes from the supplied buffer and return
43 * the number of bytes actually written.
44 *
45 * - long seek_func(long offset, int whence, void *user_ptr)
46 * Must seek offset bytes from: the beginning of the file if whence is SEEK_SET,
47 * the current position if whence is SEEK_CUR, or the end of the file if whence is
48 * SEEK_END, and return the resulting file offset from the beginning of the file.
49 * (i.e. seek_func(0, SEEK_CUR, user_ptr); must be equivalent to an ftell).
50 *
51 * All three functions get the user-data pointer set through scnfile_io_set_user_data
52 * as their last argument.
53 *
54 * Note: obviously you don't need to set a write function if you're only going
55 * to call scnfile_read, or the read and seek function if you're only going to call
56 * scnfile_write.
57 *
58 * Note: if the user-supplied write function is buffered, make sure to flush
59 * (or close the file) after scnfile_write returns.
60 */
61 void scnfile_io_user_data(struct scnfile_io *io, void *uptr);
62 void scnfile_io_read_func(struct scnfile_io *io, size_t (*read)(void*, size_t, void*));
63 void scnfile_io_write_func(struct scnfile_io *io, size_t (*write)(void*, size_t, void*));
64 void scnfile_io_seek_func(struct scnfile_io *io, long (*seek)(long, int, void*));
67 #ifdef __cplusplus
68 }
69 #endif
71 #endif /* SCENE_H_ */