FTEX (File Format)
The FTEX (caFe TEXture) texture format is a format for textures which appears as a subfile of a BFRES file. It appears in the 1:st index group in a BFRES file. Unless otherwise noted, all offsets in the file are relative to themselves.
An FTEX file begins with an 0xC0 byte header that starts with the file identifier, followed by info about the texture and mipmaps.
|0x00||4||Char||File magic. Always FTEX in ASCII.|
|0x04||4||UInt32||Dimension. Maps to GX2SurfaceDim (line 849 here). Indicates the "shape" of a given surface or texture.|
|0x08||4||UInt32||Texture width. Width of the texture in pixels.|
|0x0C||4||UInt32||Texture height. Height of the texture in pixels.|
|0x14||4||UInt32||Number of mipmaps.|
|0x18||4||UInt32||Texture format. Maps to GX2SurfaceFormat (line 589 here for explanation and format values).|
|0x1C||4||UInt32||AA mode. Maps to GX2AAMode (line 865 here). Indicates the AA mode (number of samples) for the surface.|
|0x20||4||UInt32||Usage. Maps to GX2SurfaceUse (line 823 here). Indicates how the given surface may be used.|
|0x24||4||UInt32||Data length. Length of texture data in bytes.|
|0x28||4||UInt32||Data pointer. Set at runtime.|
|0x2C||4||UInt32||Mipmaps data length. Length of mipmaps data in bytes.|
|0x30||4||UInt32||Mipmaps pointer. Set at runtime.|
|0x34||4||UInt32||Tile mode. Maps to GX2TileMode (line 795 here). Indicates the desired tiling mode for the surface.|
|0x3C||4||UInt32||Alignment. Always 512 * bytes per pixel.|
|0x44||0x34||UInt32||Mipmap offsets. An array of 13 offsets for each mipmap, relative to the start of the mipmap data.|
|0x7C||4||UInt32||Number of mipmaps (again).|
|0x80||4||UInt32||First slice. Always 0.|
|0x84||4||UInt32||Number of slices. Always 1.|
|0x88||4||Byte||Component Selector, determines which texture color channels are used for each target channel. The bytes map to the Red, Green, Blue and Alpha channel and can receive one of the following channels.
|0x8C||0x14||UInt32||Texture registers. Array of 5 unsigned integers with unknown purpose.|
|0xA0||4||UInt32||Texture handle. Set at runtime.|
|0xA4||4||UInt32||Array length (seems to be just a byte in MK8 files, with the remaining 3 bytes being padding?).|
|0xA8||4||Int32||File name offset.|
|0xAC||4||Int32||File path offset, the path of the file this data was originally created from. Stripped in Mario Kart 8 files, always pointing to an empty string at the end of the BFRES string table.|
|0xB0||4||Int32||Data offset. Offset to the texture data.|
|0xB4||4||Int32||Mipmap offset. Offset to the mipmap texture data.|
|0xB8||4||Int32||User Data Index Group offset.|
|0xBC||2||UInt16||User Data entry count.|
|0xC0||End of FTEX header|
The image and mipmap data is not present after the header. It comes after the BFRES string table instead. This seems to be a caching optimization, since the CPU generally doesn't need to handle the image data. Instead it is sent directly to the GPU.