Difference between revisions of "FTEX (File Format)"

From MK8
Jump to navigation Jump to search
(Undo revision 3103 by Aboood40091 (talk))
m (Reverted edits by Aboood40091 (talk) to last revision by Wexos)
 
(15 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Under-construction| ''Please do not add speculation here''.}}
+
The '''FTEX''' (ca'''F'''e '''TEX'''ture) texture format is a format for textures which appears as a subfile of a '''[[BFRES (File Format)|BFRES file]]'''. It appears in the '''1:st''' [[index group]] in a [[BFRES (File Format)|BFRES file]]. Unless otherwise noted, all offsets in the file are relative to themselves.
 
 
The '''FTEX''' texture format is a format for textures which appears as a subfile of a '''[[BFRES (File Format)|BFRES file]]'''.
 
  
 
== Header (FTEX) ==
 
== Header (FTEX) ==
 +
An FTEX file begins with an 0xC0 byte header that starts with the file identifier, followed by info about the texture and mipmaps.
  
Every FTEX file begins with an 0xC0 byte '''FTEX''' header that starts with the file identifier, followed by info about the image.
 
 
{| class="wikitable"
 
{| class="wikitable"
! Offset
+
! Offset !! Size !! Type !! Description
! Size
+
|-
! Description
+
| 0x00 || 4 || Char[4] || '''File magic'''. Always ''FTEX'' in ASCII.
 +
|-
 +
| 0x04 || 4 || UInt32 || '''Dimension'''. Maps to '''GX2SurfaceDim''' (line 849 [http://pastebin.com/DCrP1w9x 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.
 +
|-
 +
| 0x10 || 4 || UInt32 || '''Texture depth'''.
 +
|-
 +
| 0x14 || 4 || UInt32 || '''Number of mipmaps'''.
 
|-
 
|-
| 0x00
+
| 0x18 || 4 || UInt32 || '''Texture format'''. Maps to '''GX2SurfaceFormat''' (line 589 [http://pastebin.com/DCrP1w9x here] for explanation and format values).
| 4
 
| "'''FTEX'''" File identifier, ASCII string.
 
 
|-
 
|-
| 0x04
+
| 0x1C || 4 || UInt32 || '''AA mode'''. Maps to '''GX2AAMode''' (line 865 [http://pastebin.com/DCrP1w9x here]). Indicates the AA mode (number of samples) for the surface.
| 4
 
| '''Dimension'''. Indicates the "shape" of a given surface or texture (see line 849 [http://pastebin.com/DCrP1w9x here]).
 
 
|-
 
|-
| 0x08
+
| 0x20 || 4 || UInt32 || '''Usage'''. Maps to '''GX2SurfaceUse''' (line 823 [http://pastebin.com/DCrP1w9x here]). Indicates how the given surface may be used.
| 4
 
| '''Texture Width'''. Width of the texture in pixels.
 
 
|-
 
|-
| 0x0C
+
| 0x24 || 4 || UInt32 || '''Data length'''. Length of texture data in bytes.
| 4
 
| '''Texture Height'''. Height of the texture in pixels.
 
 
|-
 
|-
| 0x10
+
| 0x28 || 4 || UInt32 || '''Data pointer'''. Set at runtime.
| 4
 
| '''Depth'''.
 
 
|-
 
|-
| 0x14
+
| 0x2C || 4 || UInt32 || '''Mipmaps data length'''. Length of mipmaps data in bytes.
| 4
 
| '''Number of Mipmaps'''.
 
 
|-
 
|-
| 0x18
+
| 0x30 || 4 || UInt32 || '''Mipmaps pointer'''. Set at runtime.
| 4
 
| '''Texture Format'''. Go to line 589 on [http://pastebin.com/DCrP1w9x this page] for explanation and format values.
 
 
|-
 
|-
| 0x1C
+
| 0x34 || 4 || UInt32 || '''Tile mode'''. Maps to '''GX2TileMode''' (line 795 [http://pastebin.com/DCrP1w9x here]). Indicates the desired tiling mode for the surface.
| 4
 
| '''AA Mode'''. Indicates the AA mode (number of samples) for the surface (see line 865 [http://pastebin.com/DCrP1w9x here]).
 
 
|-
 
|-
| 0x20
+
| 0x38 || 4 || UInt32 || '''Swizzle value'''.
| 4
 
| '''Usage'''. Indicates how the given surface may be used (see line 823 [http://pastebin.com/DCrP1w9x here]).
 
 
|-
 
|-
| 0x24
+
| 0x3C || 4 || UInt32 || '''Alignment'''. Always 512 * bytes per pixel.
| 4
 
| '''Data Length'''. Length of texture data in bytes.
 
 
|-
 
|-
| 0x28
+
| 0x40 || 4 || UInt32 || '''Pitch'''.
| 4
 
| '''Data Pointer?'''
 
 
|-
 
|-
| 0x2C
+
| 0x44 || 0x34 || UInt32[13] || '''Mipmap offsets'''. An array of 13 offsets for each mipmap, relative to the start of the mipmap data.
| 4
 
| '''Mipmaps Data Length'''. Length of mipmaps data in bytes.
 
 
|-
 
|-
| 0x30
+
| 0x78 || 4 || UInt32 || '''First mipmap'''.
| 4
 
| '''Mipmaps Pointer?'''
 
 
|-
 
|-
| 0x34
+
| 0x7C || 4 || UInt32 || '''Number of mipmaps''' (again).
| 4
 
| '''Tile Mode'''. Indicates the desired tiling mode for the surface (see line 795 [http://pastebin.com/DCrP1w9x here]).
 
 
|-
 
|-
| 0x38
+
| 0x80 || 4 || UInt32 || '''First slice'''. Always 0.
| 4
 
| '''Swizzle Value'''.
 
 
|-
 
|-
| 0x3C
+
| 0x84 || 4 || UInt32 || '''Number of slices'''. Always 1.
| 4
 
| '''Alignment'''. Always 512 * bytes per pixel.
 
 
|-
 
|-
| 0x40
+
| 0x88 || 4 || Byte[4] || '''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.
| 4
+
{| class="wikitable"
| '''Pitch'''.
+
! Value !! Name !! Description
 +
|-
 +
| 0 || R || The channel will receive the red values of the texture.
 +
|-
 +
| 1 || G || The channel will receive the green values of the texture.
 +
|-
 +
| 2 || B || The channel will receive the blue values of the texture.
 +
|-
 +
| 3 || A || The channel will receive the alpha values of the texture.
 +
|-
 +
| 4 || 0 || The channel will always have a value 0.
 +
|-
 +
| 5 || 1 || The channel will always have a value 1.
 +
|}
 
|-
 
|-
| 0x44
+
| 0x8C || 0x14 || UInt32[5] || '''Texture registers'''. Array of 5 unsigned integers with unknown purpose.
| 0x0D
 
| '''Mip Offset'''. Offset for each mipmap?
 
 
|-
 
|-
| 0x51
+
| 0xA0 || 4 || UInt32 || '''Texture handle'''. Set at runtime.
| 0x2B
 
| Unknown. Mipmaps related. (Always 0 in textures with no mipmaps)
 
 
|-
 
|-
| 0x7C
+
| 0xA4 || 4 || UInt32 || '''Array length''' (seems to be just a byte in MK8 files, with the remaining 3 bytes being padding?).
| 4
 
| '''Number of Mipmaps'''. Again...
 
 
|-
 
|-
| 0x80
+
| 0xA8 || 4 || Int32 || '''File name''' offset.
| 4
 
| Unknown. Always 0.
 
 
|-
 
|-
| 0x84
+
| 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 [[BFRES (File Format)#String Table|string table]].
| 4
 
| Unknown. Always 1.
 
 
|-
 
|-
| 0x88
+
| 0xB0 || 4 || Int32 || '''Data offset'''. Offset to the texture data.
| 4
 
| Unknown. Always 0x00010203. (Is this some kind of a pattern? 00->01->02->03)
 
 
|-
 
|-
| 0x8C
+
| 0xB4 || 4 || Int32 || '''Mipmap offset'''. Offset to the mipmap texture data.
| 0x24
 
| Unknown.
 
 
|-
 
|-
| 0xB0
+
| 0xB8 || 4 || Int32 || '''[[User Data]] [[Index Group]]''' offset.
| 4
 
| '''Data Offset'''. Offset to the texture data. Relative to this field.
 
 
|-
 
|-
| 0xB4
+
| 0xBC || 2 || UInt16 || '''[[User Data]] entry count'''.
| 4
 
| '''Mipmap Offset'''. Offset to the mipmap texture data. Relative to this field. '''0''' if not present.
 
 
|-
 
|-
| 0xB8
+
| 0xBE || 2 || — || Padding.
| 8
 
| {{Unknown}}
 
 
|-
 
|-
| 0xC0
+
| 0xC0 || colspan="3" {{Unknown|End of '''FTEX''' header}}
| colspan="2" {{Unknown|End of '''FTEX''' header}}
 
 
|}
 
|}
  
Incomplete header documentation. Last 8 words (32 bytes) seem to change per file. Offset 160 (dec) from FTEX header always seems to be zero, followed by a single byte (value of 1), 3 padding bytes, then a relative offset to the string table, then a relative offset to UnknownDataA, a relative offset to UnknownDataB, a relative offset to unknown DataC, and then two more unknowns (usually zero).
+
== Image Data ==
 +
The image and mipmap data is not present after the header. It comes after the [[BFRES (File Format)#String Table|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.
  
 
[[Category:File Format]]
 
[[Category:File Format]]

Latest revision as of 14:17, 19 June 2018

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.

Header (FTEX)

An FTEX file begins with an 0xC0 byte header that starts with the file identifier, followed by info about the texture and mipmaps.

Offset Size Type Description
0x00 4 Char[4] 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.
0x10 4 UInt32 Texture depth.
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.
0x38 4 UInt32 Swizzle value.
0x3C 4 UInt32 Alignment. Always 512 * bytes per pixel.
0x40 4 UInt32 Pitch.
0x44 0x34 UInt32[13] Mipmap offsets. An array of 13 offsets for each mipmap, relative to the start of the mipmap data.
0x78 4 UInt32 First mipmap.
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[4] 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.
Value Name Description
0 R The channel will receive the red values of the texture.
1 G The channel will receive the green values of the texture.
2 B The channel will receive the blue values of the texture.
3 A The channel will receive the alpha values of the texture.
4 0 The channel will always have a value 0.
5 1 The channel will always have a value 1.
0x8C 0x14 UInt32[5] 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.
0xBE 2 Padding.
0xC0 End of FTEX header

Image Data

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.