Performance plummets after changing screen mode
Andrew Gillett

After I destroy and recreate the display, my game's performance goes from about 2 ms per frame to 15+. In the menus, performance drops to around 10 seconds per frame. This made me wonder if it's the text drawing that has become slow, but increasing the amount of text drawn during the game only has a moderate, rather than disastrous, effect on frame rate.

I'm reloading all sprites and fonts after each screen mode change. Is there anything else I should be doing?

Resizing instead of recreating the display does not cause this problem.

Peter Hull

Reloading ought to create bitmaps as video bitmaps on the new current display, but my guess is it isn't for some reason. Can you try al_get_bitmap_flags on any of your bitmaps to check if they are indeed video and not memory bitmaps.
Also, as I understand it, al_convert_memory_bitmaps should do the conversion without requiring you to reload at all.
Finally check that the new display is current when bitmaps are loaded - it should be made current when it is created (remember current display is per-thread) but you could use al_set_target_backbuffer to be sure.
If you could create a minimal example that would be useful!

Andrew Gillett

al_convert_memory_bitmaps() isn't working. Some (or all?) bitmaps remain as memory bitmaps. If I call al_convert_bitmap each time I try to draw a memory bitmap, those bitmaps are converted, but the issue remains.

EDIT
I realised I don't need to re-create the display to change mode, I just need to call al_resize_display and/or al_set_display_flag(screen, ALLEGRO_FULLSCREEN_WINDOW, !windowed).

Would I be right in thinking that requesting a particular refresh rate is meaningless for windowed or fullscreen windowed modes?

Peter Hull

Does the resizing thing fix your problem now?
I don't know about refresh - it used to be relevant for CRT but modern displays don't have variable refresh rates?

I made this little prog:

#SelectExpand
1#include <allegro5/allegro.h> 2#include <allegro5/allegro_image.h> 3#include <stdio.h> 4 5void wot(ALLEGRO_BITMAP *b) { 6 if (al_get_bitmap_flags(b) & ALLEGRO_MEMORY_BITMAP) { 7 printf("It is a memory bitmap, "); 8 } else { 9 printf("It is not a memory bitmap, "); 10 } 11 if (al_get_bitmap_flags(b) & ALLEGRO_VIDEO_BITMAP) { 12 puts("it is a video bitmap"); 13 } else { 14 puts("it is not a video bitmap"); 15 } 16} 17int main() { 18 al_init(); 19 al_init_image_addon(); 20 ALLEGRO_DISPLAY *d1 = al_create_display(640, 480); 21 ALLEGRO_BITMAP *b = al_load_bitmap("b.png"); 22 wot(b); 23 al_destroy_display(d1); 24 wot(b); 25 d1 = al_create_display(320, 240); 26 wot(b); 27 al_destroy_bitmap(b); 28 al_destroy_display(d1); 29 30 return 0; 31}

on mac this does convert the bitmap to a memory bitmap and back. Does it work for you?

Andrew Gillett

Yes, resizing the window or switching between window and fullscreen window fixes the issue. Your code example works. However, I'm not sure the issue I was having has anything to do with any bitmaps I've created myself, as it only manifested in the menus, where only text is being drawn.

Thread #618255. Printed from Allegro.cc