Thursday, June 16, 2011

Image Transparency & Performance (Frame Rate) Solved

Moving from a Android Phone to an Android Tablet, I have been having a hell of a time trying to keep my frame-rate stable and about 60FPS.  Search as I may on the internet, no one seems to have asked or answered this question so let me post it here:
"How can I draw many Sprites/Bitmaps that contain transparency on a (SurfaceView) canvas  in Android without having my framerate (FPS) go to hell?"
Things worked fine on my phone (58FPS), but deploying the same app to my tablet, the framerate chugs to (>30FPS) I assumed it had something to do with the larger screen.  (I however assumed the video card would be "beefer" on the Tablet, so I couldn't quite understand what was going on.)

Searching the internet I found this article from Romain Guy about the performance of rendering to give you more information. in general the performance for rendering an RGB_565 image verses others can 1.5 to 2x faster (Depending on the screen you are rendering to.)


That made some sense, but then I had read many times that transparencies are not possible in RGB_565 format (Which is not true by the way, it just does not contain an Alpha channel, big difference).  the ARGB_4444 format means literally 4 bits for each Alpha, Red, Green, Blue
RGB_565 means 5 bytes Red, 6 bytes Green, 5 bytes Blue

RGB_565 does have a "transparent" pixel value the int (0) so images stored as PNGs and read in (with transparency) or you can create a bitmap:


Bitmap bitmap = Bitmap.createBitmap(width, height, Config.RGB_565);

anyways, this has made a HUGE difference, too bad it's taken this many days of struggling trying other workarounds... hopefully someone else out there will find this info and it will be a help to them...

Added Note:
For gingerbread... all windows are 32 bits, OpenGL is 16 bits for compatibility
http://www.curious-creature.org/2010/12/04/gingerbread-and-32-bits-windows/

Side note: playing Plants verses Zombies on android tablet and I think they are suffering from this problem (using the wrong assets to draw on the screen), the framerate practically kills this stellar experience
for me.

1 comment:

  1. Although the article would lead you to believe that using ARGB_8888, in practice on my iconia Atab this yields me a framerate of around 24 FPS...

    change the setting to a RGB_565 and the framerate is back up to 58 FPS...

    Something going on with this Iconia Video Card. I thought it is a tegra so maybe there is an issue.

    ReplyDelete