No hay resultados
We’ve come a long way from the custom 3D renderers and affine transformation tricks that used to be the stock and trade of every game programmer pushing the graphics envelope. Modern GPUs and frameworks let us concentrate (mostly) on the game we want to make, instead of the low-level drawing.
That doesn’t mean we are completely off the hook, though. We still have to (get to?) make choices about how the game looks and performs. We control the rendering technology—even if we don’t have to write it—and it’s up to us to tweak and optimize its behavior to suit our needs.
Texture maps are a great example. Applied almost like decals to the polygons of 3D objects, these images are essential assets that add depth, beauty, and realism. The price for this visual interest is a little extra configuration and resource management. Here are three simple ways you can improve your game’s appearance and performance when texture mapping on Fire tablets.
The latest generation of Fire tablets support OpenGL ES 3.0 and below, while older Kindle Fires support OpenGL ES 2.0. OpenGL ES makes working with textures easy, even if you are targeting multiple devices with varying capabilities. You can query the device at runtime to learn what is supported and adjust accordingly to optimize performance.
Maximum texture size, for example, describes the largest width or height possible for image data used as a texture. In the past, manufacturers tended to support only small sizes (e.g. 1K, 2K, or 4K on a side), and it was common to allocate video memory for textures based on the maximum size available—simple, if not especially efficient. With newer hardware supporting textures 8K or 16K across, though, this shortcut can rapidly exhaust all video memory.
Fire tablets support much larger texture sizes than other devices on the market, so allocating memory based on that limit by default is a bad idea. Instead, the best practice is to allocate memory based on your actual size requirements.
If you don’t plan on manipulating texture data at runtime, you can improve memory efficiency and performance by compressing your textures in advance. Compressed textures allow OpenGL ES to optimize video memory usage, making more of it available to your game and sometimes making what you have perform better. How you compress your data depends on your requirements and the device(s) where your game will run.
ETC1, a limited compression format supported by Android and Fire OS as a standard feature, is available on all Fire tablets. It does not support an alpha channel, though, which means textures compressed with ETC1 cannot have transparency. The ETC2/EAC format remedies this, supporting transparency as well as higher compression and better visual quality. It is a standard feature of OpenGL ES 3.0 and available on the latest Fire tablets, though not earlier models supporting only OpenGL ES 2.0.
Fire tablets also support GPU-specific texture compression formats. ATC compression works on devices with Qualcomm Adreno graphics processors, while those using PowerVR chips support the PVRTC format.
Qualcomm Adreno 420 Fire HDX 8.9 (4th Gen) Qualcomm Adreno 330 Kindle Fire HDX 8.9” (3rd Gen) Kindle Fire HDX 7” (3rd Gen) |
PowerVR G6200 Fire HD 7 (4th Gen) Fire HD 6 (4th Gen) PowerVR SGX 544 Kindle Fire HD 7” (3rd Gen) Kindle Fire HD 8.9” (2nd Gen) PowerVR SGX 540 Kindle Fire HD 7” (3rd Gen) Kindle Fire HD 8.9” (2nd Gen) PowerVR Kindle Fire (1st Gen) |
It is possible to combine multiple texture compression formats in a single APK. You can even include ATC and PVRTC textures together if you don’t want to release separate versions of your game based on GPU. In that case, you would determine at runtime which compression format was supported and load the appropriate set of textures.
Generically, a bitmap is a collection of picture elements related by proximity, palette, or some other characteristic. Similarly, a mipmap is a collection of related graphical objects, only these represent different levels of detail (LOD) for images. (The Latin multum in parvo, “much in little,” is where we get “mip.”) You can dramatically improve the appearance—and sometimes the performance—of your 3D game by pre-scaling certain images, especially those used as textures. The idea is to create high-quality “down-samples” that OpenGL ES will choose between, based on distance from the camera or 2D render size.
OpenGL ES can even interpolate between adjacent mipmap images (called trilinear filtering) to smooth the transition as objects move closer to or farther from the camera viewpoint. Because fewer texture pixels must be processed to render the down-samples (compared to simply scaling the full-sized image), they are drawn faster. Since they are anti-aliased as part of the pre-scaling step, the load on the GPU also decreases.
Image by Tokigun (CC BY-SA 3.0)
Using mipmaps in your game is straightforward, because OpenGL ES includes a function to generate them for you. It also allows you to specify the smoothing strategies it will apply when reducing and enlarging the images.
Even though much of the low-level drudgery of rendering has been pushed to frameworks and graphics processors, we are still in the driver's seat and ultimately control how our games look and how well they perform. These simple tips will help you fine tune the way OpenGL ES works with textures on Fire tablets, keeping your games running fast and looking great.
-peter (@peterdotgames)