Overview

ddsparse is a simple C++ DDS file parser for compressed 2D textures.

Supported

  • BC 1-7 (DXT 1/3/5, RGTC 1/2, and BPTC) DDS textures.
  • Mipmap chains for the above formats.

Not supported

  • Texture arrays.
  • Cubemaps.
  • 1D and 3D textures.
  • All uncompressed formats.
  • Decompressing compressed textures.
  • Compressing raw pixel data.

ddsparse does not open files itself, it will only parse a chunk of memory.

Usage example

// Data will *not* be copied into the Parser. You have to make sure the memory
// stays valid yourself.
dds::Parser parser(data, dataSize);

if (parser.getFormat() == dds::FORMAT_UNKNOWN || parser.getMipmapCount() == 0)
{
    // Invalid DDS file or unsupported format!
    // dds::isDDS(data, dataSize) can be used to dermine if the data is a
    // valid DDS file, but it will not say if the format is supported.
    return;
}

// Assuming you made a function to change the DDS format enum to a GL format.
GLenum glformat = getGLFormat(parser.getFormat());

// Upload the texture data to an OpenGL texture.
for (int i = 0; i < parser.getMipmapCount(); i++)
{
    // Image data represents a single mipmap level of a texture.
    const dds::Image *img = parser.getImageData(i);

    glCompressedTexImage2D(GL_TEXTURE_2D,
                           i,
                           glformat,
                           img->width,
                           img->height,
                           0,
                           GLsizei(img->dataSize),
                           img->data);
}