|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <cstdint> |
| 4 | + |
| 5 | +// DDSPixelFormat.dwFlags bits |
| 6 | +enum { |
| 7 | + DDPF_ALPHAPIXELS = 1, // Texture contains alpha data; dwRGBAlphaBitMask contains valid data. |
| 8 | + DDPF_ALPHA = 2, // Used in some older DDS files for alpha channel only uncompressed data(dwRGBBitCount contains the alpha channel bitcount; dwABitMask contains valid data) |
| 9 | + DDPF_FOURCC = 4, // Texture contains compressed RGB data; dwFourCC contains valid data. 0x4 |
| 10 | + DDPF_RGB = 8, // Texture contains uncompressed RGB data; dwRGBBitCount and the RGB masks(dwRBitMask, dwGBitMask, dwBBitMask) contain valid data. 0x40 |
| 11 | + DDPF_YUV = 16, //Used in some older DDS files for YUV uncompressed data(dwRGBBitCount contains the YUV bit count; dwRBitMask contains the Y mask, dwGBitMask contains the U mask, dwBBitMask contains the V mask) |
| 12 | + DDPF_LUMINANCE = 32, // Used in some older DDS files for single channel color uncompressed data (dwRGBBitCount contains the luminance channel bit count; dwRBitMask contains the channel mask). Can be combined with DDPF_ALPHAPIXELS for a two channel DDS file. |
| 13 | +}; |
| 14 | + |
| 15 | +// dwCaps members |
| 16 | +enum { |
| 17 | + DDSCAPS_COMPLEX = 8, |
| 18 | + DDSCAPS_MIPMAP = 0x400000, |
| 19 | + DDSCAPS_TEXTURE = 0x1000, // Required |
| 20 | +}; |
| 21 | + |
| 22 | +// Not using any D3D headers here, this is cross platform and minimal. |
| 23 | +// Boiled down from the public documentation. |
| 24 | +struct DDSPixelFormat { |
| 25 | + uint32_t dwSize; // must be 32 |
| 26 | + uint32_t dwFlags; |
| 27 | + uint32_t dwFourCC; |
| 28 | + uint32_t dwRGBBitCount; |
| 29 | + uint32_t dwRBitMask; |
| 30 | + uint32_t dwGBitMask; |
| 31 | + uint32_t dwBBitMask; |
| 32 | + uint32_t dwABitMask; |
| 33 | +}; |
| 34 | + |
| 35 | +struct DDSHeader { |
| 36 | + uint32_t dwMagic; // Magic is not technically part of the header struct but convenient to have here when reading the files. |
| 37 | + uint32_t dwSize; // must be 124 |
| 38 | + uint32_t dwFlags; |
| 39 | + uint32_t dwHeight; |
| 40 | + uint32_t dwWidth; |
| 41 | + uint32_t dwPitchOrLinearSize; // The pitch or number of bytes per scan line in an uncompressed texture; the total number of bytes in the top level texture for a compressed texture |
| 42 | + uint32_t dwDepth; // we'll always use 1 here |
| 43 | + uint32_t dwMipMapCount; |
| 44 | + uint32_t dwReserved1[11]; |
| 45 | + DDSPixelFormat ddspf; |
| 46 | + uint32_t dwCaps; |
| 47 | + uint32_t dwCaps2; // nothing we care about |
| 48 | + uint32_t dwCaps3; // unused |
| 49 | + uint32_t dwCaps4; // unused |
| 50 | + uint32_t dwReserved2; |
| 51 | +}; |
| 52 | + |
| 53 | +// DDS header extension to handle resource arrays, DXGI pixel formats that don't map to the legacy Microsoft DirectDraw pixel format structures, and additional metadata. |
| 54 | +struct DDSHeaderDXT10 { |
| 55 | + uint32_t dxgiFormat; |
| 56 | + uint32_t resourceDimension; // 1d = 2, 2d = 3, 3d = 4. very intuitive |
| 57 | + uint32_t miscFlag; |
| 58 | + uint32_t arraySize; // we only support 1 here |
| 59 | + uint32_t miscFlags2; // sets alpha interpretation, let's not bother |
| 60 | +}; |
| 61 | + |
| 62 | +// Simple DDS parser, suitable for texture replacement packs. |
| 63 | +// Doesn't actually load, only does some logic to fill out DDSLoadInfo so the caller can then |
| 64 | +// do the actual load with a simple series of memcpys or whatever is appropriate. |
| 65 | +struct DDSLoadInfo { |
| 66 | + uint32_t bytesToCopy; |
| 67 | +}; |
| 68 | + |
| 69 | +bool DetectDDSParams(const DDSHeader *header, DDSLoadInfo *info); |
0 commit comments