A streamlined version of the DirectX SDK sample DDSWithoutD3DX11 texture loading code for a simple light-weight runtime .DDS file loader. This version only supports Direct3D 11 and performs no runtime pixel data conversions (i.e. 24bpp legacy DDS files always fail). This is ideal for runtime usage, and supports the full complement of Direct3D 11 texture resources (1D, 2D, volume maps, cubemaps, mipmap levels, texture arrays, BC formats, etc.). It supports both legacy and 'DX10' extension header format .dds files.
Also part of DirectXTex http://go.microsoft.com/fwlink/?LinkId=248926
Loads a .DDS file assuming the image of the file is located in a memory buffer. Creates a Direct3D 11 resource and optionally a Direct3D 11 shader resource view.
CreateDDSTextureFromFile
Loads a .DDS file from disk and creates a Direct3D 11 resource and optionally a Direct3D 11 shader resource view.
For both these functions if 'maxsize' parameter non-zero, then all mipmap levels larger than the maxsize are ignored before creating the Direct3D 11 resource. This allows for load-time scaling. If '0', then if the attempt to create the Direct3D 11 resource fails and there are mipmaps present, it will retry assuming a maxsize based on the device's current feature level.
CreateDDSTextureFromMemoryEx
CreateDDSTextureFromFileEx
These versions provide explicit control over the created resource's usage, binding flags, CPU access flags, and miscellaneous flags for advanced / expert scenarios. The standard routines default to D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, and 0 respectively. For cubemaps, the miscellaneous flags default to D3D11_RESOURCE_MISC_TEXTURECUBE. There is also a 'forceSRGB' option for working around gamma issues with content that is in the sRGB or similar color space but is not encoded explicitly as an SRGB format.
Texture arrays require Feature Level 10.0 or later. Cubemap arrays requires Feature Level 10.1 or later.
Be sure to review the various format limitations for the different feature levels. To support all feature levels, stick with textures in the following formats:
http://blogs.msdn.com/b/chuckw/archive/2012/06/20/direct3d-feature-levels.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/bb219822.aspx
Also part of DirectXTex http://go.microsoft.com/fwlink/?LinkId=248926
Functions
CreateDDSTextureFromMemoryLoads a .DDS file assuming the image of the file is located in a memory buffer. Creates a Direct3D 11 resource and optionally a Direct3D 11 shader resource view.
CreateDDSTextureFromFile
Loads a .DDS file from disk and creates a Direct3D 11 resource and optionally a Direct3D 11 shader resource view.
For both these functions if 'maxsize' parameter non-zero, then all mipmap levels larger than the maxsize are ignored before creating the Direct3D 11 resource. This allows for load-time scaling. If '0', then if the attempt to create the Direct3D 11 resource fails and there are mipmaps present, it will retry assuming a maxsize based on the device's current feature level.
CreateDDSTextureFromMemoryEx
CreateDDSTextureFromFileEx
These versions provide explicit control over the created resource's usage, binding flags, CPU access flags, and miscellaneous flags for advanced / expert scenarios. The standard routines default to D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, and 0 respectively. For cubemaps, the miscellaneous flags default to D3D11_RESOURCE_MISC_TEXTURECUBE. There is also a 'forceSRGB' option for working around gamma issues with content that is in the sRGB or similar color space but is not encoded explicitly as an SRGB format.
Example
This example creates a shader resource view on the ID3D11Device d3dDevice which can be used for rendering.usingnamespace DirectX; usingnamespace Microsoft::WRL; ComPtr<ID3D11ShaderResourceView> srv; HRESULT hr = CreateDDSTextureFromFile( d3dDevice, L"SEAFLOOR.DDS", nullptr, &srv ) ThrowIfFailed(hr);
Feature Level Notes
In order to support all feature levels, you should make sure your DDS textures are mip-mapped so that they contain a suitably sized image. Non-mipmapped textures will either need explicit feature level association, or be sized less than 2048 for 1D, 2048 x 2048 for 2D, 512 x 512 for cubemaps, and 256 x 256 x 256 for volume maps.Texture arrays require Feature Level 10.0 or later. Cubemap arrays requires Feature Level 10.1 or later.
Be sure to review the various format limitations for the different feature levels. To support all feature levels, stick with textures in the following formats:
- DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
- DXGI_FORMAT_R8G8B8A8_SNORM
- DXGI_FORMAT_B8G8R8A8_UNORM
- DXGI_FORMAT_R16G16_SNORM
- DXGI_FORMAT_R8G8_SNORM
- DXGI_FORMAT_R8_UNORM
- DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC1_UNORM_SRGB
- DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_BC2_UNORM_SRGB
- DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_BC3_UNORM_SRGB
Release Notes
- DDSTextureLoader performs no run-time conversions. If there is not a direct mapping to a DXGI supported format, the function fails. Notably this means legacy Direct3D9 24bpp DDS files will not load. You can make use of the DirectXTex library or texconv tool to convert legacy Direct3D9 DDS files to a supported format.
- On a system with the DirectX 11.0 Runtime or lacking WDDM 1.2 drivers, attempts to load 16bpp format files (BGR 5:6:5, BGRA 5:5:5:1, and BGRA 4:4:4:4) will fail.
- Partial cubemaps (i.e. DDS files without all six faces defined) are not supported by Direct3D 11.
Further Reading
http://blogs.msdn.com/b/chuckw/archive/2010/02/05/the-dds-file-format-lives.aspxhttp://blogs.msdn.com/b/chuckw/archive/2012/06/20/direct3d-feature-levels.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/bb219822.aspx