Warning: Can't synchronize with the repository (Couldn't open Subversion repository /home/crystal/scm/crystal: SubversionException: ("Expected FS format between '1' and '3'; found format '4'", 160043)). Look in the Trac log for more information.

This is an idea on hoe to encode texture formats into strings.

Special formats

Special formats are simple: they're designated by a string starting with *, everything else afterwards is arbitrary.

Examples:

  • *dxt1 DXT1 compressed texture
  • *3dc 3Dc compressed texture

General formats

The general syntax is (in dog  EBNF): format := components {components} [_ format]; components := component {component} size; whereas component is the component type, summarized below, size is the width of the component, in bit, and format is an optional specifier for the component format.

Component types

rRed
gGreen
bBlue
aAlpha
xJunk (unused)
lLuminance
dDepth
sStencil

Open questions

  • There are only so much letters. Even when also taking uppercase letters there's only a limited number of component types. Also, same letters may lend themselves to different types.

Format

Format optionally specifies how the data is encoded.

fFloat

Examples:

  • abgr32_f: Red, green, blue, alpha are stored as 32-bit floats.

Matching components and sizes

A component has the size as specified by the next size specifier right of it.

Examples:

  • argb8, a8r8g8b8: Red, green, blue, alpha are all 8 bit wide.
  • r5g6b5: Red is 5 bit wide, green 6 bit, blue 5bit.
  • x1rgb5, x1r5g5b5: Red, green, blue are all 5 bit wide. One bit is unused.

Open questions

  • Always require size or default to 8?

Storage

The leftmost component is stored in the most significant bits; the rightmost component in the least significant bits. A tuple of components is interpreted as a word with the size being the sum of all component sizes, rounded up to the next multiple of 8. These words are then stored in little-endian.

This means that for formats with 8-bit components, the bytes in memory are swapped in comparison to their order in the format string. See the examples.

Examples:

  • argb8 When interpreted as 32-bit words, blue is in bits 0-7, green in 8-15, red in 16-23, alpha 24-31. When interpreted as bytes, it's four bytes, the first stores blue, the second green, the third red, the fourth alpha.
  • r5g6b5: Red is stored in the 5 most significant bits of the second byte, green in the 3 least significant bits of the second byte and 3 most significant bits of the first byte, blue in the 5 least significant bits of the first byte.

Open questions

  • Endianness? E.g. in which byte order are the components of rgb16 stored? Perhaps check how relevant GL exts specify that.

More examples

  • d24: 24-bit depth texture.
  • d24s8: Combined 24-bit depth and 8-bit stencil texture.