Mercurial > sdl-ios-xcode
comparison src/video/sdlgenblit.pl @ 2262:bee005ace1bf
Work in progress: merging new texture features into SDL blit system
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 17 Aug 2007 06:21:58 +0000 |
parents | 7387e0514595 |
children | 900c35d8e8fd |
comparison
equal
deleted
inserted
replaced
2261:c20476d7d7b3 | 2262:bee005ace1bf |
---|---|
121 } | 121 } |
122 | 122 |
123 sub output_copydefs | 123 sub output_copydefs |
124 { | 124 { |
125 print FILE <<__EOF__; | 125 print FILE <<__EOF__; |
126 #define SDL_RENDERCOPY_MODULATE_COLOR 0x0001 | 126 extern SDL_BlitFuncEntry *SDL_GeneratedBlitFuncTable; |
127 #define SDL_RENDERCOPY_MODULATE_ALPHA 0x0002 | |
128 #define SDL_RENDERCOPY_MASK 0x0010 | |
129 #define SDL_RENDERCOPY_BLEND 0x0020 | |
130 #define SDL_RENDERCOPY_ADD 0x0040 | |
131 #define SDL_RENDERCOPY_MOD 0x0080 | |
132 #define SDL_RENDERCOPY_NEAREST 0x0100 | |
133 | |
134 typedef struct { | |
135 void *src; | |
136 int src_w, src_h; | |
137 int src_pitch; | |
138 void *dst; | |
139 int dst_w, dst_h; | |
140 int dst_pitch; | |
141 void *aux_data; | |
142 int flags; | |
143 Uint8 r, g, b, a; | |
144 } SDL_RenderCopyData; | |
145 | |
146 typedef int (*SDL_RenderCopyFunc)(SDL_RenderCopyData *data); | |
147 | |
148 extern SDL_RenderCopyFunc SDLCALL SDL_GetRenderCopyFunc(Uint32 src_format, Uint32 dst_format, int modMode, int blendMode, int scaleMode); | |
149 | |
150 __EOF__ | 127 __EOF__ |
151 } | 128 } |
152 | 129 |
153 sub output_copyfuncname | 130 sub output_copyfuncname |
154 { | 131 { |
159 my $blend = shift; | 136 my $blend = shift; |
160 my $scale = shift; | 137 my $scale = shift; |
161 my $args = shift; | 138 my $args = shift; |
162 my $suffix = shift; | 139 my $suffix = shift; |
163 | 140 |
164 print FILE "$prefix SDL_RenderCopy_${src}_${dst}"; | 141 print FILE "$prefix SDL_Blit_${src}_${dst}"; |
165 if ( $modulate ) { | 142 if ( $modulate ) { |
166 print FILE "_Modulate"; | 143 print FILE "_Modulate"; |
167 } | 144 } |
168 if ( $blend ) { | 145 if ( $blend ) { |
169 print FILE "_Blend"; | 146 print FILE "_Blend"; |
170 } | 147 } |
171 if ( $scale ) { | 148 if ( $scale ) { |
172 print FILE "_Scale"; | 149 print FILE "_Scale"; |
173 } | 150 } |
174 if ( $args ) { | 151 if ( $args ) { |
175 print FILE "(SDL_RenderCopyData *data)"; | 152 print FILE "(SDL_BlitInfo *info)"; |
176 } | 153 } |
177 print FILE "$suffix"; | 154 print FILE "$suffix"; |
178 } | 155 } |
179 | 156 |
180 sub get_rgba | 157 sub get_rgba |
223 print FILE <<__EOF__; | 200 print FILE <<__EOF__; |
224 *dst = *src; | 201 *dst = *src; |
225 __EOF__ | 202 __EOF__ |
226 return; | 203 return; |
227 } | 204 } |
228 | 205 |
229 if ( $blend ) { | 206 if ( $blend ) { |
230 get_rgba("src", $src); | 207 get_rgba("src", $src); |
231 get_rgba("dst", $dst); | 208 get_rgba("dst", $dst); |
232 $s = "src"; | 209 $s = "src"; |
233 $d = "dst"; | 210 $d = "dst"; |
235 get_rgba("", $src); | 212 get_rgba("", $src); |
236 } | 213 } |
237 | 214 |
238 if ( $modulate ) { | 215 if ( $modulate ) { |
239 print FILE <<__EOF__; | 216 print FILE <<__EOF__; |
240 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) { | 217 if (flags & SDL_COPY_MODULATE_COLOR) { |
241 ${s}R = (${s}R * modulateR) / 255; | 218 ${s}R = (${s}R * modulateR) / 255; |
242 ${s}G = (${s}G * modulateG) / 255; | 219 ${s}G = (${s}G * modulateG) / 255; |
243 ${s}B = (${s}B * modulateB) / 255; | 220 ${s}B = (${s}B * modulateB) / 255; |
244 } | 221 } |
245 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) { | 222 if (flags & SDL_COPY_MODULATE_ALPHA) { |
246 ${s}A = (${s}A * modulateA) / 255; | 223 ${s}A = (${s}A * modulateA) / 255; |
247 } | 224 } |
248 __EOF__ | 225 __EOF__ |
249 } | 226 } |
250 if ( $blend ) { | 227 if ( $blend ) { |
251 print FILE <<__EOF__; | 228 print FILE <<__EOF__; |
252 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) { | 229 if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { |
253 /* This goes away if we ever use premultiplied alpha */ | 230 /* This goes away if we ever use premultiplied alpha */ |
254 if (${s}A < 255) { | 231 if (${s}A < 255) { |
255 ${s}R = (${s}R * ${s}A) / 255; | 232 ${s}R = (${s}R * ${s}A) / 255; |
256 ${s}G = (${s}G * ${s}A) / 255; | 233 ${s}G = (${s}G * ${s}A) / 255; |
257 ${s}B = (${s}B * ${s}A) / 255; | 234 ${s}B = (${s}B * ${s}A) / 255; |
258 } | 235 } |
259 } | 236 } |
260 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) { | 237 switch (flags & (SDL_COPY_MASK|SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { |
261 case SDL_RENDERCOPY_MASK: | 238 case SDL_COPY_MASK: |
262 if (${s}A) { | 239 if (${s}A) { |
263 ${d}R = ${s}R; | 240 ${d}R = ${s}R; |
264 ${d}G = ${s}G; | 241 ${d}G = ${s}G; |
265 ${d}B = ${s}B; | 242 ${d}B = ${s}B; |
266 } | 243 } |
267 break; | 244 break; |
268 case SDL_RENDERCOPY_BLEND: | 245 case SDL_COPY_BLEND: |
269 ${d}R = ${s}R + ((255 - ${s}A) * ${d}R) / 255; | 246 ${d}R = ${s}R + ((255 - ${s}A) * ${d}R) / 255; |
270 ${d}G = ${s}G + ((255 - ${s}A) * ${d}G) / 255; | 247 ${d}G = ${s}G + ((255 - ${s}A) * ${d}G) / 255; |
271 ${d}B = ${s}B + ((255 - ${s}A) * ${d}B) / 255; | 248 ${d}B = ${s}B + ((255 - ${s}A) * ${d}B) / 255; |
272 break; | 249 break; |
273 case SDL_RENDERCOPY_ADD: | 250 case SDL_COPY_ADD: |
274 ${d}R = ${s}R + ${d}R; if (${d}R > 255) ${d}R = 255; | 251 ${d}R = ${s}R + ${d}R; if (${d}R > 255) ${d}R = 255; |
275 ${d}G = ${s}G + ${d}G; if (${d}G > 255) ${d}G = 255; | 252 ${d}G = ${s}G + ${d}G; if (${d}G > 255) ${d}G = 255; |
276 ${d}B = ${s}B + ${d}B; if (${d}B > 255) ${d}B = 255; | 253 ${d}B = ${s}B + ${d}B; if (${d}B > 255) ${d}B = 255; |
277 break; | 254 break; |
278 case SDL_RENDERCOPY_MOD: | 255 case SDL_COPY_MOD: |
279 ${d}R = (${s}R * ${d}R) / 255; | 256 ${d}R = (${s}R * ${d}R) / 255; |
280 ${d}G = (${s}G * ${d}G) / 255; | 257 ${d}G = (${s}G * ${d}G) / 255; |
281 ${d}B = (${s}B * ${d}B) / 255; | 258 ${d}B = (${s}B * ${d}B) / 255; |
282 break; | 259 break; |
283 } | 260 } |
296 my $dst = shift; | 273 my $dst = shift; |
297 my $modulate = shift; | 274 my $modulate = shift; |
298 my $blend = shift; | 275 my $blend = shift; |
299 my $scale = shift; | 276 my $scale = shift; |
300 | 277 |
301 output_copyfuncname("int", $src, $dst, $modulate, $blend, $scale, 1, "\n"); | 278 output_copyfuncname("void", $src, $dst, $modulate, $blend, $scale, 1, "\n"); |
302 print FILE <<__EOF__; | 279 print FILE <<__EOF__; |
303 { | 280 { |
304 const int flags = data->flags; | 281 const int flags = info->flags; |
305 __EOF__ | 282 __EOF__ |
306 if ( $modulate ) { | 283 if ( $modulate ) { |
307 print FILE <<__EOF__; | 284 print FILE <<__EOF__; |
308 const Uint32 modulateR = data->r; | 285 const Uint32 modulateR = info->r; |
309 const Uint32 modulateG = data->g; | 286 const Uint32 modulateG = info->g; |
310 const Uint32 modulateB = data->b; | 287 const Uint32 modulateB = info->b; |
311 const Uint32 modulateA = data->a; | 288 const Uint32 modulateA = info->a; |
312 __EOF__ | 289 __EOF__ |
313 } | 290 } |
314 if ( $blend ) { | 291 if ( $blend ) { |
315 print FILE <<__EOF__; | 292 print FILE <<__EOF__; |
316 Uint32 srcpixel; | 293 Uint32 srcpixel; |
330 int posy, posx; | 307 int posy, posx; |
331 int incy, incx; | 308 int incy, incx; |
332 | 309 |
333 srcy = 0; | 310 srcy = 0; |
334 posy = 0; | 311 posy = 0; |
335 incy = (data->src_h << 16) / data->dst_h; | 312 incy = (info->src_h << 16) / info->dst_h; |
336 incx = (data->src_w << 16) / data->dst_w; | 313 incx = (info->src_w << 16) / info->dst_w; |
337 | 314 |
338 while (data->dst_h--) { | 315 while (info->dst_h--) { |
339 $format_type{$src} *src; | 316 $format_type{$src} *src; |
340 $format_type{$dst} *dst = ($format_type{$dst} *)data->dst; | 317 $format_type{$dst} *dst = ($format_type{$dst} *)info->dst; |
341 int n = data->dst_w; | 318 int n = info->dst_w; |
342 srcx = -1; | 319 srcx = -1; |
343 posx = 0x10000L; | 320 posx = 0x10000L; |
344 while (posy >= 0x10000L) { | 321 while (posy >= 0x10000L) { |
345 ++srcy; | 322 ++srcy; |
346 posy -= 0x10000L; | 323 posy -= 0x10000L; |
349 if (posx >= 0x10000L) { | 326 if (posx >= 0x10000L) { |
350 while (posx >= 0x10000L) { | 327 while (posx >= 0x10000L) { |
351 ++srcx; | 328 ++srcx; |
352 posx -= 0x10000L; | 329 posx -= 0x10000L; |
353 } | 330 } |
354 src = ($format_type{$src} *)(data->src + (srcy * data->src_pitch) + (srcx * $format_size{$src})); | 331 src = ($format_type{$src} *)(info->src + (srcy * info->src_pitch) + (srcx * $format_size{$src})); |
355 __EOF__ | 332 __EOF__ |
356 print FILE <<__EOF__; | 333 print FILE <<__EOF__; |
357 } | 334 } |
358 __EOF__ | 335 __EOF__ |
359 output_copycore($src, $dst, $modulate, $blend); | 336 output_copycore($src, $dst, $modulate, $blend); |
360 print FILE <<__EOF__; | 337 print FILE <<__EOF__; |
361 posx += incx; | 338 posx += incx; |
362 ++dst; | 339 ++dst; |
363 } | 340 } |
364 posy += incy; | 341 posy += incy; |
365 data->dst += data->dst_pitch; | 342 info->dst += info->dst_pitch; |
366 } | 343 } |
367 __EOF__ | 344 __EOF__ |
368 } else { | 345 } else { |
369 print FILE <<__EOF__; | 346 print FILE <<__EOF__; |
370 | 347 |
371 while (data->dst_h--) { | 348 while (info->dst_h--) { |
372 $format_type{$src} *src = ($format_type{$src} *)data->src; | 349 $format_type{$src} *src = ($format_type{$src} *)info->src; |
373 $format_type{$dst} *dst = ($format_type{$dst} *)data->dst; | 350 $format_type{$dst} *dst = ($format_type{$dst} *)info->dst; |
374 int n = data->dst_w; | 351 int n = info->dst_w; |
375 while (n--) { | 352 while (n--) { |
376 __EOF__ | 353 __EOF__ |
377 output_copycore($src, $dst, $modulate, $blend); | 354 output_copycore($src, $dst, $modulate, $blend); |
378 print FILE <<__EOF__; | 355 print FILE <<__EOF__; |
379 ++src; | 356 ++src; |
380 ++dst; | 357 ++dst; |
381 } | 358 } |
382 data->src += data->src_pitch; | 359 info->src += info->src_pitch; |
383 data->dst += data->dst_pitch; | 360 info->dst += info->dst_pitch; |
384 } | 361 } |
385 __EOF__ | 362 __EOF__ |
386 } | 363 } |
387 print FILE <<__EOF__; | 364 print FILE <<__EOF__; |
388 return 0; | |
389 } | 365 } |
390 | 366 |
391 __EOF__ | 367 __EOF__ |
392 } | 368 } |
393 | 369 |
394 sub output_copyfunc_h | 370 sub output_copyfunc_h |
395 { | 371 { |
396 my $src = shift; | |
397 my $dst = shift; | |
398 for (my $modulate = 0; $modulate <= 1; ++$modulate) { | |
399 for (my $blend = 0; $blend <= 1; ++$blend) { | |
400 for (my $scale = 0; $scale <= 1; ++$scale) { | |
401 if ( $modulate || $blend || $scale ) { | |
402 output_copyfuncname("extern int SDLCALL", $src, $dst, $modulate, $blend, $scale, 1, ";\n"); | |
403 } | |
404 } | |
405 } | |
406 } | |
407 } | 372 } |
408 | 373 |
409 sub output_copyinc | 374 sub output_copyinc |
410 { | 375 { |
411 print FILE <<__EOF__; | 376 print FILE <<__EOF__; |
412 #include "SDL_video.h" | 377 #include "SDL_video.h" |
413 #include "SDL_rendercopy.h" | 378 #include "SDL_blit.h" |
379 #include "SDL_blit_auto.h" | |
414 | 380 |
415 __EOF__ | 381 __EOF__ |
416 } | 382 } |
417 | 383 |
418 sub output_copyfunctable | 384 sub output_copyfunctable |
419 { | 385 { |
420 print FILE <<__EOF__; | 386 print FILE <<__EOF__; |
421 static struct { | 387 static SDL_BlitFuncEntry _SDL_GeneratedBlitFuncTable[] = { |
422 Uint32 src_format; | |
423 Uint32 dst_format; | |
424 int modMode; | |
425 int blendMode; | |
426 int scaleMode; | |
427 SDL_RenderCopyFunc func; | |
428 } SDL_RenderCopyFuncTable[] = { | |
429 __EOF__ | 388 __EOF__ |
430 for (my $i = 0; $i <= $#src_formats; ++$i) { | 389 for (my $i = 0; $i <= $#src_formats; ++$i) { |
431 my $src = $src_formats[$i]; | 390 my $src = $src_formats[$i]; |
432 for (my $j = 0; $j <= $#dst_formats; ++$j) { | 391 for (my $j = 0; $j <= $#dst_formats; ++$j) { |
433 my $dst = $dst_formats[$j]; | 392 my $dst = $dst_formats[$j]; |
434 for (my $modulate = 0; $modulate <= 1; ++$modulate) { | 393 for (my $modulate = 0; $modulate <= 1; ++$modulate) { |
435 for (my $blend = 0; $blend <= 1; ++$blend) { | 394 for (my $blend = 0; $blend <= 1; ++$blend) { |
436 for (my $scale = 0; $scale <= 1; ++$scale) { | 395 for (my $scale = 0; $scale <= 1; ++$scale) { |
437 if ( $modulate || $blend || $scale ) { | 396 if ( $modulate || $blend || $scale ) { |
438 print FILE " { SDL_PIXELFORMAT_$src, SDL_PIXELFORMAT_$dst, "; | 397 print FILE " { SDL_PIXELFORMAT_$src, SDL_PIXELFORMAT_$dst, "; |
398 my $flags = ""; | |
399 my $flag = ""; | |
439 if ( $modulate ) { | 400 if ( $modulate ) { |
440 print FILE "(SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), "; | 401 $flag = "SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA"; |
441 } else { | 402 if ( $flags eq "" ) { |
442 print FILE "0, "; | 403 $flags = $flag; |
404 } else { | |
405 $flags = "$flags | $flag"; | |
406 } | |
443 } | 407 } |
444 if ( $blend ) { | 408 if ( $blend ) { |
445 print FILE "(SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), "; | 409 $flag = "SDL_COPY_MASK | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD"; |
446 } else { | 410 if ( $flags eq "" ) { |
447 print FILE "0, "; | 411 $flags = $flag; |
412 } else { | |
413 $flags = "$flags | $flag"; | |
414 } | |
448 } | 415 } |
449 if ( $scale ) { | 416 if ( $scale ) { |
450 print FILE "SDL_TEXTURESCALEMODE_FAST, "; | 417 $flag = "SDL_COPY_NEAREST"; |
451 } else { | 418 if ( $flags eq "" ) { |
452 print FILE "0, "; | 419 $flags = $flag; |
420 } else { | |
421 $flags = "$flags | $flag"; | |
422 } | |
453 } | 423 } |
424 if ( $flags eq "" ) { | |
425 $flags = "0"; | |
426 } | |
427 print FILE "($flags), SDL_CPU_ANY,"; | |
454 output_copyfuncname("", $src_formats[$i], $dst_formats[$j], $modulate, $blend, $scale, 0, " },\n"); | 428 output_copyfuncname("", $src_formats[$i], $dst_formats[$j], $modulate, $blend, $scale, 0, " },\n"); |
455 } | 429 } |
456 } | 430 } |
457 } | 431 } |
458 } | 432 } |
459 } | 433 } |
460 } | 434 } |
461 print FILE <<__EOF__; | 435 print FILE <<__EOF__; |
436 { 0, 0, 0, 0, NULL } | |
462 }; | 437 }; |
463 | 438 |
464 SDL_RenderCopyFunc SDL_GetRenderCopyFunc(Uint32 src_format, Uint32 dst_format, int modMode, int blendMode, int scaleMode) | 439 SDL_BlitFuncEntry *SDL_GeneratedBlitFuncTable = _SDL_GeneratedBlitFuncTable; |
465 { | |
466 int i; | |
467 | |
468 for (i = 0; i < SDL_arraysize(SDL_RenderCopyFuncTable); ++i) { | |
469 if (src_format != SDL_RenderCopyFuncTable[i].src_format) { | |
470 continue; | |
471 } | |
472 if (dst_format != SDL_RenderCopyFuncTable[i].dst_format) { | |
473 continue; | |
474 } | |
475 if ((modMode & SDL_RenderCopyFuncTable[i].modMode) != modMode) { | |
476 continue; | |
477 } | |
478 if ((blendMode & SDL_RenderCopyFuncTable[i].blendMode) != blendMode) { | |
479 continue; | |
480 } | |
481 if ((scaleMode & SDL_RenderCopyFuncTable[i].scaleMode) != scaleMode) { | |
482 continue; | |
483 } | |
484 return SDL_RenderCopyFuncTable[i].func; | |
485 } | |
486 return NULL; | |
487 } | |
488 | 440 |
489 __EOF__ | 441 __EOF__ |
490 } | 442 } |
491 | 443 |
492 sub output_copyfunc_c | 444 sub output_copyfunc_c |
503 } | 455 } |
504 } | 456 } |
505 } | 457 } |
506 } | 458 } |
507 | 459 |
508 open_file("SDL_rendercopy.h"); | 460 open_file("SDL_blit_auto.h"); |
509 output_copydefs(); | 461 output_copydefs(); |
510 for (my $i = 0; $i <= $#src_formats; ++$i) { | 462 for (my $i = 0; $i <= $#src_formats; ++$i) { |
511 for (my $j = 0; $j <= $#dst_formats; ++$j) { | 463 for (my $j = 0; $j <= $#dst_formats; ++$j) { |
512 output_copyfunc_h($src_formats[$i], $dst_formats[$j]); | 464 output_copyfunc_h($src_formats[$i], $dst_formats[$j]); |
513 } | 465 } |
514 } | 466 } |
515 print FILE "\n"; | 467 print FILE "\n"; |
516 close_file("SDL_rendercopy.h"); | 468 close_file("SDL_blit_auto.h"); |
517 | 469 |
518 open_file("SDL_rendercopy.c"); | 470 open_file("SDL_blit_auto.c"); |
519 output_copyinc(); | 471 output_copyinc(); |
520 output_copyfunctable(); | 472 output_copyfunctable(); |
521 for (my $i = 0; $i <= $#src_formats; ++$i) { | 473 for (my $i = 0; $i <= $#src_formats; ++$i) { |
522 for (my $j = 0; $j <= $#dst_formats; ++$j) { | 474 for (my $j = 0; $j <= $#dst_formats; ++$j) { |
523 output_copyfunc_c($src_formats[$i], $dst_formats[$j]); | 475 output_copyfunc_c($src_formats[$i], $dst_formats[$j]); |
524 } | 476 } |
525 } | 477 } |
526 close_file("SDL_rendercopy.c"); | 478 close_file("SDL_blit_auto.c"); |