Looking for a *.dds texture loading library in C++ that isn't specific to any Rendering API

Started by
9 comments, last by snake5 8 years, 1 month ago

The the above library looks more complete, except that it doesn’t handle mipmaps (it appears to just load them as part of a big chunk, whereas mine separates them into separate memory blocks).


It does handle mipmaps. Every mipmap is retrieved separately by dds_seek/dds_read. dds_read_all is only a wrapper that copies everything into one big buffer with a predefined order of items.

Basically whatever texture part you want out of it, you can move the pointer to it using "dds_seek( &info, cubemap_side, mipmap_id )" and then memcpy it using "dds_read( &info, my_buffer )"

What it doesn't handle though, is pitch (row length in bytes). If your target buffer expects different pitch, it will be necessary to use an intermediate buffer in size that can be retrieved using dds_getinfo (size member of dds_image_info output struct). Or write your own reading function (once you have the side/mipmap offset, it shouldn't be that hard).

DDS is such a simple format that i'm not even sure that it needs a library. There's no parsing/etc involved, it's just a simple header followed by data which can be directly consumed by the API without conversion.

There actually are multiple DDS formats, one pre-DX10, the other one contains an extra header. It even supports partial cubemaps and all sorts of weird pixel compositions. Nobody needs them (not that I recall, anyway) but it's important to detect these cases to avoid buffer overruns and broken visuals. Sadly, the format isn't quite as simple as one would expect.

Internally I use something even more simple (this is the header, pixel sorting order major->minor is - side, mipmap, depth, height, width):
struct TextureInfo /* 12 bytes */
{
	uint8_t type; /* 2D[1]/CUBE[2]/VOLUME[3] */
	uint8_t mipcount;
	uint16_t width;
	uint16_t height;
	uint16_t depth;
	uint16_t format; /* format ID (rgba8/r5g6b5/dxt1/dxt3/dxt5/..) */
	uint16_t flags; /* SRGB[0x01]/HASMIPS[0x02]/LERP[0x04]/CLAMP_X[0x10]/CLAMP_Y[0x20] */
};
struct Texture
{
	char magic[4]; /* STX\0 */
	uint32_t datasize; /* size of 'data' */
	TextureInfo info;
	uint8_t data[ datasize ];
};

This topic is closed to new replies.

Advertisement