I am writing a resource manager for my game which should tell if some limit of allocated resources has been breached and delete some least used resources in this case (as well as allocate resources, count how much memory is in use for these resources etc.).
However, I found that images take up much more space in memory than on disk, and I have no idea how to get the size of an uncompressed ALLEGRO_BITMAP. Is there a way to do this?
ALLEGRO_BTIMAP *bmp = al_load_bitmap("foo.png"); int size = al_get_bitmap_width(bmp) * al_get_bitmap_height(bmp) * al_get_pixel_size(al_get_bitmap_format(bmp));
That should do it.
That's a good idea, thank you, Thomas.
Note that if you use mipmapping, these numbers won't be totally accurate for vram usage.
Also note that, in some cases, such as using texture preservation in D3D, Allegro keeps a backup of the texture in system memory.
Also, in cases where non-power-of-2 textures are not supported, Allegro might pad your bitmap to PO2, so that might take up more memory. Sometimes too, the graphics driver will do this too.
Also, if you use Windows, you may want to try MSI Afterburner.
This neat tool can tell you how much vram is in use. So before you start your app, just note how much vram is used, and the difference between the value when your app is running and this start value is how much vram your app is consuming.