goat3d

view src/goat3d_write.cc @ 53:6d514398a728

fixed a merge mistake
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 17 Jan 2014 18:30:35 +0200
parents cb5414f406eb
children dad392c710df af1310ed212b
line source
1 #include "goat3d_impl.h"
2 #include "chunk.h"
4 using namespace g3dimpl;
6 /*
7 static long save_env(const Scene *scn, long offset, goat3d_io *io);
8 static long save_materials(const Scene *scn, long offset, goat3d_io *io);
9 static long save_material(const Material *mat, long offset, goat3d_io *io);
10 static long save_mat_attrib(const char *name, const MaterialAttrib &attr, long offset, goat3d_io *io);
11 static long save_meshes(const Scene *scn, long offset, goat3d_io *io);
12 static long save_lights(const Scene *scn, long offset, goat3d_io *io);
13 static long save_cameras(const Scene *scn, long offset, goat3d_io *io);
14 static long save_nodes(const Scene *scn, long offset, goat3d_io *io);
16 static long write_chunk_float(int id, float val, long offs, goat3d_io *io);
17 static long write_chunk_float3(int id, const Vector3 &vec, long offs, goat3d_io *io);
18 static long write_chunk_float4(int id, const Vector4 &vec, long offs, goat3d_io *io);
19 */
21 bool Scene::save(goat3d_io *io) const
22 {
23 /*
24 long res;
26 ChunkHeader hdr;
27 hdr.id = CNK_SCENE;
28 hdr.size = sizeof hdr;
30 if((res = save_env(this, hdr.size, io)) < 0) {
31 return false;
32 }
33 hdr.size += res;
35 if((res = save_materials(this, hdr.size, io)) < 0) {
36 return false;
37 }
38 hdr.size += res;
40 if((res = save_meshes(this, hdr.size, io)) < 0) {
41 return false;
42 }
43 hdr.size += res;
45 if((res = save_lights(this, hdr.size, io)) < 0) {
46 return false;
47 }
48 hdr.size += res;
50 if((res = save_cameras(this, hdr.size, io)) < 0) {
51 return false;
52 }
53 hdr.size += res;
55 if((res = save_nodes(this, hdr.size, io)) < 0) {
56 return false;
57 }
58 hdr.size += res;
60 // now go back and write the root chunk
61 io->seek(0, SEEK_SET, io->cls);
62 if(io->write(&hdr, sizeof hdr, io->cls) < (ssize_t)sizeof hdr) {
63 return false;
64 }
66 return true;
67 */
68 return false;
69 }
71 bool Scene::save_anim(const XFormNode *node, goat3d_io *io) const
72 {
73 return false;
74 }
77 #if 0
78 static long save_env(const Scene *scn, long offset, goat3d_io *io)
79 {
80 long res;
82 ChunkHeader hdr;
83 hdr.id = CNK_ENV;
84 hdr.size = sizeof hdr;
86 if((res = write_chunk_float3(CNK_ENV_AMBIENT, scn->get_ambient(), offset, io)) < 0) {
87 return -1;
88 }
89 hdr.size += res;
91 // TODO add fog chunk
93 io->seek(offset, SEEK_SET, io->cls);
94 if(io->write(&hdr, sizeof hdr, io->cls) < (ssize_t)sizeof hdr) {
95 return -1;
96 }
97 return hdr.size;
98 }
100 static long save_materials(const Scene *scn, long offset, goat3d_io *io)
101 {
102 long res;
104 ChunkHeader hdr;
105 hdr.id = CNK_MTL_LIST;
106 hdr.size = sizeof hdr;
108 for(int i=0; i<scn->get_material_count(); i++) {
109 if((res = save_material(scn->get_material(i), offset + hdr.size, io)) < 0) {
110 return -1;
111 }
112 hdr.size += res;
113 }
115 io->seek(offset, SEEK_SET, io->cls);
116 if(io->write(&hdr, hdr.size, io->cls) < hdr.size) {
117 return -1;
118 }
119 return hdr.size;
120 }
122 static long save_material(const Material *mat, long offset, goat3d_io *io)
123 {
124 long res;
126 ChunkHeader hdr;
127 hdr.id = CNK_MTL;
128 hdr.size = sizeof hdr;
130 for(int i=0; i<mat->get_attrib_count(); i++) {
131 const char *name = mat->get_attrib_name(i);
132 if((res = save_mat_attrib(name, (*mat)[i], offset + hdr.size, io)) < 0) {
133 return -1;
134 }
135 hdr.size += res;
136 }
138 io->seek(offset, SEEK_SET, io->cls);
139 if(io->write(&hdr, hdr.size, io->cls) < hdr.size) {
140 return -1;
141 }
142 return hdr.size;
143 }
145 static long save_mat_attrib(const char *name, const MaterialAttrib &attr, long offset, goat3d_io *io)
146 {
147 long res;
149 ChunkHeader hdr;
150 hdr.id = CNK_MTL_ATTR;
151 hdr.size = sizeof hdr;
153 // TODO cont.
154 return -1;
155 }
157 static long save_meshes(const Scene *scn, long offset, goat3d_io *io)
158 {
159 return 0;
160 }
162 static long save_lights(const Scene *scn, long offset, goat3d_io *io)
163 {
164 return 0;
165 }
167 static long save_cameras(const Scene *scn, long offset, goat3d_io *io)
168 {
169 return 0;
170 }
172 static long save_nodes(const Scene *scn, long offset, goat3d_io *io)
173 {
174 return 0;
175 }
177 static long write_chunk_float(int id, float val, long offs, goat3d_io *io)
178 {
179 int size = sizeof(ChunkHeader) + sizeof val;
180 char *buf = (char*)alloca(size);
182 Chunk *c = (Chunk*)buf;
183 c->hdr.id = id;
184 c->hdr.size = size;
185 *(float*)c->data = val;
187 io->seek(offs, SEEK_SET, io->cls);
188 if(io->write(buf, size, io->cls) < size) {
189 return -1;
190 }
191 return size;
192 }
194 static long write_chunk_float3(int id, const Vector3 &vec, long offs, goat3d_io *io)
195 {
196 int size = sizeof(ChunkHeader) + sizeof vec;
197 char *buf = (char*)alloca(size);
199 Chunk *c = (Chunk*)buf;
200 c->hdr.id = id;
201 c->hdr.size = size;
202 *(Vector3*)c->data = vec;
204 io->seek(offs, SEEK_SET, io->cls);
205 if(io->write(buf, size, io->cls) < size) {
206 return -1;
207 }
208 return size;
209 }
211 static long write_chunk_float4(int id, const Vector4 &vec, long offs, goat3d_io *io)
212 {
213 int size = sizeof(ChunkHeader) + sizeof vec;
214 char *buf = (char*)alloca(size);
216 Chunk *c = (Chunk*)buf;
217 c->hdr.id = id;
218 c->hdr.size = size;
219 *(Vector4*)c->data = vec;
221 io->seek(offs, SEEK_SET, io->cls);
222 if(io->write(buf, size, io->cls) < size) {
223 return -1;
224 }
225 return size;
226 }
227 #endif