IWICDdsDecoder 无法加载立方体贴图

IWICDdsDecoder fails to load Cube maps

我用 NVidia's Texture Exporter Tool 创建了一个纹理立方体,但我无法用 IWICDdsDecoder 加载它。

失败 0x88982f61 : The image header is unrecognized.

另一方面,使用 NVTET 创建的普通 2D 纹理 (Dimension = WICDdsTexture2D) 可以正确加载并且运行良好。

IWICDdsLoader 支持立方体贴图吗?如果不支持,为什么要指定 WICDdsDimension.WICDdsTextureCube

适用于 NVTET 编写的正常 WICDdsTexture2D 纹理的部分加载程序代码。

HRESULT lResult;

WICStream lStream;
lResult = gFactory->CreateStream(&lStream);
if (FAILED(lResult)) return lResult;

lResult = lStream->InitializeFromFilename(aPath, GENERIC_READ);
if (FAILED(lResult)) return lResult;

WICBitmapDecoder lBitmapDecoder;
lResult = gFactory->CreateDecoder(GUID_ContainerFormatDds, nullptr, &lBitmapDecoder);
if (FAILED(lResult)) return lResult;

lResult = lBitmapDecoder->Initialize(lStream, WICDecodeMetadataCacheOnDemand);
if (FAILED(lResult)) return lResult; // <-- it fails here!
// 0x88982f61 : The image header is unrecognized.

WICDdsDecoder lDecoder(lBitmapDecoder);
if (!lDecoder) return E_NOINTERFACE;

WICDdsParameters lParameters{};
lResult = lDecoder->GetParameters(&lParameters);
if (FAILED(lResult)) return lResult;
if (lParameters.Dimension != WICDdsTextureCube) return E_FAIL;

// etc.

Windows8.1 中引入的内置 WIC DDS 编解码器旨在支持 WebGL。它仅支持 DXT1-5 (BC1-3) 格式纹理。这记录在 Microsoft Docs.

为了高效加载 DDS 文件(所有 DXGI 格式和复杂的表面构造),请查看 DDSTextureLoaderDX11 or DX12. This module is available integrated into the DirectX Tool Kit and as standalone versions in the DirectXTex 项目。

如果您需要支持旧版 Direct3D 9 时代格式 DDS 文件、格式​​转换等,请参阅 DirectXTex DDS 编解码器。

有关现代 DDS 纹理处理的更多背景信息,请参阅 this blog post

There is also a Direct3D 9 version of DDSTextureLoader available if needed in the DirectXTex project. See this blog post for details.