Skip to content

CreateTexture

Chuck Walbourn edited this page Jun 22, 2015 · 20 revisions

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( ID3D11Device* pDevice,
    const Image* srcImages, size_t nimages, const TexMetadata& metadata,
    ID3D11Resource** ppResource );

HRESULT CreateTextureEx( ID3D11Device* pDevice,
    const Image* srcImages, _In_ size_t nimages, const TexMetadata& metadata,
    D3D11_USAGE usage, unsigned int bindFlags,
    unsigned int cpuAccessFlags, unsigned int miscFlags,
    bool forceSRGB,
    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

For Use

  • Universal Windows Platform apps
  • Windows desktop apps
  • Windows 11
  • Windows 10
  • Windows 8.1
  • Windows 7 Service Pack 1
  • Xbox One
  • Xbox Series X|S
  • Windows Subsystem for Linux

For Development

  • Visual Studio 2022
  • Visual Studio 2019 (16.11)
  • clang/LLVM v12 - v18
  • GCC 10.5, 11.4, 12.3
  • MinGW 12.2, 13.2
  • CMake 3.20

Related Projects

DirectXTex Rust bindings

DirectX Tool Kit for DirectX 11

DirectX Tool Kit for DirectX 12

DirectXMesh

DirectXMath

Tools

Test Suite

Content Exporter

DxCapsViewer

See also

DirectX Landing Page

Clone this wiki locally