blitting text and images

Started by raft, March 30, 2010, 04:02:41 PM

Previous topic - Next topic

raft

here are Android versions of two small and (hopefully) handy classes for blitting text and images. more information can be found on original thread

TexturePack packs several arbitrary sized images into a jPCT texture. it automatically layouts images and adjusts Texture size.

AGLFont creates GL renderable (blittable) fonts out of Android fonts.

Rectangle is used by AGLFont.

Bones Android demo app demonstrates how to use it

and an addition to GLFont by nmare which allows multi-line and multi-color text blits

cheers ;D
r a f t

edit: updated the links and fixed getStringBounds(..) issue
edit2: added link to nmare's addition

EgonOlsen

An apk would be cool in addition...

raft

Quote from: EgonOlsen on March 30, 2010, 08:18:12 PM
An apk would be cool in addition...

already there is an apk indeed. it's listed in Bones home page

EgonOlsen

I see...works fine (30fps without/8fps with animation) and looks great on my phone. I would be very interested to know how this runs on the Nexus One... dl.zerocool to the rescue?

raft

i've already asked him for a test ;) hoping he wont mind quoting from pm:

Quote
Here is some basic results. Apparently everything runs pretty fine.
while not animating fps are arround 55 to 59

When the animation starts you drop down to 15fps to 20fps~ depending on which animation you choose, then after a second it goes back to 30fps even "spin" animation who look like a little bit slower that the other (sometimes it fall back from 30 to 26 fps)

What is strange is that all animation get stuck to 30fps after a second, like there's something synchronizing behind.
I didn't had time to look at your code, so at moment I'm just running the apk demo.

slow down while animating is expected. but i cant explain it gain some speed again. it behaves like it has JIT but it hasnt AFAIK. maybe Android detects continuous data flow and make some optimization ???

EgonOlsen

I think so. I've noticed that too on my applications just to a smaller amount. Dalvik might do some caching or similar. However, 30 fps is a pretty good result. If they enable this new JIT in addition, maybe 50-60 fps will be possible... ;D

raft

capture of some speech bubbles on emulator.
texts are blitted with GLFont, bubble images are blitted with TexturePack:



blitting really hurts performace at least on emulator, dont know why ???

EgonOlsen

Which version of AE is this? The latest?

raft

latest i suppose (1.21). i downloaded yesterday

EgonOlsen

Yes, that should be the latest then. I was asking, because i already improved blitting performance. I assume that each character is a single, transparent and maybe scaled blit? Is there an apk to try this on actual hardware? The emulator isn't a fillrate wonder.
However, i can see one or two additional optimizations...i'll give them a try either tomorrow or next week.

raft

indeed it was sunday i suppose, does it make a difference ?
right, each character is single, transparent but unscaled blit. each balloon image are two (border and inside) transparent and scaled blits.

here is an apk: http://www.aptalkarga.com/tmp/A1.apk
center key adds a random bubble. they disappear after some seconds
you should probably need to remove old S1 or A1 before installing this.

thanks :)


EgonOlsen

It starts with 8fps and slows down to almost 0 if i keep adding bubbles. Looks like as if you are not discarding the bubbles once they moved out of the screen. However, 8 fps isn't really fast either. I'll write myself a test case to see how much this can be improved...then again, i don't expect any miracles unless i'm doing something really stupid that i haven't noticed yet. But basically, blitting is like playing an animation, i.e. it's all about pumping new vertices to the GPU each frame. That part can be optimized a little bit by using indexed geometry (which might run 10-20% faster than now), but apart from that, i don't see much room for improvement. We'll see...

EgonOlsen

You might want to try to order your blits by texture if possible. The less texture changes there are, the better. However, i don't think that this will help very much, but maybe it's worth a try anyway.

raft

yes, out of screen condition is not checked. it wasnt necessary for desktop version. i can do it. in real life there aren't many bubbles on the fly at the same time, but it wont hurt but help for sure..

i've tried blitting all text at last. which is kind of sorting. did slightly help: ~5-10% increase

i definitely need a boost here. 10-20% even 30-40% range wont help much

  • i can try to use android text utilities. i'm not sure this is possible over GL surface and even if possible i seriously doubt it will perform any better.
  • instead of character blitting, i can render each bubble's text to a texture and blit it. this is what i do in desktop karga except it's java2d not blitting. this will dramatically reduce number of blits in cost of texture creation
  • what else ?

EgonOlsen

You might use a modified approach of your second bullet point, by filling some pre-generated textures with the bubble texts via an ITextureEffect. That will reduce at least some of the overhead of creating new textures.