?/TD>
Microsoft DirectX 9.0

DDS File Layout for Textures


For simple uncompressed textures, the file should contain DDSD_PITCH and a DDPF_RGB pixel format surface. The pitch value should be DWORD-aligned. In this case, the main image should be (dwPitchOrLinearSize-by-dwHeight) bytes total.

If the file also contains mipmaps, the DDSD_MIPMAPCOUNT, DDSCAPS_MIPMAP, and DDSCAPS_COMPLEX flags should be set, and the dwMipMapCount field should contain the total number of levels defined in the file (for a 256-by-256 image, this field would be 9). The pitch for each mipmap-level image is computed from dwWidth and the pixel format, which is then DWORD-aligned. For example, a 256-by-256 main image, with a pixel format of R8G8B8 (three bytes per pixel) and all mipmap levels, would contain the following:

"DDS", (256, 256), (pitch=768), (pixel format=R8G8B8,bitcount=24), (mipmapcount=9), (TEXTURE, PITCH, COMPLEX, MIPMAP, RGB)128 bytes
256-by-256 main image196608 bytes
128-by-128 mipmap image49152 bytes
64-by-64 mipmap image12288 bytes
32-by-32 mipmap image3072 bytes
16-by-16 mipmap image768 bytes
8-by-8 mipmap image192 bytes
4-by-4 mipmap image48 bytes
2-by-2 mipmap image12 bytes
1-by-1 mipmap image4 bytes

For simple compressed textures, the file should contain DDSD_LINEARSIZE and a DDPF_FOURCC pixel format surface. In this case, the image should be dwPitchOrLinearSize bytes total. If the file contains mipmaps, the DDSD_MIPMAPCOUNT, DDSCAPS_COMPLEX, DDSCAPS_MIPMAP, and dwMipMapCount fields should be set.

For DXTn compressed formats, the size of each mipmap level image is one-fourth the size of the previous, with a minimum of 8 (DXT1) or 16 (DXT2-5) bytes (this is true only for square textures). For example, a 256-by-256 main image, with a pixel format of DXT1 and all mipmap levels, would contain the following:

DDS, (256, 256), (linearsize=32768), 128 bytes (pixel format=DXT1), (mipmapcount=9), (TEXTURE, LINEARSIZE, COMPLEX, MIPMAP, FOURCC)128 bytes
256-by-256 main image32768 bytes
128-by-128 mipmap image8192 bytes
64-by-64 mipmap image2048 bytes
32-by-32 mipmap image512 bytes
16-by-16 mipmap image128 bytes
8-by-8 mipmap image32 bytes
4-by-4 mipmap image8 bytes
2-by-2 mipmap image8 bytes
1-by-1 mipmap image8 bytes

If mipmaps are generated, all levels down to 1-by-1 are usually written. Some tools may not support partial mipmap chains.

When computing DXTn compressed sizes for non-square textures, the following formula should be used at each mipmap level:

max(1,width ?4)x max(1,height ?4)x 8 (DXT1) or 16 (DXT2-5)

A 256-by-64 main image, with a pixel format of DXT1 and all mipmap levels, would contain the following:

"DDS ", (256, 64), (linearsize=8192), (pixel format=DXT1), (mipmapcount=9), (TEXTURE, LINEARSIZE, COMPLEX, MIPMAP, FOURCC)128 bytes
256-by-64 main image8192 bytes
128-by-32 mipmap image2048 bytes
64-by-16 mipmap image512 bytes
32-by-8 mipmap image128 bytes
16-by-4 mipmap image32 bytes
8-by-2 mipmap image16 bytes
4-by-1 mipmap image8 bytes
2-by-1 mipmap image8 bytes
1-by-1 mipmap image8 bytes


© 2002 Microsoft Corporation. All rights reserved.