Sunday, June 7, 2009

Fast, high quality, small memory footprint. Pick two.

I've finally found a solution to my page-flipping animation problem. The short answer: PVRTC texture maps. PVRTC texture maps are extremely efficient. I've found I can load a 512x512 PVRTC texture directly from the iPhone filesystem for each unique frame of full screen animation and still main 60 frames per second. I repeat - 60 frames per second of fullscreen 320x480 page flipping animation with no a single image being pre-loaded or cached. I was very surprised at the speed difference.

That's the short answer. The long answer is this efficiency doesn't come without some tradeoffs. All the time I was trying to find a good solution to the full screen page-flipping animation problem, I would find things that worked, but the tradeoffs were usually unacceptable. For instance, I could get 30 FPS animation if I load all my frames of animation into ram first and just use drawRect. Given I had over 1300 frame of animation, this was not acceptable - the RAM requirements would be crazy!

My frames of animation are cell-shaded pictures and as jpg images, they only take about 30K each. However, when converted to a PVRTC, the size of each image is about 120K using the standard PVRTC compression and is 64K if I use the most aggressive compression. So, the tradeoff now is the app download size. Instead of being about 35 meg, it's now going to be about 80 meg. But, this is the most reasonable tradeoff of the bunch. I couldn't have my app use more RAM, and I didn't want to drop the frame rate even lower than 10 FPS, so opting for more filesystem space used with the benefit of 60 FPS seems like a decent trade off.

Now I just have to go through the process of converting all the images. Unfortunately, Apple's texturetool program is dog slow! It is taking over 4 seconds per 512x512 on my MacBook Pro. Fortunately I have batched the process using a perl script so I can just let it run overnight.

All content copyright © 2009  Brian Stormont, unless otherwise noted.   All rights reserved.