KTX (Khronos Texture Format)

1. Introduction

In Castle Game Engine we fully support KTX, Khronos Texture Format.

There’s nothing special you need to do to use KTX files in Castle Game Engine. Just load images in KTX format and display them as usual. Yo can refer to KTX image anywhere you would refer to an image (texture), e.g. you point to their URLs from TCastleImageControl.Url, TCastleImageTransform.Url, TDrawableImage, TImageTextureNode. See using images in the manual.

KTX in castle-image-viewer

2. Tooling

Our Castle Image Viewer supports KTX and allows to view each subimage of a KTX file.

We also have example utility image_decompose that allows to extract all subimages from a KTX file.

You may find example KTX images inside our demo models. Also KTX-Software has some samples (look in tests subdirectory).

3. Features

KTX is an excellent image format with a number of graphic features useful when it comes to using it for textures and 3D:

  • Can utilize GPU compression (images are compressed not only on disk, but also in GPU memory). We support these GPU-compressed formats in KTX:

    • S3TC (DXT* formats, often available on desktops),

    • ATITC (ATI compression, available on some mobile devices),

    • PVRTC (PowerVR compression, available on some mobile devices),

    • ETC1 (Ericsson compression, often available on mobile devices, but without alpha support).

    • More compressed formats can be trivially added, just submit a bugreport with a sample KTX file.

  • Float-based formats are fully supported. When encountered, KTX files with float-based data will be read to engine float-based formats, and passed as floats to the GPU (so your shaders can enjoy data that has higher-precision and is not bounded to the [0, 1] range):

  • Textures can have explicit mipmaps (allows texture have better quality when viewer from far away).

  • Volume (3D) textures.

  • Configurable orientation of the image data in file. KTX data may be specified in top-to-bottom or bottom-to-top order. For 3D images, the slices can additionally be in front-to-back or back-to-front order. We support all these possibilities.

  • Cube map can be stored — this means that we effectively have 6 images (for skyboxes, reflections, etc.). TODO: We don’t support cubemap yet, but we plan to add it. Submit a bugreport with a sample KTX file to make it happen sooner!

We support KTX 1 right now. We plan to support KTX 2 (with KHR_texture_basisu) in the future too.

4. Enumerating KTX subimages using Pascal

You can use CastleInternalCompositeImage unit to load KTX files and explicitly iterate over subimages inside KTX. For example, to iterate over items in a texture array in KTX, for any purpose.

Warning
As the name suggests, CastleInternalCompositeImage is an internal unit and its API may change arbitrarily in the future. Please let us know if you actually need this functionality and why — at the very least, we will consider making it "official" (e.g. unit CastleCompositeImage) and we will put effort to not break its API.

To improve this documentation just edit this page and create a pull request to cge-www repository.