[AD] Drawing a bitmap to itself...

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


... has many problems right now. From what I see to properly implement
it all we need quite a bit of code. Just thought I think a bit aloud
here before starting to implement it. A few alternate options would be:

1) Disallow drawing a bitmap to itself.

al_set_target_bitmap(b);
al_draw_bitmap(b); // Will trigger an ASSERT.

2) Disallow overlapped drawing to itself.

al_set_target_bitmap(b);
al_draw_bitmap_region(b);
al_draw_bitmap(sub_bitmap_of_b);
// Both will work as long as the region of pixels read does not
// overlap the region of pixels written. If there is overlap the
// behavior is undefined (but it won't crash).

3) Use some un-optimized blanket implementation, like internally replace

al_draw_bitmap(b)

with this whenever b (or its parent) is the target bitmap (or a
sub-bitmap thereof):

al_store_state(...);
al_set_new_bitmap_flags(...);
t = al_create_bitmap(...);
al_set_target_bitmap(t);
al_draw_bitmap(b);
al_set_target_bitmap(b);
al_draw_bitmap(t);
al_destroy_bitmap(t);
al_restore_state(...);


With option 3) whenever "b" is a big bitmap it would need lots of memory
and be very slow, so we might be better off with solution 1. Solution 1
is most clean, no side-effects like creating a temporary bitmap and no
undefined behavior like with solution 2. Of course it also limits what
you can do even more than solution 2.


I didn't think too much about how difficult exactly it would be to
properly implement this, I stopped when I realized that at least
sometimes a temporary bitmap is required and I couldn't implement it in
just a few hours. And given the limited use of drawing a bitmap to
itself one of the above options might do instead for 5.0 :)

-- 
Elias Pschernig <elias.pschernig@xxxxxxxxxx>





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/