Add better support for the DX10 DDS formats.
This commit is contained in:
parent
db1b30ee4b
commit
9d47e100f1
@ -54,6 +54,8 @@ namespace
|
||||
static const uint FOURCC_ATI1 = MAKEFOURCC('A', 'T', 'I', '1');
|
||||
static const uint FOURCC_ATI2 = MAKEFOURCC('A', 'T', 'I', '2');
|
||||
|
||||
static const uint FOURCC_DX10 = MAKEFOURCC('D', 'X', '1', '0');
|
||||
|
||||
// 32 bit RGB formats.
|
||||
static const uint D3DFMT_R8G8B8 = 20;
|
||||
static const uint D3DFMT_A8R8G8B8 = 21;
|
||||
@ -253,6 +255,144 @@ namespace
|
||||
D3D10_RESOURCE_DIMENSION_TEXTURE3D = 4,
|
||||
};
|
||||
|
||||
|
||||
const char * getDxgiFormatString(DXGI_FORMAT dxgiFormat)
|
||||
{
|
||||
#define CASE(format) case DXGI_FORMAT_##format: return #format
|
||||
switch(dxgiFormat)
|
||||
{
|
||||
CASE(UNKNOWN);
|
||||
|
||||
CASE(R32G32B32A32_TYPELESS);
|
||||
CASE(R32G32B32A32_FLOAT);
|
||||
CASE(R32G32B32A32_UINT);
|
||||
CASE(R32G32B32A32_SINT);
|
||||
|
||||
CASE(R32G32B32_TYPELESS);
|
||||
CASE(R32G32B32_FLOAT);
|
||||
CASE(R32G32B32_UINT);
|
||||
CASE(R32G32B32_SINT);
|
||||
|
||||
CASE(R16G16B16A16_TYPELESS);
|
||||
CASE(R16G16B16A16_FLOAT);
|
||||
CASE(R16G16B16A16_UNORM);
|
||||
CASE(R16G16B16A16_UINT);
|
||||
CASE(R16G16B16A16_SNORM);
|
||||
CASE(R16G16B16A16_SINT);
|
||||
|
||||
CASE(R32G32_TYPELESS);
|
||||
CASE(R32G32_FLOAT);
|
||||
CASE(R32G32_UINT);
|
||||
CASE(R32G32_SINT);
|
||||
|
||||
CASE(R32G8X24_TYPELESS);
|
||||
CASE(D32_FLOAT_S8X24_UINT);
|
||||
CASE(R32_FLOAT_X8X24_TYPELESS);
|
||||
CASE(X32_TYPELESS_G8X24_UINT);
|
||||
|
||||
CASE(R10G10B10A2_TYPELESS);
|
||||
CASE(R10G10B10A2_UNORM);
|
||||
CASE(R10G10B10A2_UINT);
|
||||
|
||||
CASE(R11G11B10_FLOAT);
|
||||
|
||||
CASE(R8G8B8A8_TYPELESS);
|
||||
CASE(R8G8B8A8_UNORM);
|
||||
CASE(R8G8B8A8_UNORM_SRGB);
|
||||
CASE(R8G8B8A8_UINT);
|
||||
CASE(R8G8B8A8_SNORM);
|
||||
CASE(R8G8B8A8_SINT);
|
||||
|
||||
CASE(R16G16_TYPELESS);
|
||||
CASE(R16G16_FLOAT);
|
||||
CASE(R16G16_UNORM);
|
||||
CASE(R16G16_UINT);
|
||||
CASE(R16G16_SNORM);
|
||||
CASE(R16G16_SINT);
|
||||
|
||||
CASE(R32_TYPELESS);
|
||||
CASE(D32_FLOAT);
|
||||
CASE(R32_FLOAT);
|
||||
CASE(R32_UINT);
|
||||
CASE(R32_SINT);
|
||||
|
||||
CASE(R24G8_TYPELESS);
|
||||
CASE(D24_UNORM_S8_UINT);
|
||||
CASE(R24_UNORM_X8_TYPELESS);
|
||||
CASE(X24_TYPELESS_G8_UINT);
|
||||
|
||||
CASE(R8G8_TYPELESS);
|
||||
CASE(R8G8_UNORM);
|
||||
CASE(R8G8_UINT);
|
||||
CASE(R8G8_SNORM);
|
||||
CASE(R8G8_SINT);
|
||||
|
||||
CASE(R16_TYPELESS);
|
||||
CASE(R16_FLOAT);
|
||||
CASE(D16_UNORM);
|
||||
CASE(R16_UNORM);
|
||||
CASE(R16_UINT);
|
||||
CASE(R16_SNORM);
|
||||
CASE(R16_SINT);
|
||||
|
||||
CASE(R8_TYPELESS);
|
||||
CASE(R8_UNORM);
|
||||
CASE(R8_UINT);
|
||||
CASE(R8_SNORM);
|
||||
CASE(R8_SINT);
|
||||
CASE(A8_UNORM);
|
||||
|
||||
CASE(R1_UNORM);
|
||||
|
||||
CASE(R9G9B9E5_SHAREDEXP);
|
||||
|
||||
CASE(R8G8_B8G8_UNORM);
|
||||
CASE(G8R8_G8B8_UNORM);
|
||||
|
||||
CASE(BC1_TYPELESS);
|
||||
CASE(BC1_UNORM);
|
||||
CASE(BC1_UNORM_SRGB);
|
||||
|
||||
CASE(BC2_TYPELESS);
|
||||
CASE(BC2_UNORM);
|
||||
CASE(BC2_UNORM_SRGB);
|
||||
|
||||
CASE(BC3_TYPELESS);
|
||||
CASE(BC3_UNORM);
|
||||
CASE(BC3_UNORM_SRGB);
|
||||
|
||||
CASE(BC4_TYPELESS);
|
||||
CASE(BC4_UNORM);
|
||||
CASE(BC4_SNORM);
|
||||
|
||||
CASE(BC5_TYPELESS);
|
||||
CASE(BC5_UNORM);
|
||||
CASE(BC5_SNORM);
|
||||
|
||||
CASE(B5G6R5_UNORM);
|
||||
CASE(B5G5R5A1_UNORM);
|
||||
CASE(B8G8R8A8_UNORM);
|
||||
CASE(B8G8R8X8_UNORM);
|
||||
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
#undef CASE
|
||||
}
|
||||
|
||||
const char * getD3d10ResourceDimensionString(D3D10_RESOURCE_DIMENSION resourceDimension)
|
||||
{
|
||||
switch(resourceDimension)
|
||||
{
|
||||
default:
|
||||
case D3D10_RESOURCE_DIMENSION_UNKNOWN: return "UNKNOWN";
|
||||
case D3D10_RESOURCE_DIMENSION_BUFFER: return "BUFFER";
|
||||
case D3D10_RESOURCE_DIMENSION_TEXTURE1D: return "TEXTURE1D";
|
||||
case D3D10_RESOURCE_DIMENSION_TEXTURE2D: return "TEXTURE2D";
|
||||
case D3D10_RESOURCE_DIMENSION_TEXTURE3D: return "TEXTURE3D";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace nv
|
||||
@ -545,7 +685,8 @@ void DDSHeader::setPixelFormat(uint bitcount, uint rmask, uint gmask, uint bmask
|
||||
|
||||
void DDSHeader::setDX10Format(uint format)
|
||||
{
|
||||
this->pf.flags = 0;
|
||||
//this->pf.flags = 0;
|
||||
this->pf.fourcc = FOURCC_DX10;
|
||||
this->header10.dxgiFormat = format;
|
||||
}
|
||||
|
||||
@ -593,7 +734,8 @@ void DDSHeader::swapBytes()
|
||||
|
||||
bool DDSHeader::hasDX10Header() const
|
||||
{
|
||||
return this->pf.flags == 0;
|
||||
return this->pf.fourcc == FOURCC_DX10; // @@ This is according to AMD
|
||||
//return this->pf.flags == 0; // @@ This is according to MS
|
||||
}
|
||||
|
||||
|
||||
@ -623,7 +765,7 @@ bool DirectDrawSurface::isValid() const
|
||||
return false;
|
||||
}
|
||||
|
||||
const uint required = (DDSD_WIDTH|DDSD_HEIGHT|DDSD_CAPS|DDSD_PIXELFORMAT);
|
||||
const uint required = (DDSD_WIDTH|DDSD_HEIGHT/*|DDSD_CAPS|DDSD_PIXELFORMAT*/);
|
||||
if( (header.flags & required) != required ) {
|
||||
return false;
|
||||
}
|
||||
@ -643,40 +785,46 @@ bool DirectDrawSurface::isSupported() const
|
||||
{
|
||||
nvDebugCheck(isValid());
|
||||
|
||||
if (header.pf.flags & DDPF_FOURCC)
|
||||
if (header.hasDX10Header())
|
||||
{
|
||||
if (header.pf.fourcc != FOURCC_DXT1 &&
|
||||
header.pf.fourcc != FOURCC_DXT2 &&
|
||||
header.pf.fourcc != FOURCC_DXT3 &&
|
||||
header.pf.fourcc != FOURCC_DXT4 &&
|
||||
header.pf.fourcc != FOURCC_DXT5 &&
|
||||
header.pf.fourcc != FOURCC_RXGB &&
|
||||
header.pf.fourcc != FOURCC_ATI1 &&
|
||||
header.pf.fourcc != FOURCC_ATI2)
|
||||
{
|
||||
// Unknown fourcc code.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (header.pf.flags & DDPF_RGB)
|
||||
{
|
||||
// All RGB formats are supported now.
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isTextureCube() && (header.caps.caps2 & DDSCAPS2_CUBEMAP_ALL_FACES) != DDSCAPS2_CUBEMAP_ALL_FACES)
|
||||
{
|
||||
// Cubemaps must contain all faces.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isTexture3D())
|
||||
{
|
||||
// @@ 3D textures not supported yet.
|
||||
return false;
|
||||
if (header.pf.flags & DDPF_FOURCC)
|
||||
{
|
||||
if (header.pf.fourcc != FOURCC_DXT1 &&
|
||||
header.pf.fourcc != FOURCC_DXT2 &&
|
||||
header.pf.fourcc != FOURCC_DXT3 &&
|
||||
header.pf.fourcc != FOURCC_DXT4 &&
|
||||
header.pf.fourcc != FOURCC_DXT5 &&
|
||||
header.pf.fourcc != FOURCC_RXGB &&
|
||||
header.pf.fourcc != FOURCC_ATI1 &&
|
||||
header.pf.fourcc != FOURCC_ATI2)
|
||||
{
|
||||
// Unknown fourcc code.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (header.pf.flags & DDPF_RGB)
|
||||
{
|
||||
// All RGB formats are supported now.
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isTextureCube() && (header.caps.caps2 & DDSCAPS2_CUBEMAP_ALL_FACES) != DDSCAPS2_CUBEMAP_ALL_FACES)
|
||||
{
|
||||
// Cubemaps must contain all faces.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isTexture3D())
|
||||
{
|
||||
// @@ 3D textures not supported yet.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -712,16 +860,40 @@ uint DirectDrawSurface::depth() const
|
||||
else return 1;
|
||||
}
|
||||
|
||||
bool DirectDrawSurface::isTexture1D() const
|
||||
{
|
||||
nvDebugCheck(isValid());
|
||||
if (header.hasDX10Header())
|
||||
{
|
||||
return header.header10.resourceDimension == D3D10_RESOURCE_DIMENSION_TEXTURE1D;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DirectDrawSurface::isTexture2D() const
|
||||
{
|
||||
nvDebugCheck(isValid());
|
||||
return !isTexture3D() && !isTextureCube();
|
||||
if (header.hasDX10Header())
|
||||
{
|
||||
return header.header10.resourceDimension == D3D10_RESOURCE_DIMENSION_TEXTURE2D;
|
||||
}
|
||||
else
|
||||
{
|
||||
return !isTexture3D() && !isTextureCube();
|
||||
}
|
||||
}
|
||||
|
||||
bool DirectDrawSurface::isTexture3D() const
|
||||
{
|
||||
nvDebugCheck(isValid());
|
||||
return (header.caps.caps2 & DDSCAPS2_VOLUME) != 0;
|
||||
if (header.hasDX10Header())
|
||||
{
|
||||
return header.header10.resourceDimension == D3D10_RESOURCE_DIMENSION_TEXTURE3D;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (header.caps.caps2 & DDSCAPS2_VOLUME) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool DirectDrawSurface::isTextureCube() const
|
||||
@ -1070,7 +1242,7 @@ void DirectDrawSurface::printInfo() const
|
||||
if (header.pf.flags & DDPF_NORMAL) printf("\t\tDDPF_NORMAL\n");
|
||||
|
||||
printf("\tFourCC: '%c%c%c%c'\n", ((header.pf.fourcc >> 0) & 0xFF), ((header.pf.fourcc >> 8) & 0xFF), ((header.pf.fourcc >> 16) & 0xFF), ((header.pf.fourcc >> 24) & 0xFF));
|
||||
printf("\tBit count: %d\n", header.pf.bitcount);
|
||||
printf("\tBit count: %d (0x%.8X)\n", header.pf.bitcount, header.pf.bitcount);
|
||||
printf("\tRed mask: 0x%.8X\n", header.pf.rmask);
|
||||
printf("\tGreen mask: 0x%.8X\n", header.pf.gmask);
|
||||
printf("\tBlue mask: 0x%.8X\n", header.pf.bmask);
|
||||
@ -1101,11 +1273,11 @@ void DirectDrawSurface::printInfo() const
|
||||
printf("\tCaps 3: 0x%.8X\n", header.caps.caps3);
|
||||
printf("\tCaps 4: 0x%.8X\n", header.caps.caps4);
|
||||
|
||||
if (header.pf.flags == 0)
|
||||
if (header.hasDX10Header())
|
||||
{
|
||||
printf("DX10 Header:\n");
|
||||
printf("\tDXGI Format: %u\n", header.header10.dxgiFormat);
|
||||
printf("\tResource dimension: %u\n", header.header10.resourceDimension);
|
||||
printf("\tDXGI Format: %u (%s)\n", header.header10.dxgiFormat, getDxgiFormatString((DXGI_FORMAT)header.header10.dxgiFormat));
|
||||
printf("\tResource dimension: %u (%s)\n", header.header10.resourceDimension, getD3d10ResourceDimensionString((D3D10_RESOURCE_DIMENSION)header.header10.resourceDimension));
|
||||
printf("\tMisc flag: %u\n", header.header10.miscFlag);
|
||||
printf("\tArray size: %u\n", header.header10.arraySize);
|
||||
}
|
||||
|
@ -119,6 +119,7 @@ namespace nv
|
||||
uint width() const;
|
||||
uint height() const;
|
||||
uint depth() const;
|
||||
bool isTexture1D() const;
|
||||
bool isTexture2D() const;
|
||||
bool isTexture3D() const;
|
||||
bool isTextureCube() const;
|
||||
|
Loading…
Reference in New Issue
Block a user