[AD] Improvements to the graphics drivers

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


So, there have been some discussion here, on the forums and irc about 3 major features that are generally desirable for Allegro 5 to have. I wanted to start working up to implementing them, so I figured I'd outline them here, with their rough proposed api. The are presented in the order I think they should be implemented.

1. Deferred drawing

Rationale: Basically this is to remove the overhead when drawing the same internal bitmap many many times, think tilemaps and fonts. Right now the solution is to use the primitives addon to cache these things and draw them via that, this is done, e.g. in the bitmap font addon right now. There's no reason that this can't be put in core library, as pretty much every game with tiles will run into these issues pretty quickly. Thus, the idea is to have a set of functions which turn on the deferred mode and turn it off. While the deferred mode is on, the al_draw_*_bitmap calls basically add sextuplets of vertices (two triangles) to an internal buffer that will be drawn once the mode is turned off. No state changes will be allowed in the deferred mode (although, we can simply flush the buffer internally for some limited sets of state changes, I'm thinking of changing the texture specifically).

Here's the proposed API. I'm not married to the exact name of the functions.

void al_hold_drawing();

Starts deferred drawing mode

void al_release_drawing();

Stops deferred drawing mode

I already started implementing something like this for the OpenGL driver just to see how it would work, so far there aren't any issues (things do become a little simpler if the ALLEGRO_TRANSFORM is put inside the core though).

2. Bitmap Atlasing

Atlasing is the inverse operation of bitmap sub-bitmapping. Basically, given a set of disparate bitmaps, combine them into a single, larger bitmap, and have them be sub-bitmaps of that biggeer bitmap. This naturally plays into the deferred drawing idea above, and gives it its true power, since bitmaps that belong to a single atlas can be drawn in one swoop. There will be a need to do 1px clamped boundaries for the GL_LINEAR folks, but otherwise it shouldn't be too hard. I did some quick research on algorithms and this thread seemed to be okay in terms of links:

http://www.gamedev.net/community/forums/topic.asp?topic_id=392413

Also see this for another take on the above:

http://en.wikipedia.org/wiki/Texture_atlas

Here's the API for it:

ALLEGRO_ATLAS* al_create_atlas(int width); 

Creates an atlas, all atlases are square (makes little point of creating a non-square atlast on POT-only GPU's)

void al_destroy_atlas();

Destroys the atlas and the bitmap, taking all the sub-bitmaps with it.

bool al_add_bitmap_to_atlas(ALLEGRO_ATLAS* atlas, ALLEGRO_BITMAP* bmp);

Attempts to add a bitmap to the atlas. Returns true on success, false on failure (bitmap bigger than the estimated empty space). If successful, the passed bitmap becomes a sub-bitmap of the atlas.

ALLEGRO_BITMAP* al_convert_atlas_to_bitmap(ALLEGRO_ATLAS* atlas);

Converts the atlas to just a bitmap and destroys the atlas. This is a memory saving operation, since most likely the atlasing algorithm will be using a rather sizeable tree, which games (especially those on mobile devices) probably don't want to lug around. Maybe unnecessary. Perhaps just have a al_finalize_atlas() that just deletes that tree, but keeps the atlas around.

3. ALLEGRO_TRANSFORM in the allegro core

This simplifies the deferred drawing implementation, and is overall desirable by some people. No new API, just making the implementation work for all drawing operations. This is easy for hardware stuff, not quite as much for the software stuff, but is still doable. For fonts I'd suggest not doing anything special, and just stretching the glyphs. Todd Cope said that this looks acceptable with GL_LINEAR turned on.

So any ideas/thoughts/suggestions? This is of course not for 4.9.15, but should be doable for 4.9.16, especially the first 2. I'm generally volunteering to do all those things if you're wondering :P But in principle the 3 things can be done in parallel by several people.

-SiegeLord


      




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