Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Processor-intensive Gosu::BlockAllocator while loading image
- - By Jamer Date 2011-11-16 09:35
Hello again,

I have a small C++ application that subdivides a large sheet image into about one hundred smaller 16x16 pixel images using imagesFromTiledBitmap().  My issue is this: that function takes an inordinatly large 95% of my program's cycles.  Additionally, it introduces an unpreferable delay into the loading of game areas.  Profiling reveals that most all of that is from Gosu::BlockAllocator::alloc and Gosu::BlockAllocator::Impl::isBlockFree.

I was wondering why this is so slow and if it would be any faster to just load up the image into a single texture and then just render offset rectangles from that onto the screen.

Thanks,
Jamer

Attached gprof log from application: http://osdg.net/~pm/gprof.txt
Parent - - By jlnr (dev) Date 2011-11-16 11:08
Hey,

Is this from a release build? The BlockAllocator is something that might be especially slooow in debug.

Anyway, Gosu splits up and pads each individual tile with a 1-pixel border because otherwise, they would bleed (seemingly) random colors once they are drawn with some scaling or rotation. (And even Gosu's fullscreen mode can add scaling.)

The algorithm is really brute-force though. I plan to understand & try Carmack's block allocation from Q2 on a free afternoon, here's the link if the problem seems interesting to you :) http://fabiensanglard.net/quake2/quake2_opengl_renderer.php, it's LM_AllocBlock.
Parent - - By Jamer Date 2011-11-16 11:41
Oh, I was also going to ask about those colors. They appear for me with fullscreen scaling even with a 1-pixel border.
Parent - - By jlnr (dev) Date 2011-11-16 12:24
Even on opaque tiles? Do you scale them manually in addition to fullscreen scaling? Hard to imagine how that would happen :S

I am asking about opaque tiles because sometimes, the transparent pixels in PNG files have the weirdest color values with only alpha being 0.
Parent - - By Jamer Date 2011-11-16 12:33
No, only transparent pixels in PNGs. And no, I only scale them with fullscreen.

I have not seen it in opaque tiles. Do you know of any way to fix the color bleed with transparent images?
Parent - By jlnr (dev) Date 2011-11-16 13:19
No. Photoshop has functionality to remove black and white "matte", but I never got it to do what I want.

If you only need 1-bit transparency, you can just use BMP files. Gosu will fill in transparent parts with the average color values of adjacent pixels, except with alpha=0. But now that I think about it, it does this BEFORE splitting up the bitmap, not afterwards. (*adds To Do item*)
Parent - By Jamer Date 2011-11-22 06:47 Edited 2011-11-22 08:24
I've made another (unofficial) measurement with the profiler. This time it's with my patch applied. I'm getting a reduction in CPU usage from 0.20 seconds to 0.01 seconds. :)

http://osdg.net/~pm/gprof2.txt
Parent - By jlnr (dev) Date 2011-11-16 11:09
Of course, if imagesFromTiledBitmap would know about padding and the image would happen to be a square power-of-two size, it should do what you are saying :) Or maybe Gosu should just be able to dump tilesheets altogether, so that you'd only have to compute them on the first run. That would enable texture compression for iOS too, but I have never come up with a nice interface for that.
Up Topic Gosu / Gosu Exchange / Processor-intensive Gosu::BlockAllocator while loading image

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill