Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Does Aal_convert_bitmaps Preserve Bitmap Flags?

This thread is locked; no one can reply to it. rss feed Print
Does Aal_convert_bitmaps Preserve Bitmap Flags?
jmasterx
Member #11,410
October 2009

I found a bug in Allegro when using OpenGL and this laptop I have with a GMA 4400 on Win8.

When I go from fullscreen window back to windowed, things mess up and it doesnt go back to windowed.

Even ex_fullscreen_window messes up if I tell it to use GL. Ofcourse D3D works fine. -_-

To try to address this, I tried to recreate the display instead of toggling the flag. This works. Only issue is now none of the bitmaps have mipmap, mag linear, etc.

      m_sceneMessenger->sendContextWillChangedMessage();
      Vec2 resolution = getResolution();
      al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_PROGRAMMABLE_PIPELINE | ALLEGRO_WINDOWED);
      al_set_new_bitmap_flags(
        ALLEGRO_VIDEO_BITMAP | ALLEGRO_MIN_LINEAR | 
        ALLEGRO_MAG_LINEAR | ALLEGRO_MIPMAP | ALLEGRO_CONVERT_BITMAP);
      al_destroy_display(context);
      context = al_create_display(resolution.getX(),resolution.getY());
      al_set_new_bitmap_flags(
        ALLEGRO_VIDEO_BITMAP | ALLEGRO_MIN_LINEAR | 
        ALLEGRO_MAG_LINEAR | ALLEGRO_MIPMAP | ALLEGRO_CONVERT_BITMAP);
      al_convert_bitmaps();
      m_sceneMessenger->sendContextChangedMessage();

Is this normal or is al_convert_bitmaps supposed to restore mipmap, maglinear etc?

Using 5.1.10 on Windows 7/8

Bruce Pascoe
Member #15,931
April 2015
avatar

I've noticed that as well, if you try to un-fullscreen a fullscreen window in OpenGL mode it gets stuck in some sort of weird "limbo" state. It only seems to happen on Intel cards though, on my AMD machine it works fine.

What's weird is that I also has a screenshot feature, and if I activate that while it's in "limbo", the screenshot code cloning the backbuffer usually coaxes it the rest of the way out of fullscreen mode.

That might be a thing to try, actually: In your code that switches between fullscreen and windowed modes, what happens if you add this line after the switch:

Does that work around the issue?

jmasterx
Member #11,410
October 2009

Wow, that completely fixed it! Many thanks! :)

Bruce Pascoe
Member #15,931
April 2015
avatar

I hereby dub this fix "How I fixed Allegro fullscreen using this one weird trick" ;)

SiegeLord
Member #7,827
October 2006
avatar

From what I understand, when bitmaps get converted, they all get their flags set to what is passed to al_set_new_bitmap_flags. It's not obvious how to get them to preserve flags, since if there's a memory bitmap in between conversions, it'll necessarily lose some flags.

As for the fullscreen toggling, I'll investigate it at some point.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

jmasterx
Member #11,410
October 2009

SiegeLord said:

they all get their flags set to what is passed to al_set_new_bitmap_flags.

In this case that did not happen at all. I tried to shove calls to al_set_new_bitmap_flags with mipmap, mag linear etc before, after etc recreating the display but none of the bitmaps ever wound up having those attributes after conversion.

Maybe because Allegro notes that to have mipmap you need power of 2 textures and many of my textures are not power of 2 so maybe when they are converted they are not converted to power of 2?

Thomas Fjellstrom
Member #476
June 2000
avatar

I wonder if we should store the "last_flags" or something for a converted bitmap, so when its converted back it can keep its previous flags.

jmasterx said:

maybe when they are converted they are not converted to power of 2?

Hm, if allegro is actually turning your bitmaps into power of 2 textures, and isn't when its converting back, it probably should.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

SiegeLord
Member #7,827
October 2006
avatar

Alright, so the situation somewhat different. Turns out al_convert_bitmaps merely toggles whether the bitmap is memory or not, but otherwise it preserves the remaining flags. What was happening in your example was that when the display was destroyed, the flags were reset to just ALLEGRO_MEMORY_BITMAP. I've now fixed it to preserve the bitmap flags upon destruction, so everything should be fine.

I'm still investigating the toggling issue.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Bruce Pascoe
Member #15,931
April 2015
avatar

Alright, good you're still looking into that issue, it's been plaguing me for a while. It only seems to occur on machines with Intel graphics, my main development machine (AMD) doesn't exhibit it.

Regardless, the workaround I came up with above has to be my favorite fix of all time:

#SelectExpand
513 // strange but true: this fixes an Allegro bug where OpenGL displays get 514 // stuck in limbo when switching out of fullscreen. 515 al_destroy_bitmap(al_clone_bitmap(al_get_backbuffer(g_display)));

:P

Go to: