Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Threading bitmap loads

Credits go to beoran for helping out!
This thread is locked; no one can reply to it. rss feed Print
Threading bitmap loads
pmprog
Member #11,579
January 2010
avatar

So, in OpenApoc, I was loading my menu GUI from XML, and rendering it to the screen. I got really confused why when loading from the XML it ran really slowly and jerky, but when I manually constructed the UI, it was smooth.

Anyway, long story short, it was because I threaded the load of the XML (which included the bitmap).

Now, when you try and draw with a bitmap loaded in a different thread, it takes a lot longer to render (I assume it's something to do with handing references between threads)

How can I go about threading my load, but without the overhead when it comes to rendering?

beoran
Member #12,636
March 2011

What probably happens is that the images got loaded in the wrong format. Normally, Allegro will use the display format to convert your images to display format for optimal performance. Likely the thread mis-loads the format and also loads the images as memory bitmaps, not video bitmaps.

Now I haven't done this before but I guess the way for you would be to open a display, inspect it's format with al_get_display_format, and then set that format with al_set_new_bitmap_format , then ensure that you will make video bitmap with al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP) and finally clone the loaded bitmap to the right format with al_clone_bitmap.

Thomas Fjellstrom
Member #476
June 2000
avatar

In some version of 5.1, you also get: al_convert_bitmap and al_convert_bitmaps which may or may not be faster and more efficient than al_clone_bitmap.

--
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

pmprog
Member #11,579
January 2010
avatar

Ah, I never really thought about display formats over threads, but that makes a lot of sense.

Thanks, I'll give it a try.

Edit: This didn't actually help me any. I'll just considering ditching the threaded loads

Max Savenkov
Member #4,613
May 2004
avatar

Did you try to actually profile the code to see what's causing slowdowns? It might be something unexpected.

pmprog
Member #11,579
January 2010
avatar

I remember thinking about it, but I couldn't find any tools in VS2013 for it... Having just opened VS2013 now, I think I was just going blind, will have a go tonight.

Though, I've actually modified my loading code, I only load images at first attempt to render them; otherwise, I would have been loading practically every reasource for the game straight off, and that could have been quite a chunk of memory. Still, I guess it'll be nice to know for future

Max Savenkov
Member #4,613
May 2004
avatar

You can use one of the 3rd party profiling tools. I myself quite liked Luke Stackwalker and VerySleepy. But I recently saw the new version of (free) AMD CodeXL tool and it was quite a step ahead of their old CodeAnalyst offering, so you can also use it.

Go to: