Which is a faster way to render tiles?

Hey guys. Nice to make your acquaintance. I'm quite new to allegro so please bear with my lack of knowledge.

I'm currently developing a tiling engine for my game and have come across two potential ways of rendering the tiles to the screen.

One is that in every frame, I calculate which sub rectangle of the tilemap intersect with the camera, and call many al_draw_bitmap_region per frame to render the tiles from my tilesheet bitmap to the screen.

The other one is that as soon as I have a tilemap loaded, I pre-render my entire tilemap onto a large bitmap (by calling many al_draw_bitmap_region), and every frame I simply render (al_draw_bitmap) that large bitmap to the screen. I got this method from reading the source of Flixel, and thought it is a rather smart way of doing this. But knowing that flash/AS is inherently different from allegro + C/C++, I'm dubious of whether or not this is a good idea in our case.

I'm not sure which one would be more efficient and I don't actually know how to test it :S. So here I am hoping that you guys could give me some tips.

Thanks in advance for any replies!


l j

You should not draw the entire tilemap on one large bitmap.
Allegro uses textures to store the bitmaps and the max size of a texture is limited. As far as I know allegro will not try to make a bitmap out of multiple textures but instead allocate a memory bitmap, which is slow.

I'm fairly sure it's a better idea to use al_draw_bitmap_region.
al_create_sub_bitmap Is an alternative.

If you're drawing the same bitmap many times, al_hold_bitmap_drawing ought to give you a performance boost.

edit: this post belongs in programming questions.

Todd Cope

The second way will be slightly faster but will only work if your map is small enough to fit into a single texture. I would recommend using the first way as it is more flexible and, if you use deferred rendering, will be plenty fast.

You need to be mindful of texture size limits as well. If your map is 4096x4096 pixels and you use the second method, your game will not work on my netbook (maximum texture size of 2048x2048 there).

Also, a large texture to hold a pre-rendered map uses a lot of memory. That is not usually an issue with desktop games, though.

The amount of time saved by using the second method will be negligible.

Edit: Beaten.


Wow, thanks guys for such fast replies.

large tilemaps are almost guaranteed later on so the pre-rendered bitmap does seem to be a bad idea now.

Deferred rendering sounds like a fantastic tool for the first method, I'll definitely use that for rendering tiles.

Thanks again for your answers!


Jeff Bernard
Todd Cope said:

If your map is 4096x4096 pixels and you use the second method, your game will not work on my netbook (maximum texture size of 2048x2048 there).

Out of curiosity, is there a way to programmatically get a device's maximum texture size?

Todd Cope

Yes, use this: al_get_display_option(display, ALLEGRO_MAX_BITMAP_SIZE);

Thread #612559. Printed from Allegro.cc