There's one more optimization we can apply that is suited for 2D graphics programming with flat geometry, such as with rectangles. We'll look into that in the next chapter. The keyword to search for is batching, which means reducing the number of glDrawElements()/glDrawArrays() calls. An equivalent for 3D graphics exists as well, called instancing, but that's not possible to do with OpenGL ES 1.x.
I want to mention two more things before we close this chapter. First of all, when you run either BobText or OptimizedBobTest (which contains the superoptimized code we just developed), notice that the Bobs wobble around the screen somewhat. This is due to the fact that their positions are passed to glTranslatef() as floats. The problem with pixel-perfect rendering is that OpenGL ES is really sensitive to vertex positions with fractional parts in their coordinates. We can't really work around this problem; the effect will be less pronounced or even nonexistent in a real game, as we'll see when we implement our next game. We can hide the effect to some extent by using a more diverse background, among other things.
The second thing I want to point out is how we interpret the FPS measurements. As you can see from the preceding output, the FPS fluctuate a little. This can be attributed to background processes that run alongside our application. We will never have all of the system resources for our game, so we have to learn to live with this issue. When you are optimizing your program, don't fake the environment by killing all background processes. Run the application on a phone that is in a normal state, as you'd use it yourself during the day. This will reflect the same experience that a user will have.
Our nice achievement concludes this chapter. As a word of warning, only start optimizing your rendering code after you have it working, and only then after you actually have a performance problem. Premature optimization is often a cause for having to rewrite your entire rendering code, as it may become unmaintainable.
Was this article helpful?