26 type |
27 type |
27 AtlasInfo = record |
28 AtlasInfo = record |
28 PackerInfo: Atlas; // Rectangle packer context |
29 PackerInfo: Atlas; // Rectangle packer context |
29 TextureInfo: TAtlas; // OpenGL texture information |
30 TextureInfo: TAtlas; // OpenGL texture information |
30 Allocated: boolean; // indicates if this atlas is in use |
31 Allocated: boolean; // indicates if this atlas is in use |
|
32 DumpID: Integer; |
31 end; |
33 end; |
32 |
34 |
33 var |
35 var |
34 Info: array[0..MaxAtlases-1] of AtlasInfo; |
36 Info: array[0..MaxAtlases-1] of AtlasInfo; |
35 |
37 |
36 |
38 |
37 //////////////////////////////////////////////////////////////////////////////// |
39 //////////////////////////////////////////////////////////////////////////////// |
38 // Debug routines |
40 // Debug routines |
|
41 |
|
42 procedure DumpInfo(tex: PTexture); |
|
43 var |
|
44 frame: Integer; |
|
45 i, atlasID: Integer; |
|
46 aw, ah: Integer; |
|
47 begin |
|
48 if tex = nil then |
|
49 exit; |
|
50 |
|
51 frame:= 0; |
|
52 writeln(stdout, 'Texture: ' + IntToHex(Integer(tex), 8)); |
|
53 |
|
54 while tex <> nil do |
|
55 begin |
|
56 atlasID:= -1; |
|
57 for i:= 0 to Pred(MaxAtlases) do |
|
58 if tex^.atlas = @Info[i].TextureInfo then |
|
59 atlasID:=i; |
|
60 |
|
61 aw:= tex^.atlas^.w; |
|
62 ah:= tex^.atlas^.h; |
|
63 |
|
64 writeln(stdout, 'Frame : ' + IntToStr(frame)); |
|
65 writeln(stdout, 'Size : ' + IntToStr(tex^.w) + 'x' + IntToStr(tex^.h)); |
|
66 writeln(stdout, 'Atlas : ' + IntToStr(atlasID)); |
|
67 writeln(stdout, 'Location: ' + IntToStr(tex^.x) + 'x' + IntToStr(tex^.y)); |
|
68 writeln(stdout, 'TB : ' + '(' + FloatToStrF(tex^.tb[0].X, ffFixed, 15, 4) + ',' + FloatToStrF(tex^.tb[0].Y, ffFixed, 15, 4) + ') ' |
|
69 + '(' + FloatToStrF(tex^.tb[1].X, ffFixed, 15, 4) + ',' + FloatToStrF(tex^.tb[1].Y, ffFixed, 15, 4) + ') ' |
|
70 + '(' + FloatToStrF(tex^.tb[2].X, ffFixed, 15, 4) + ',' + FloatToStrF(tex^.tb[2].Y, ffFixed, 15, 4) + ') ' |
|
71 + '(' + FloatToStrF(tex^.tb[3].X, ffFixed, 15, 4) + ',' + FloatToStrF(tex^.tb[3].Y, ffFixed, 15, 4) + ')'); |
|
72 |
|
73 writeln(stdout, 'TB.ABS : ' + '(' + FloatToStrF(tex^.tb[0].X * aw, ffFixed, 15, 4) + ',' + FloatToStrF(tex^.tb[0].Y * ah, ffFixed, 15, 4) + ') ' |
|
74 + '(' + FloatToStrF(tex^.tb[1].X * aw, ffFixed, 15, 4) + ',' + FloatToStrF(tex^.tb[1].Y * ah, ffFixed, 15, 4) + ') ' |
|
75 + '(' + FloatToStrF(tex^.tb[2].X * aw, ffFixed, 15, 4) + ',' + FloatToStrF(tex^.tb[2].Y * ah, ffFixed, 15, 4) + ') ' |
|
76 + '(' + FloatToStrF(tex^.tb[3].X * aw, ffFixed, 15, 4) + ',' + FloatToStrF(tex^.tb[3].Y * ah, ffFixed, 15, 4) + ')'); |
|
77 |
|
78 inc(frame); |
|
79 tex:= tex^.nextFrame; |
|
80 end; |
|
81 halt(0); |
|
82 end; |
39 |
83 |
40 procedure AssertCount(tex: PTexture; count: Integer); |
84 procedure AssertCount(tex: PTexture; count: Integer); |
41 var |
85 var |
42 i, j: Integer; |
86 i, j: Integer; |
43 found: Integer; |
87 found: Integer; |
166 {$IFDEF GL2} |
211 {$IFDEF GL2} |
167 glUseProgram(prog); |
212 glUseProgram(prog); |
168 {$ENDIF} |
213 {$ENDIF} |
169 end; |
214 end; |
170 end; |
215 end; |
171 |
216 {$ELSE} |
172 procedure DumpAtlas(var info: AtlasInfo); |
217 begin; |
|
218 end; |
|
219 {$ENDIF} |
|
220 |
|
221 procedure DumpAtlas(var dinfo: AtlasInfo); |
173 var |
222 var |
174 png: png_structp; |
223 png: png_structp; |
175 png_info: png_infop; |
224 png_info: png_infop; |
176 w, h, sz: Integer; |
225 w, h, sz: Integer; |
177 filename: string; |
226 filename: string; |
178 rows: array of png_bytep; |
227 rows: array of png_bytep; |
179 size: Integer; |
228 size: Integer; |
180 i, j: Integer; |
229 i, j: Integer; |
|
230 idx: Integer; |
181 mem, p, pp: PByte; |
231 mem, p, pp: PByte; |
182 begin |
232 begin |
183 filename:= '/home/wolfgangst/hedgewars/dump/atlas_' + IntToStrPad(DumpID) + '.png'; |
233 idx:= -1; |
|
234 for i:= 0 to Pred(MaxAtlases) do |
|
235 if @dinfo = @Info[i] then |
|
236 idx:=i; |
|
237 |
|
238 filename:= '/home/wolfgangst/hedgewars/dump/atlas_' + IntToStr(idx) + '_' + IntToStrPad(dinfo.DumpID) + '.png'; |
184 Assign(DumpFile, filename); |
239 Assign(DumpFile, filename); |
185 inc(DumpID); |
240 inc(dinfo.DumpID); |
186 Rewrite(DumpFile); |
241 Rewrite(DumpFile); |
187 |
242 |
188 w:= info.TextureInfo.w; |
243 w:= dinfo.TextureInfo.w; |
189 h:= info.TextureInfo.h; |
244 h:= dinfo.TextureInfo.h; |
190 size:= w * h * 4; |
245 size:= w * h * 4; |
191 SetLength(rows, h); |
246 SetLength(rows, h); |
192 GetMem(mem, size); |
247 GetMem(mem, size); |
193 |
248 |
194 glBindTexture(GL_TEXTURE_2D, info.TextureInfo.id); |
249 glBindTexture(GL_TEXTURE_2D, dinfo.TextureInfo.id); |
195 |
250 |
196 glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, mem); |
251 glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, mem); |
197 |
252 |
198 p:= mem; |
253 p:= mem; |
199 for i:= 0 to pred(h) do |
254 for i:= 0 to pred(h) do |
372 sp: PTexture; |
427 sp: PTexture; |
373 i, j, stride: Integer; |
428 i, j, stride: Integer; |
374 scanline: PByte; |
429 scanline: PByte; |
375 r: TSDL_Rect; |
430 r: TSDL_Rect; |
376 begin |
431 begin |
377 writeln('Uploading sprite to ', sprite.x, ',', sprite.y, ',', sprite.width, ',', sprite.height); |
432 //writeln('Uploading sprite to ', sprite.x, ',', sprite.y, ',', sprite.width, ',', sprite.height); |
378 sp:= PTexture(sprite.UserData); |
433 sp:= PTexture(sprite.UserData); |
379 sp^.x:= sprite.x; |
434 sp^.x:= sprite.x; |
380 sp^.y:= sprite.y; |
435 sp^.y:= sprite.y; |
381 sp^.isRotated:= sp^.w <> sprite.width; |
436 sp^.isRotated:= sp^.w <> sprite.width; |
382 sp^.atlas:= @info.TextureInfo; |
437 sp^.atlas:= @info.TextureInfo; |