From 6fcd00fdbdece25fa074ca98cd1ee9f413edb2e6 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Fri, 14 Jul 2017 00:44:00 -0700 Subject: [PATCH] Support DDS files with non-standard nVidia Texture Tools flags --- DirectXTex/DirectXTexDDS.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/DirectXTex/DirectXTexDDS.cpp b/DirectXTex/DirectXTexDDS.cpp index 7373985..9f68568 100644 --- a/DirectXTex/DirectXTexDDS.cpp +++ b/DirectXTex/DirectXTexDDS.cpp @@ -155,15 +155,22 @@ namespace // FourCC CTX1 (Xbox 360 only) // FourCC EAR, EARG, ET2, ET2A (Ericsson Texture Compression) - DXGI_FORMAT GetDXGIFormat(const DDS_PIXELFORMAT& ddpf, DWORD flags, _Inout_ DWORD& convFlags) + DXGI_FORMAT GetDXGIFormat(const DDS_HEADER& hdr, const DDS_PIXELFORMAT& ddpf, DWORD flags, _Inout_ DWORD& convFlags) { + uint32_t ddpfFlags = ddpf.dwFlags; + if (hdr.dwReserved1[9] == MAKEFOURCC('N', 'V', 'T', 'T')) + { + // Clear out non-standard nVidia DDS flags + ddpfFlags &= ~0xC0000000 /* DDPF_SRGB | DDPF_NORMAL */; + } + const size_t MAP_SIZE = sizeof(g_LegacyDDSMap) / sizeof(LegacyDDS); size_t index = 0; for (index = 0; index < MAP_SIZE; ++index) { const LegacyDDS* entry = &g_LegacyDDSMap[index]; - if (ddpf.dwFlags == entry->ddpf.dwFlags) + if (ddpfFlags == entry->ddpf.dwFlags) { if (entry->ddpf.dwFlags & DDS_FOURCC) { @@ -245,6 +252,12 @@ namespace cflags ^= CONV_FLAGS_SWIZZLE; } + if ((hdr.dwReserved1[9] == MAKEFOURCC('N', 'V', 'T', 'T')) + && (ddpf.dwFlags & 0x40000000 /* DDPF_SRGB */)) + { + format = MakeSRGB(format); + } + convFlags = cflags; return format; @@ -409,7 +422,7 @@ namespace // Note there's no way for a legacy Direct3D 9 DDS to express a '1D' texture } - metadata.format = GetDXGIFormat(pHeader->ddspf, flags, convFlags); + metadata.format = GetDXGIFormat(*pHeader, pHeader->ddspf, flags, convFlags); if (metadata.format == DXGI_FORMAT_UNKNOWN) return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);