Author Topic: blitting text and images  (Read 53007 times)

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
blitting text and images
« on: March 30, 2010, 04:02:41 pm »
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
« Last Edit: August 25, 2013, 08:34:49 pm by raft »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: blitting text and images
« Reply #1 on: March 30, 2010, 08:18:12 pm »
An apk would be cool in addition...

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: blitting text and images
« Reply #2 on: March 30, 2010, 08:26:22 pm »
An apk would be cool in addition...

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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: blitting text and images
« Reply #3 on: March 30, 2010, 08:41:27 pm »
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?

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: blitting text and images
« Reply #4 on: March 30, 2010, 08:53:24 pm »
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 ???

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: blitting text and images
« Reply #5 on: March 30, 2010, 09:01:49 pm »
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

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: blitting text and images
« Reply #6 on: March 30, 2010, 10:22:40 pm »
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 ???

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: blitting text and images
« Reply #7 on: March 30, 2010, 10:42:00 pm »
Which version of AE is this? The latest?

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: blitting text and images
« Reply #8 on: March 30, 2010, 11:05:38 pm »
latest i suppose (1.21). i downloaded yesterday

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: blitting text and images
« Reply #9 on: March 30, 2010, 11:24:09 pm »
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.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: blitting text and images
« Reply #10 on: March 30, 2010, 11:46:24 pm »
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 :)


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: blitting text and images
« Reply #11 on: March 31, 2010, 08:03:11 am »
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...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: blitting text and images
« Reply #12 on: March 31, 2010, 08:37:11 am »
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.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: blitting text and images
« Reply #13 on: March 31, 2010, 10:58:03 am »
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 ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: blitting text and images
« Reply #14 on: March 31, 2010, 12:23:01 pm »
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.