-
Notifications
You must be signed in to change notification settings - Fork 167
Loading textures from dds files
The DDS file format was introduced with DirectX as a way to efficiently load texture data. Though it was originally designed for DirectX, it can also be used in OpenGL.
- Can contain compressed or uncompressed texture data -- Compressed textures via DDS is a great way to reduce runtime memory usage.
- Can contain mipmap data
- Can contain cubemap data
- Can contain texture data that closely matches GPU formats which can result in faster loading times.
Compressed textures take up less storage and RAM and render faster on GPUs that support them. All DirectX hardware supports using compressed textures.
The following compressed texture formats supported via the GL_EXT_texture_compression_s3tc extension that can be used with ANGLE are:
- GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
- GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE
- GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE
OpenGL ES 2.0 provides a way to create textures from compressed data by using glCompressedTexImage2D. The application can load texture data, specify the corresponding format and create and manage the texture themselves.
The DirectX Tool Kit (DirectXTK) includes DDSTextureLoader, which is an easy-to-use helper for developers wanting to load DDS files into DirectX textures. We have created a version of this helper for Windows Store apps to use with ANGLE.
A sample demonstrating how to use DDSTextureLoader can be found in our GitHub samples directory.
To use DDSTextureLoader in your own project, copy DDSTextureLoader.h and DDSTextureLoader.cpp from the samples directory and use it like this:
HRESULT hr = S_OK;
hr = DirectX::CreateDDSTextureFromFile(L"SomeTexture.dds", &mTexture);
if (FAILED(hr))
{
// The DDS file failed to load. mTexture is not a valid texture.
}
Due to coordinate system differences, 'CreateDDSTextureFromFile' by default will vertically flip image data before creating the resulting GL texture. This is an unnecessary overhead which you can avoid by manually flipping the contents of your DDS files and setting CreateDDSTextureFromFile's optional 'verticalFlip' parameter to false.