Rendering Subsystem Description

TextureCache

The TextureCache system deals with unloading texture resources. It is intended to be used on memory constrained systems, such as mobile platforms, to reduce the total memory footprint, although it is available on every platform. However, it is only initialized by default on iOS, Android and PS Vita platforms, during the implicit creation of the TextureManager object, inside HAL::InitHAL. The TextureCache is only applicable on images whose image data is smaller than its texture data, meaning compressed images that must be decoded into uncompressed RGBA color data to be used by the GPU. These include PNG, JPEG and Flash-internal image formats. It does not apply to images that are compressed and can be used by the GPU directly, or images that are uncompressed – these data for these images is automatically unloaded once their texture data is copied from the image.

If the TextureManager is being allocated and passed into HALInitParams, it takes a TextureCache as the last parameter of its constructor. Only one implementation of the TextureCache is provided, named TextureCacheGeneric, however the user may create a derived TextureCache implementation. If this is the case, the TextureManager must be allocated and passed a derived TextureCache instance, and then the TextureManager must be passed into the InitHAL via the HALInitParams.

The generic implementation of TextureCache employs a simple LRU strategy for evicting textures from memory. It will not attempt to evict any textures until a threshold of applicable textures are allocated. Once the threshold has been reached (8MB by default), it will attempt to evict LRU texture, until it is under the limit again. If the limit cannot be achieved, because more than threshold of texture memory is used in a single frame, then a warning is emitted. The limit is adjustable at runtime, using the SetLimitSize function of the TextureCache. The system will never evict textures that are required for proper rendering.