Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » The most effective use of al_hold_bitmap_drawing

This thread is locked; no one can reply to it. rss feed Print
The most effective use of al_hold_bitmap_drawing
Karolx
Member #16,821
March 2018

Hi,

I know there are already some thread with this topic, but none of the answers were quite exhaustive.

What is most effective usage of the al_hold_bitmap_drawing(true)? I am not sure if I understand the documentation correctly.

Specifically, do I have to to call al_hold_bitmap_drawing(false) every time the actually rendered bitmap (parent bitmap) changed from the last rendered or is it not neccessary? And if the second option is correct, is it simply enough to call al_hold_bitmap_drawing(true) before the first bitmap and then call al_hold_bitmap_drawing(false) just before the flip?

Thank you for answer.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

http://liballeg.org/a5docs/trunk/graphics.html#al_hold_bitmap_drawing

The main problem is changing the texture that is bound in the gpu. If you have to bind a different texture to draw the next object it takes longer, thus the fewer times you bind a new texture to draw the better. This is why tile or sprite atlases are used, because they keep all the related graphics on the same gpu texture.

You can draw whatever you want while drawing is held, but only drawing from the same few textures will get you a speed advantage when you release held drawing.

Karolx
Member #16,821
March 2018

I understand why we want to hold textures and why it is best to have as few textures as possible (or parent textures) and draw them with minimal switching between them.

My question is about the api. Do I have to do something when switching textures or it is possible to call al_hold_bitmap_drawing(true) before the first bitmap and then call al_hold_bitmap_drawing(false) just before the flip?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

I mostly answered that. Allegro will handle texture changes, but every time the texture is changed it must flush its cache of operations, which defeats the point of using held drawing.

So, you only need one pair of hold drawing calls. Allegro will take care of the rest.

Karolx
Member #16,821
March 2018

Thank you for answer(s). I know you mostly answered that, but I wanted an explicit answer to be sure. So thanks for that.

Maybe one little additional question. If Allegro can handle texture changes, is there any advantage of not using al_hold_bitmap_drawing?

Go to: