Creates a Direct3D 11 resource from a set of images.

This function is intended for use with tools or editor programs. For runtime/engine use, we strongly recommend using DDSTextureLoader, and/or WICTextureLoader instead of DirectXTex.

HRESULT CreateTexture( _In_ ID3D11Device* pDevice,
    _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages,
    _In_ const TexMetadata& metadata,
    _Outptr_ ID3D11Resource** ppResource );

HRESULT CreateTextureEx( _In_ ID3D11Device* pDevice,
    _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages,
    _In_ const TexMetadata& metadata,
    _In_ D3D11_USAGE usage, _In_ unsigned int bindFlags,
    _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags,
    _In_ bool forceSRGB,
    _Outptr_ ID3D11Resource** ppResource );

Parameters

  • usage: The non-Ex version of this function assumes this is D3D11_USAGE_DEFAULT.
  • bindFlags: The non-Ex version of this function assumes this is D3D11_BIND_SHADER_RESOURCE.
  • cpuAccessFlags: The non-Ex version of this function assumes this is 0.
  • miscFlags: The non-Ex version of this function assumes this is 0.
  • forceSRGB: This is 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

WCHAR ext[_MAX_EXT];
_wsplitpath_s( filename, nullptr, 0, nullptr, 0, nullptr, 0, ext, _MAX_EXT );

ScratchImage image;
HRESULT hr;
if ( _wcsicmp( ext, L".dds" ) == 0 )
{
    hr = LoadFromDDSFile( filename, DDS_FLAGS_NONE, nullptr, image );
}
else if ( _wcsicmp( ext, L".tga" ) == 0 )
{
    hr = LoadFromTGAFile( filename, nullptr, image );
}
else
{
    hr = LoadFromWICFile( filename, WIC_FLAGS_NONE, nullptr, image );
}
if ( SUCCEEDED(hr) )
{
    ID3D11Resource* pResource = nullptr;
    hr = CreateTexture( device,
        image.GetImages(), image.GetImageCount(),
        image.GetMetadata(), &pResource );
    if ( FAILED(hr) )
    {
        ...

Remark

This function does not provide support for auto-gen mipmaps (the runtime/engine loaders can support this) because the assumption is if you need mipmaps with DirectTex you will call GenerateMipMaps or GenerateMipMaps3D

Last edited Mar 10, 2014 at 10:47 PM by walbourn, version 7