Defold supports automatic texture processing and compression of image data (in Atlas, Tile sources, Cubemaps and stand-alone textures used for models, GUI etc).
There are two types of compression, software image compression and hardware texture compression.
Software compression (such as PNG and JPEG) reduces the storage size of image resources. This makes the the final bundle size smaller. However, the image files need to be uncompressed when read into memory so even though an image is small on disk, it can have a large memory footprint.
Hardware texture compression also reduces the storage size of image resources. But, unlike software compression, it reduces the in-memory footprint for textures. This is because the graphics hardware is able to directly manage compressed textures without first having to uncompress them.
The processing of textures is configured through a specific texture profile. In this file you create profiles that express what compressed format(s) and type should be used when creating bundles for a specific platform. Profiles are then tied to matching file paths patterns, allowing fine tuned control over what files in your project should be compressed and exactly how.
Since all available hardware texture compression is lossy, you will get artifacts in your texture data. These artifacts are highly dependent on how your source material looks and what compression method is used. You should test your source material and experiment to get the best results. Google is your friend here.
You can select what software image compression is applied on the final texture data (compressed or raw) in the bundle archives. Defold supports WebP or ZLib (default). WebP supports both lossy and lossless compression and usually results in significantly better compression than ZLib, which is a general data compression algorithm
Compression is a resource intensive and time consuming operation that can cause very long build times depending on the number of texture images to compress and also the chosen texture formats and type of software compression.
Each project contains a specific .texture_profiles file that contains the configuration used when compressing textures. By default, this file is builtins/graphics/default.texture_profiles and it has a configuration matching every texture resource to a profile using RGBA with no hardware texture compression and using the default ZLib file compression.
To add texture compression:
You can turn on and off the use of texture profiles in the editor preferences. Select File ▸ Preferences.... The General tab contains a checkbox item Enable texture profiles.
The Path Settings section of the texture profiles file contains a list of path patterns and which profile to use when processing resources that match the path. The paths are expressed as “Ant Glob” patterns (see http://ant.apache.org/manual/dirtasks.html#patterns for details). Patterns can be expressed using the following wildcards:
sprite*.pngmatches the files sprite.png, sprite1.png and sprite_with_a_long_name.png.
sprite?.pngmatches the files sprite1.png, spriteA.png but not sprite.png or sprite_with_a_long_name.png.
/gui/**matches all files in the directory /gui and all its subdirectories.
This example contains two path patterns and their corresponding profiles.
Note that the more generic path is put last. The matcher works top down. The first occurrence that matches the resource path will be used. A matching path expression further down the list never overrides the first match. Had the paths been put in the opposite order every atlas would have been processed with profile “atlas”, even the ones in directory /gui.
Texture resources that do not match any path in the profiles file will be compiled and rescaled to the closest power of 2, but will otherwise be left intact.
The profiles section of the texture profiles file contains a list of named profiles. Each profile contains one or more platforms, each platform being described by a list of properties.
OS_ID_GENERICmatches all platforms including dev-app builds on device,
OS_ID_WINDOWSmatches Windows target bundles,
OS_ID_IOSmatches iOS bundles and so on. Note that if
OS_ID_GENERICis specified, it will be included for all platforms.
If two path settings matches the same file and the path uses different profiles with different platforms both profiles will be used and two texture will be generated.
The Formats added to a profile each have the following properties:
FAST(lowest quality, fast compression) to
BEST(highest quality, slowest compression).
COMPRESSION_TYPE_WEBP_LOSSY. See Compression Types below for more details.
Graphics hardware textures can be processed into uncompressed or lossy compressed data with various numbers of channels and bit depths. Hardware compression that is fixed means that the resulting image will be of a fixed size, regardless of the image content. This means that the quality loss during compression depends on the content of the original texture.
The following lossy compression formats are currently supported.
||none||3 channel color. Alpha is discarded|
||none||3 channel color and full alpha.|
||none||3 channel color. 5+6+5 bits.|
||none||3 channel color and full alpha. 4+4+4+4 bits.|
||none||1 channel gray-scale, no alpha. RGB channels multiplied into one. Alpha is discarded.|
||none||1 channel gray-scale and full alpha. RGB channels multiplied into one.|
||1:16 fixed.||No alpha. Requires square images. Non square images will be resized.|
||1:8 fixed||No alpha. Requires square images. Non square images will be resized.|
||1:16 fixed||Pre-multiplied alpha. Requires square images. Non square images will be resized.|
||1:8 fixed.||Pre-multiplied alpha. Requires square images. Non square images will be resized.|
||1:6 fixed||No alpha|
The following software image compression types are supported. The data is uncompressed when the texture file is loaded into memory.
||All formats||Generic lossless data compression. Default.|
||All formats||WebP lossless compression. Higher quality level results in smaller size.|
||All non hardware compressed formats.||WebP lossy compression. Lower quality level results in smaller size.|
For hardware compressed texture formats PVRTC or ETC, the WebP lossless compression process transforms the compressed hardware texture format data into data more suitable for WebP image compression using an internal intermediate format. This is then transformed back into the compressed hardware texture format when loaded by the run-time. WebP lossy type is currently not supported for hardware compressed texture formats PVRTC and ETC.
Did you spot an error or do you have a suggestion? Please let us know on GitHub!GITHUB