R8G8B8

In Microsoft Direct3D, all two-dimensional (2-D) images are represented by a linear range of memory called a surface. A surface can be thought of as a 2-D array in which each element holds a color value that represents a small section of the image, called a pixel. An image's detail level is defined both by the number of pixels needed to represent the image and the number of bits needed for the image's color spectrum. For example, an image that is 800 pixels wide by 600 pixels tall with 32 bits of color for each pixel (written as 800x600x32) is more detailed then an image that is 640 pixels wide by 480 pixels tall with 16 bits of color for each pixel (written as 640x480x16). Likewise, the more detailed image requires a larger surface to store the data. For an 800x600x32 image, the surface's array dimensions are 800x600, and each element holds a 32-bit value to represent its color.

All surfaces have a size and store a specific number of bits that represent color. These bits are separated into individual color elements: red, green, and blue. In Microsoft DirectX 9.0 for Managed Code, all color elements are defined by the Format enumeration. A color format is broken down into the number of byes reserved for each color. For example, a 16-bit color format is defined as Format.R5G6B5, where five bits are reserved for red (R), six bits for green (G), and five bits for blue (B).

All formats are listed from left to right, most significant bit (MSB) to least significant bit (LSB). For example, ARGB is ordered from the MSB channel A (alpha) to the LSB channel B (blue). During traversal of surface data, the data is stored in memory from LSB to MSB, which means that the channel order in memory is from LSB (blue) to MSB (alpha).

The default value for formats that contain undefined channels is 1. The only exception is the A8 format, which is initialized to 000 for the three color channels.

Unsigned Formats

Data in an unsigned format must be positive. Unsigned formats use combinations of (R)ed, (G)reen, (B)lue, (A)lpha, (L)uminance, and (P)alette data. Palette data is also referred to as color-indexed data because the data is used to index a color palette.

Unsigned format flags Format
R8G8B8 A 24-bit RGB pixel format that uses 8 bits per channel.
A8R8G8B8 A 32-bit ARGB pixel format, with alpha, that uses 8 bits per channel.
X8R8G8B8 A 32-bit RGB pixel format in which 8 bits are reserved for each color.
R5G6B5 A 16-bit RGB pixel format that uses 5 bits for red, 6 bits for green, and 5 bits for blue.
X1R5G5B5 A 16-bit pixel format in which 5 bits are reserved for each color.
A1R5G5B5 A 16-bit pixel format in which 5 bits are reserved for each color and 1 bit is reserved for alpha.
A4R4G4B4 A 16-bit ARGB pixel format that uses 4 bits for each channel.
R3G3B2 An 8-bit RGB texture format that uses 3 bits for red, 3 bits for green, and 2 bits for blue.
ii An 8-bit format that uses alpha only.
A8R3G3B2 A 16-bit ARGB texture format that uses 8 bits for alpha, 3 bits each for red and green, and 2 bits for blue.
X4R4G4B4 A 16-bit RGB pixel format that uses 4 bits for each color.
A2B10G10R10 A 32-bit pixel format that uses 10 bits for each color and 2 bits for alpha.
A8B8G8R8 A 32-bit ARGB pixel format, with alpha, that uses 8 bits per channel.
X8B8G8R8 A 32-bit RGB pixel format in which 8 bits are reserved for each color.
G16R16 A 32-bit pixel format that uses 16 bits each for green and red.
A2R10G10B10 A 32-bit pixel format that uses 10 bits each for red, green, and blue, and 2 bits for alpha.
A16B16G16R16 A 64-bit pixel format that uses 16 bits for each component.
A8P8 An 8-bit color format indexed with 8 bits of alpha.
P8 An 8-bit color indexed format.
L8 An 8-bit luminance-only format.
L16 A 16-bit luminance-only format.
A8L8 A 16-bit format that uses 8 bits each for alpha and luminance.
A4L4 An 8-bit format that uses 4 bits each for alpha and luminance.

Signed Formats

Data in a signed format can be both positive and negative. Signed formats use combinations of (U), (V), (W), and (Q) data.

Signed-format flags Format
V8U8 A 16-bit bump-map format that uses 8 bits each for U and V data.
Q8W8V8U8 A 32-bit bump-map format that uses 8 bits for each channel.
V16U16 A 32-bit bump-map format that uses 16 bits for each channel.
Q16W16V16U16 A 64-bit bump-map format that uses 16 bits for each component.
CxV8U8 A 16-bit normal compression format. The texture sampler computes the C channel from C = sqrt(1 - U2 - V2).

Mixed Formats

Data in mixed formats can contain a combination of signed and unsigned data.

Mixed-format flags Format
L6V5U5 A 16-bit bump-map format, with luminance, that uses 6 bits for luminance and 5 bits each for v and u data.
X8L8V8U8 A 32-bit bump-map format, with luminance, that uses 8 bits for each channel.
A2W10V10U10 A 32-bit bump-map format that uses 2 bits for alpha and 10 bits each for w, v, and u data.

FOURCC Formats

Data in a four-character code (FOURCC) format is compressed.

MAKEFOURCC

The enumerated value of the following formats is based on a number generated by combining several integer values. This allows hardware designers to use custom enumerated values that are not explicitly listed here to indicate a FOURCC format.

The following C# code fragment generates FOURCC codes.

          [C#]
          
static int MakeFourCC(int ch0, int ch1, int ch2, int ch3)
{
   return ((int)(byte)(ch0)|((int)(byte)(ch1) << 8)| ((int)(byte)(ch2) << 16) | ((int)(byte)(ch3) << 24));
}

The defined FOURCC formats are as follows.

FOURCC flags Value Format
Multi2Argb8 MakeFourCC('M','E','T','1') MultiElement texture (not compressed).
G8R8G8B8 MakeFourCC('G', 'R', 'G', 'B') A 16-bit packed RGB format that is analogous to YUY2 (Y0U0, Y1V0, Y2U2, etc.). It requires a pixel pair to properly represent the color value. The first pixel in the pair contains 8 bits of green (in the high 8 bits) and 8 bits of red (in the low 8 bits). The second pixel contains 8 bits of green (in the high 8 bits) and 8 bits of blue (in the low 8 bits). The two pixels share the red and blue components, while each has a unique green component (G0R0, G1B0, G2R2, etc.). When looking up into a pixel shader, the texture sampler does not normalize the colors; they remain in the range of 0.0f to 255.0f. This is true for all programmable pixel shader models. For the fixed-function pixel shader, the hardware should normalize to the 0.f to 1.f range and treat it as the YUY2 texture. Hardware that exposes this format must have the Caps.PixelShader1xMaxValue member set to a value capable of handling that range.
R8G8B8G8 MakeFourCC('R', 'G', 'B', 'G') A 16-bit packed RGB format that is analogous to UYVY (U0Y0, V0Y1, U2Y2, etc.). It requires a pixel pair ito properly represent the color value. The first pixel in the pair contains 8 bits of green (in the low 8 bits) and 8 bits of red (in the high 8 bits). The second pixel contains 8 bits of green (in the low 8 bits) and 8 bits of blue (in the high 8 bits). The two pixels share the red and blue components, while each has a unique green component (R0G0, B0G1, R2G2, etc.). When looking up into a pixel shader, the texture sampler does not normalize the colors; they remain in the range of 0.0f to 255.0f. This is true for all programmable pixel shader models. For the fixed-function pixel shader, the hardware should normalize to the 0.f to 1.f range and treat it as the YUY2 texture. Hardware that exposes this format must have the Caps.PixelShader1xMaxValue member set to a value capable of handling that range.
Dxt1 MakeFourCC('D', 'X', 'T', '1') DXT1 compression texture format.
Dxt2 MakeFourCC('D', 'X', 'T', '2') DXT2 compression texture format.
Dxt3 MakeFourCC('D', 'X', 'T', '3') DXT3 compression texture format.
DXT4 MakeFourCC('D', 'X', 'T', '4') DXT4 compression texture format.
Dxt5 MakeFourCC('D', 'X', 'T', '5') DXT5 compression texture format.
Uyvy MakeFourCC('U', 'Y', 'V', 'Y') UYVY format (PC98 compliance).
Yuy2 MakeFourCC('Y', 'U', 'Y', '2') YUY2 format (PC98 compliance).

Buffer Formats

Depth, stencil, vertex, and index buffers each have unique formats.

Buffer flags Format
D16Lockable A 16-bit z-buffer bit depth.
D32 A 32-bit z-buffer bit depth.
D15S1 A 16-bit z-buffer bit depth in which 15 bits are reserved for the depth channel and 1 bit is reserved for the stencil channel.
D24S8 A 32-bit z-buffer bit depth that uses 24 bits for the depth channel and 8 bits for the stencil channel.
D24X8 A 32-bit z-buffer bit depth that uses 24 bits for the depth channel.
D24X4S4 A 32-bit z-buffer bit depth that uses 24 bits for the depth channel and 4 bits for the stencil channel.
D32SingleLockable A lockable format in which the depth value is represented as a standard Institute of Electrical and Electronics Engineers (IEEE) floating-point number.
D24SingleS8 A nonlockable format that contains 24 bits of depth (in a 24-bit floating-point format - 20e4) and 8 bits of stencil.
D16 A 16-bit z-buffer bit depth.
VertexData Describes a vertex buffer surface.

All depth stencil formats except D16Lockable indicate no particular bit ordering per pixel, and the driver is allowed to consume more than the indicated number of bits per depth channel (but not per stencil channel).

Floating-Point Formats

These flags are used for floating-point surface formats. They use 16 bits per channel and are also known as s10e5 formats.

Floating-point flags Format
R16F A 16-bit floating-point format that uses 16 bits for the red channel.
G16R16F A 32-bit floating-point format that uses 16 bits each for the red and green channels.
A16B16G16R16F A 64-bit floating-point format that uses 16 bits for each channel (alpha, blue, green, and red).

IEEE Formats

These flags are used for floating-point surface formats. They use 32 bits per channel and are also known as s23e8 formats.

Floating-point flags Format
R32F A 32-bit floating-point format that uses 32 bits for the red channel.
G32R32F A 64-bit floating-point format that uses 32 bits each for the red and green channels.
A32B32G32R32F A 128-bit floating-point format that uses 32 bits for each channel (alpha, blue, green, and red).

Other

This flag is used for undefined formats.

Other flags Format
Unknown Surface format is unknown.

BackBuffer or Display Formats

These formats are the only valid formats for a back buffer or a display.

Format Back buffer Display
A2R10G10B10 x x (full-screen mode only)
A8R8G8B8 x
X8R8G8B8 x x
A1R5G5B5 x
X1R5G5B5 x x
R5G6B5 x x

Remarks

The order of the bits starts with the most significant byte, so A8L8 indicates that the high byte of this 2-byte format is alpha. The D16 format indicates a 16-bit integer value and an application-lockable surface.

Pixel formats have been chosen to enable the expression of extension formats defined by hardware vendors, and to include the well-established FOURCC method. The set of formats understood by the Direct3D runtime is defined by the Caps structure.

Note that formats are supplied by independent hardware vendors (IHVs), and many FOURCC codes are not listed. The formats in this enumeration are unique in that they are sanctioned by the runtime, which means that the reference rasterizer operates on all of these types. Formats supplied by IHVs are supported by the individual vendors on a card-by-card basis.