goat3d
view src/chunk.h @ 45:8da36540e2e9
fixed memory leak in readxml and reversed error return
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 08 Dec 2013 02:27:32 +0200 |
parents | 188c697b3b49 |
children | 498ca7ac7047 |
line source
1 #ifndef CHUNK_H_
2 #define CHUNK_H_
4 #ifndef _MSC_VER
5 #include <stdint.h>
6 #else
7 typedef unsigned __int32 uint32_t;
8 #endif
10 enum {
11 CNK_INVALID, // this shouldn't appear in files
12 CNK_SCENE, // the root chunk
14 // general purpose chunks
15 CNK_INT,
16 CNK_INT4,
17 CNK_FLOAT,
18 CNK_FLOAT3,
19 CNK_FLOAT4,
20 CNK_STRING,
22 // --- first level chunks ---
23 // children of CNK_SCENE
24 CNK_ENV, // environmental parameters
25 CNK_MTL, // material
26 CNK_MESH,
27 CNK_LIGHT,
28 CNK_CAMERA,
29 CNK_NODE,
31 // --- second level chunks ---
32 // children of CNK_ENV
33 CNK_ENV_AMBIENT, // ambient color, contains a single CNK_FLOAT3
34 CNK_ENV_FOG,
36 // --- third level chunks ---
37 // children of CNK_FOG
38 CNK_FOG_COLOR, // fog color, contains a single CNK_FLOAT3
39 CNK_FOG_EXP, // fog exponent, contains a single CNK_FLOAT
41 // children of CNK_MTL
42 CNK_MTL_NAME, // has a single CNK_STRING
43 CNK_MTL_ATTR, // material attribute, has a CNK_STRING for its name,
44 // a CNK_MTL_ATTR_VAL, and optionally a CNK_MTL_ATTR_MAP
45 // children of CNK_MTL_ATTR
46 CNK_MTL_ATTR_NAME, // has a single CNK_STRING
47 CNK_MTL_ATTR_VAL, // can have a single CNK_FLOAT, CNK_FLOAT3, or CNK_FLOAT4
48 CNK_MTL_ATTR_MAP, // has a single CNK_STRING
50 // children of CNK_MESH
51 CNK_MESH_NAME, // has a single CNK_STRING
52 CNK_MESH_MATERIAL, // has one of CNK_STRING or CNK_INT to identify the material
53 CNK_MESH_VERTEX_LIST, // has a series of CNK_FLOAT3 chunks
54 CNK_MESH_NORMAL_LIST, // has a series of CNK_FLOAT3 chunks
55 CNK_MESH_TANGENT_LIST, // has a series of CNK_FLOAT3 chunks
56 CNK_MESH_TEXCOORD_LIST, // has a series of CNK_FLOAT3 chunks
57 CNK_MESH_SKINWEIGHT_LIST, // has a series of CNK_FLOAT4 chunks (4 skin weights)
58 CNK_MESH_SKINMATRIX_LIST, // has a series of CNK_INT4 chunks (4 matrix indices)
59 CNK_MESH_COLOR_LIST, // has a series of CNK_FLOAT4 chunks
60 CNK_MESH_BONES_LIST, // has a series of CNK_INT or CNK_STRING chunks identifying the bone nodes
61 CNK_MESH_FACE_LIST, // has a series of CNK_FACE chunks
62 CNK_MESH_FILE, // optionally mesh data may be in another file, has a CNK_STRING filename
64 // child of CNK_MESH_FACE_LIST
65 CNK_MESH_FACE, // has three CNK_INT chunks
67 // children of CNK_LIGHT
68 CNK_LIGHT_NAME, // has a single CNK_STRING
69 CNK_LIGHT_POS, // has a single CNK_FLOAT3
70 CNK_LIGHT_COLOR, // has a single CNK_FLOAT3
71 CNK_LIGHT_ATTEN, // has a single CNK_FLOAT3 (constant, linear, squared attenuation)
72 CNK_LIGHT_DISTANCE, // has a single CNK_FLOAT
73 CNK_LIGHT_DIR, // a single CNK_FLOAT3 (for spotlights and dir-lights)
74 CNK_LIGHT_CONE_INNER, // single CNK_FLOAT, inner cone angle (for spotlights)
75 CNK_LIGHT_CONE_OUTER, // single CNK_FLOAT, outer cone angle (for spotlights)
77 // children of CNK_CAMERA
78 CNK_CAMERA_NAME, // has a single CNK_STRING
79 CNK_CAMERA_POS, // single CNK_FLOAT3
80 CNK_CAMERA_TARGET, // single CNK_FLOAT3
81 CNK_CAMERA_FOV, // single CNK_FLOAT (field of view in radians)
82 CNK_CAMERA_NEARCLIP, // single CNK_FLOAT (near clipping plane distance)
83 CNK_CAMERA_FARCLIP, // signle CNK_FLOAT (far clipping plane distance)
85 // children of CNK_NODE
86 CNK_NODE_NAME, // node name, a single CNK_STRING
87 CNK_NODE_PARENT, // it can have a CNK_INT or a CNK_STRING to identify the parent node
89 CNK_NODE_MESH, // it can have a CNK_INT or a CNK_STRING to identify this node's mesh
90 CNK_NODE_LIGHT, // same as CNK_NODE_MESH
91 CNK_NODE_CAMERA, // same as CNK_NODE_MESH
93 CNK_NODE_POS, // has a CNK_FLOAT3, position vector
94 CNK_NODE_ROT, // has a CNK_FLOAT4, rotation quaternion (x, y, z imaginary, w real)
95 CNK_NODE_SCALE, // has a CNK_FLOAT3, scaling
96 CNK_NODE_PIVOT, // has a CNK_FLOAT3, pivot point
98 CNK_NODE_MATRIX0, // has a CNK_FLOAT4, first matrix row (4x3)
99 CNK_NODE_MATRXI1, // has a CNK_FLOAT4, second matrix row (4x3)
100 CNK_NODE_MATRIX2, // has a CNK_FLOAT4, third matrix row (4x3)
102 MAX_NUM_CHUNKS
103 };
105 #define UNKNOWN_SIZE ((uint32_t)0xbaadf00d)
107 struct ChunkHeader {
108 uint32_t id;
109 uint32_t size;
110 };
112 struct Chunk {
113 ChunkHeader hdr;
114 char data[1];
115 };
118 ChunkHeader chunk_header(int id);
119 bool write_chunk_header(const ChunkHeader *hdr, goat3d_io *io);
120 bool read_chunk_header(ChunkHeader *hdr, goat3d_io *io);
121 void skip_chunk(const ChunkHeader *hdr, goat3d_io *io);
124 #endif // CHUNK_H_