Game Development Reference
In-Depth Information
Droid (Android 2.1.1):
02-17 01:47:44.096: DEBUG/FPSCounter(1758): fps: 47
02-17 01:47:45.112: DEBUG/FPSCounter(1758): fps: 47
02-17 01:47:46.127: DEBUG/FPSCounter(1758): fps: 47
02-17 01:47:47.135: DEBUG/FPSCounter(1758): fps: 46
The Hero struggles quite a bit, but the game is playable at 25 FPS. The Nexus One achieves
around 41 FPS, and the Droid also reaches 47 FPS, which is pretty playable. Can it get better?
In terms of state changes, this is not all that bad. We could reduce some redundant changes
here and there, such as some glEnable() / glDisable() calls, but we know from previous
optimization attempts that doing so won't shave off a lot of overhead.
On the Hero, there's one thing we can do: disable lighting. Once we remove the respective
glEnable() / glDisable() calls in WorldRenderer.render() , as well as WorldRenderer.renderShip()
and WorldRenderer.renderInvaders() , the Hero achieves the following frame rate:
Hero (Android 1.5):
02-17 01:14:44.580: DEBUG/FPSCounter(618): fps: 31
02-17 01:14:45.600: DEBUG/FPSCounter(618): fps: 31
02-17 01:14:46.610: DEBUG/FPSCounter(618): fps: 31
02-17 01:14:47.630: DEBUG/FPSCounter(618): fps: 31
That's quite a bit of improvement, and all we have to do is turn off lighting. Special-casing the
rendering code for a certain device is possible, but it's good to avoid that. Is there anything else
we can do?
The way we render explosions is suboptimal in the case of an exploding invader. We change the
model and texture bindings in the middle of rendering all invaders, which makes the graphics
pipeline a little unhappy. However, explosions don't happen often, and don't take a long time
(1.6 seconds). Plus, the measurements just shown were taken without any explosions onscreen,
so that's not the culprit.
The truth is that we are rendering too many objects per frame, causing significant call overhead
and stalling the pipeline a little. With our current knowledge of OpenGL ES, there's nothing much
we can do about that. However, given that the game “feels� rather playable on all devices, it's
not an absolute must to achieve 60 FPS. The Droid and Nexus One have a notoriously hard time
rendering even mildly complex 3D scenes at 60 FPS. So, the final lesson to take away from this
is: don't get crazy if your game doesn't run at 60 FPS. If it is visually smooth and plays well, you
can even make do with 30 FPS.
Note Other common optimization strategies involve using culling, vertex buffer objects, and other
more advanced topics that aren't discussed here. We tried adding these to our Android Invaders—
the effect: zero. None of these devices benefit from these optimizations. That does not mean these
techniques are useless. That depends on a lot of factors and their side effects, and it's hard to
predict how certain configurations will behave. If you are interested, just search for those terms on
the Web and try the techniques out yourself!
 
Search WWH ::




Custom Search