dradtke/allegro_tiled — pull request #1 by JWill392 (2012-12-27 15:11:10+00:00)
Title: Draw performance improvement

Map drawing code was slow. By following a common recommendation from the Allegro forums, I significantly improved drawing performance. The change only adds four lines to draw.c.

Before this change, I was getting ~51 FPS with the example. After, I'm getting 59.9999 FPS.

The change consists of adding al_hold_bitmap_drawing() around the two main drawing functions (_al_draw_orthogonal_tile_layer and _al_draw_orthogonal_object_layer). This locks rendering so you can't change rendering state, and defers rendering the bitmaps till the hold is released. If all you're doing in a section of code is drawing bitmaps, this speeds it up.

Additional ways to improve performance:
+ Ensure all tiles on tileset A are drawn, then all tiles on tileset B, etc.
+ Apparently slowest operation is switching between physical textures (correct me if I'm wrong, but I think the only bitmaps that are on different physical textures are the tilesets -- that is, individual tiles are just sub-images of the tilesets)

References:
+ https://www.allegro.cc/manual/5/al_hold_bitmap_drawing
+ https://www.allegro.cc/forums/thread/609898
+ https://www.allegro.cc/forums/thread/610110