PROCEDURE Draw;
type
TByteArray = array [Word] of byte;
PByteArray = ^TByteArray;
VAR
x, y: SINGLE;
i,ix,iy,iw, ih , FormatSize : INTEGER;
FormatLock: ALLEGRO_PIXEL_FORMAT;
Screen, Temp: ALLEGRO_BITMAPptr;
Lock: ALLEGRO_LOCKED_REGIONptr;
Data: PByteArray;
BEGIN
iw := al_get_bitmap_width (Pattern);
ih := al_get_bitmap_height (Pattern);
al_set_blender (ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
al_clear_to_color (Background);
Screen := al_get_target_bitmap;
SetXY (8, 8);
{ Test 1. }
{ /* Disabled: drawing to same bitmap is not supported. }
(*
Print ('Screen -> Screen (%.1f fps)', get_fps(0));
get_xy(&x, &y);
al_draw_bitmap(ex.Pattern, x, y, 0);
start_timer(0);
al_draw_bitmap_region(screen, x, y, iw, ih, x + 8 + iw, y, 0);
stop_timer(0);
SetXY (x, y + ih);
*)
{ Test 2. }
Print ('Screen -> Bitmap -> Screen (%.1f fps)', [GetFPS (1)]);
GetXY (x, y);
al_draw_bitmap (Pattern, x, y, 0);
Temp := al_create_bitmap (iw, ih);
al_set_target_bitmap (Temp);
al_clear_to_color (Red);
StartTimer (1);
al_draw_bitmap_region (Screen, x, y, iw, ih, 0, 0, 0);
al_set_target_bitmap (Screen);
al_draw_bitmap (Temp, x + 8 + iw, y, 0);
StopTimer (1);
SetXY (x, y + ih);
al_destroy_bitmap (Temp);
{ Test 3. }
Print ('Screen -> Memory -> Screen (%.1f fps)', [getfps (2)]);
GetXY (x, y);
al_draw_bitmap (Pattern, x, y, 0);
al_set_new_bitmap_flags (ALLEGRO_MEMORY_BITMAP);
Temp := al_create_bitmap (iw, ih);
al_set_target_bitmap (Temp);
al_clear_to_color (Red);
StartTimer (2);
al_draw_bitmap_region (Screen, x, y, iw, ih, 0, 0, 0);
al_set_target_bitmap (Screen);
al_draw_bitmap (Temp, x + 8 + iw, y, 0);
StopTimer (2);
SetXY (x, y + ih);
al_destroy_bitmap (Temp);
al_set_new_bitmap_flags (ALLEGRO_VIDEO_BITMAP);
(*
Disabled because the "memcpy". I tried it but I never used 'memcpy' on C nor
pointers on Pascal so I don't know how to translate it. *)
{ Test 4. }
Print ('Screen -> Locked -> Screen (%.1f fps)', [getfps(3)]);
getxy(x, y);
al_draw_bitmap(Pattern, x, y, 0);
StartTimer (3);
ix := round(x);
iy := round(y);
lock := al_lock_bitmap_region(Screen, ix, iy, iw, ih,
ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY);
FormatLock := ALLEGRO_PIXEL_FORMAT(lock.format);
FormatSize := lock.pixel_size;
data := AllocMem(FormatSize * iw * ih);
for i := 0 to ih -1 do
move(PByteArray(lock.data)[ + i * lock.pitch],
data[ + i * FormatSize * iw],
FormatSize * iw
);
al_unlock_bitmap(Screen);
lock := al_lock_bitmap_region(Screen, ix + 8 + iw, iy, iw, ih, FormatLock,
ALLEGRO_LOCK_WRITEONLY);
for i := 0 to ih-1 do
move(data[ + i * FormatSize * iw],
PByteArray(lock.data)[ + i * lock.pitch],
FormatSize * iw);
al_unlock_bitmap(Screen);
freeMem(data);
StopTimer (3);
SetXY (x, y + ih);
END;