Speed of clearing a working area on a bitmap
dthompson

I use 'working bitmaps' for quite a lot of my effects - for example, merging overlapping primitives before drawing them with reduced opacity:

Here, tmp needs to be cleared to 100% transparency before each draw. The most trivial way of doing this would be:

Alternatively, I could blank the area needed with a rectangle:

al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
al_draw_filled_rectangle(0, 0, 30, 30, al_map_rgba_f(0,0,0,0));

So, let's say I made the (perhaps poor) decision to clear a working area many times in my draw code. Given that al_clear_to_color ignores blending and transforms, I'm wondering whether it might be better-optimised than the primitives, despite the larger fill area.

Could someone with knowledge of Allegro's internals give me a hint as to what might be universally faster?

Edgar Reynaldo

Do yourself a favor and get out gdb. Set a breakpoint in al_clear_to_color and al_draw_filled_rectangle and step into the function and see what it does on the OpenGL / DX layer.

SiegeLord

I suspect clear is significantly faster given how much is necessary to accomplish the primitive drawing from Allegro's side.

Edgar Reynaldo

I doubt there's any faster way than just to use glClear.

dthompson

"just getting out gdb" would be fine for my specific case, but 'universal' is the operative word here; I had no idea whether some internals would run faster/slower on specific backends, OSes, or cards. For whatever reason.

From what SiegeLord is saying, though, clear sounds like it's always going to be faster. Ta ;)

Peter Hull
Edgar Reynaldo

Nice leg work Peter!

Thread #617799. Printed from Allegro.cc