The 2 main options for texture compression in OpenGL ES on IOS are KTX and PVR. Apples documentation details PVR because PowerVR chips run in all Apple mobile devices but the sample code seems to be out of date with the current Imagination Technologies file format specification.
KTX is a texture compression format created by Khronos, the custodians of OpenGL, and is independent of any chip-set or vendor. The website states
“KTX (Khronos Texture) is a lightweight file format for OpenGL® textures, designed around how textures are loaded in OpenGL. KTX files contain all the parameters needed for texture loading. A single file can contain anything from a simple base-level 2D texture through to an array texture with all mipmap levels. Textures can be stored in any of the compressed formats supported by OpenGL family APIs and extensions or can be stored uncompressed. The latest versions of OpenGL and OpenGL ES include support for ETC2 and EAC compressed textures as a standard feature.
The file format specification was created by Khronos’s OpenGL ES and ARB-OpenGL ES Convergence Working Groups and is applicable to both OpenGL and OpenGL ES.”
Khronos also provide libktx, an open source C library providing a set of functions for writing KTX files and for loading textures from them. Because it is hardware independent, supported in both OpenGL and OpenGL ES and there is an available C library for loading KTX files, the KTX format seems to be the better option to use in Woof.
Currently all textures for Woof, stored in PNG take 29.74mb of disk storage. This grows to 120mb when all images are decoded in memory. My KTX files take 12.3mb on disk and the same in memory as they do not need to be decoded before transferring to the graphics card.
Loading all assets (textures and models) when using PNG’s takes 67.5 seconds. This is unacceptable for a mobile game. Some mobile games take less than 67 seconds to play! When using compressed textures that time drops to 14.3 seconds. This too is a little high but I have some ideas how to reduce it further.
Why does it take almost 5 times as long to load 30mb of PNG’s than 12mb of KTX’s?
- PNG’s have to be decoded before they can be used by OpenGL. One PNG I use (2048×2048) is 626kb on disk but when decoded is 4mb. This extra processing takes time.
- The larger data (4mb as opposed to 350kb) has to be transferred to the graphics card once processed by the CPU.
- The KTX file already has all its mipmaps generated. The PNG does not so these must be generated before the texture can be used for rendering.
How do I generate KTX files?
Imagination Technologies, the owners of PVR, have a tool called PVRTexToolGUI which I have used to create my KTX textures.
The video above uses compressed textures which are encoded as ‘PVRTC 2bpp’ in ‘Normal (Good Quality)’ mode.