Pro OpenGL ES for iOS

(singke) #1

CHAPTER 9: Performance ’n’ Stuff (^297)
But don’t stop at fonts, because sprite sheets can also be applied anytime you have a
family of likeminded images. Switching from one texture to another can cause a lot of
unneeded overhead, whereas a sprite sheet acts as a form of texture batching, saving a
lot of GPU time. Check out the OS-X compatible Zwoptex tool, or TexturePacker, used
for general-purpose images.
Texture Uploads
Copying textures to the GPU can be very expensive, because they must reformatted by
the chip before they can be used. This can cause stuttering in the display for larger
textures. Therefore, make sure to load them up at the very start with glTexImage2D.
Mipmaps
Always make sure to use mipmaps for anything other than 2D unscaled images. Yes,
they do use a little more memory, but the smaller mipmaps can save a lot of cycles for
your objects when far away. It is recommended that you use GL_LINEAR_MIPMAP_NEAREST
because it is faster than GL_LINEAR_MIPMAP_LINEAR (albeit with a little less image fidelity).
Fewer Colors
Other recommendations might include lower-resolution color formats. A lot of imagery
would look almost as good at only 16 bits vs. 32, especially if there is no alpha mask.
Popular formats include RGBA5551 or RBGA4444, and RGB565. The latter assigns 6
bits for green because our eyes are more sensitive to green as opposed to red or blue.
On Distant Suns, my grayscale constellation artwork is only 8 bits, cutting memory
usage by 75 percent. Should I want it tinted to match a specific theme, I let OpenGL do
the work. With the proper tool and careful tweaking, some 16-bit textures are almost
indistinguishable from the 32-bitters.
Figure 9-5 illustrates four of these formats created by TexturePacker, with the highest to
lowest quality going from left to right. The first image is the true color one we’ve been
using, sometimes called ‘‘RGBA8888.’’ Next is RGB565, which still looks quite good
considering. The third one is RGBA5551, allocating a 1-bit alpha channel (notice how
much a difference the extra bit for green makes when compared to the previous texture),
and the rightmost image is the lowest quality one, RGB4444. TexturePacker also
supports the PVRTC file types referenced in Chapter 5.
Note An alternate (and free) tool is available from Imagination Technologies, the maker of
the PowerVR chips. It does the same texture modes as TexturePacker but doesn’t create sprite
sheets, as TexturePacker does. It uses X11 as the UI that is skinned to look like Windows-NT.
Go to http://www.imgtec.com and look for PowerVR Insider Utilities under the developer’s section.
Look for PVRTexTool.

Free download pdf