For simple uncompressed textures, a .dds 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.
A 256-by-256 main image with a pixel format of R8G8B8 (three bytes per pixel) and all mipmap levels would contain the following layers:
Texture Size/Type | # Bytes |
---|---|
"DDS", 256x256, pitch=768, R8G8B8, 24 bits, mipmapcount = 9, (TEXTURE, PITCH, COMPLEX, MIPMAP, RGB) | 128 |
256-by-256 main image | 196608 |
128-by-128 mipmap image | 49152 |
64-by-64 mipmap image | 12288 |
32-by-32 mipmap image | 3072 |
16-by-16 mipmap image | 768 |
8-by-8 mipmap image | 192 |
4-by-4 mipmap image | 48 |
2-by-2 mipmap image | 12 |
1-by-1 mipmap image | 3 |
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:
Texture Size/Type | # Bytes |
---|---|
DDS, 256x256, linearsize = 32768, 128 bytes DXT1, mipmapcount = 9, (TEXTURE, LINEARSIZE, COMPLEX, MIPMAP, FOURCC) | 128 |
256-by-256 main image | 32768 |
128-by-128 mipmap image | 8192 |
64-by-64 mipmap image | 2048 |
32-by-32 mipmap image | 512 |
16-by-16 mipmap image | 128 |
8-by-8 mipmap image | 32 |
4-by-4 mipmap image | 8 |
2-by-2 mipmap image | 8 |
1-by-1 mipmap image | 8 |
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:
Texture Size/Type | # Bytes |
---|---|
"DDS ", 256x64, linearsize = 8192, DXT1, mipmapcount = 9, (TEXTURE, LINEARSIZE, COMPLEX, MIPMAP, FOURCC) | 128 bytes |
256-by-64 main image | 8192 |
128-by-32 mipmap image | 2048 |
64-by-16 mipmap image | 512 |
32-by-8 mipmap image | 128 |
16-by-4 mipmap image | 32 |
8-by-2 mipmap image | 16 |
4-by-1 mipmap image | 8 |
2-by-1 mipmap image | 8 |
1-by-1 mipmap image | 8 |