Add initial ASTC pixel format support
This commit is contained in:
@@ -5,19 +5,12 @@
|
||||
|
||||
// ReSharper disable CppClangTidyClangDiagnosticSwitchEnum
|
||||
|
||||
#define MAX_PIXEL_FORMATS 256
|
||||
|
||||
namespace
|
||||
{
|
||||
int32 sizeOfInBits[MAX_PIXEL_FORMATS];
|
||||
|
||||
int32 GetIndex(const PixelFormat format)
|
||||
{
|
||||
return (int32)format;
|
||||
}
|
||||
int32 sizeOfInBits[(int32)PixelFormat::MAX];
|
||||
}
|
||||
|
||||
#define InitFormat(formats, bitCount) for(int i = 0; i < ARRAY_COUNT(formats); i++) { sizeOfInBits[GetIndex(formats[i])] = bitCount; }
|
||||
#define InitFormat(formats, bitCount) for(int i = 0; i < ARRAY_COUNT(formats); i++) { sizeOfInBits[(int32)formats[i]] = bitCount; }
|
||||
|
||||
void PixelFormatExtensions::Init()
|
||||
{
|
||||
@@ -35,7 +28,9 @@ void PixelFormatExtensions::Init()
|
||||
PixelFormat::R8_SNorm,
|
||||
PixelFormat::R8_Typeless,
|
||||
PixelFormat::R8_UInt,
|
||||
PixelFormat::R8_UNorm
|
||||
PixelFormat::R8_UNorm,
|
||||
PixelFormat::ASTC_4x4_UNorm,
|
||||
PixelFormat::ASTC_4x4_UNorm_sRGB,
|
||||
};
|
||||
InitFormat(formats2, 8);
|
||||
|
||||
@@ -53,8 +48,7 @@ void PixelFormatExtensions::Init()
|
||||
PixelFormat::R8G8_SNorm,
|
||||
PixelFormat::R8G8_Typeless,
|
||||
PixelFormat::R8G8_UInt,
|
||||
PixelFormat::R8G8_UNorm
|
||||
|
||||
PixelFormat::R8G8_UNorm,
|
||||
};
|
||||
InitFormat(formats3, 16);
|
||||
|
||||
@@ -163,7 +157,7 @@ void PixelFormatExtensions::Init()
|
||||
|
||||
int32 PixelFormatExtensions::SizeInBits(PixelFormat format)
|
||||
{
|
||||
return sizeOfInBits[GetIndex(format)];
|
||||
return sizeOfInBits[(int32)format];
|
||||
}
|
||||
|
||||
int32 PixelFormatExtensions::AlphaSizeInBits(const PixelFormat format)
|
||||
@@ -319,6 +313,8 @@ bool PixelFormatExtensions::IsCompressed(const PixelFormat format)
|
||||
case PixelFormat::BC7_Typeless:
|
||||
case PixelFormat::BC7_UNorm:
|
||||
case PixelFormat::BC7_UNorm_sRGB:
|
||||
case PixelFormat::ASTC_4x4_UNorm:
|
||||
case PixelFormat::ASTC_4x4_UNorm_sRGB:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@@ -356,6 +352,18 @@ bool PixelFormatExtensions::IsCompressedBC(PixelFormat format)
|
||||
}
|
||||
}
|
||||
|
||||
bool PixelFormatExtensions::IsCompressedASTC(PixelFormat format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case PixelFormat::ASTC_4x4_UNorm:
|
||||
case PixelFormat::ASTC_4x4_UNorm_sRGB:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool PixelFormatExtensions::IsPacked(const PixelFormat format)
|
||||
{
|
||||
return format == PixelFormat::R8G8_B8G8_UNorm || format == PixelFormat::G8R8_G8B8_UNorm;
|
||||
@@ -382,6 +390,7 @@ bool PixelFormatExtensions::IsSRGB(const PixelFormat format)
|
||||
case PixelFormat::B8G8R8A8_UNorm_sRGB:
|
||||
case PixelFormat::B8G8R8X8_UNorm_sRGB:
|
||||
case PixelFormat::BC7_UNorm_sRGB:
|
||||
case PixelFormat::ASTC_4x4_UNorm_sRGB:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@@ -392,6 +401,8 @@ bool PixelFormatExtensions::IsHDR(const PixelFormat format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case PixelFormat::R11G11B10_Float:
|
||||
case PixelFormat::R10G10B10A2_UNorm:
|
||||
case PixelFormat::R16G16B16A16_Float:
|
||||
case PixelFormat::R32G32B32A32_Float:
|
||||
case PixelFormat::R16G16_Float:
|
||||
@@ -399,7 +410,6 @@ bool PixelFormatExtensions::IsHDR(const PixelFormat format)
|
||||
case PixelFormat::BC6H_Sf16:
|
||||
case PixelFormat::BC6H_Uf16:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -527,7 +537,7 @@ bool PixelFormatExtensions::IsInteger(const PixelFormat format)
|
||||
}
|
||||
}
|
||||
|
||||
int PixelFormatExtensions::ComputeScanlineCount(const PixelFormat format, int32 height)
|
||||
int32 PixelFormatExtensions::ComputeScanlineCount(const PixelFormat format, int32 height)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
@@ -552,13 +562,15 @@ int PixelFormatExtensions::ComputeScanlineCount(const PixelFormat format, int32
|
||||
case PixelFormat::BC7_Typeless:
|
||||
case PixelFormat::BC7_UNorm:
|
||||
case PixelFormat::BC7_UNorm_sRGB:
|
||||
case PixelFormat::ASTC_4x4_UNorm:
|
||||
case PixelFormat::ASTC_4x4_UNorm_sRGB:
|
||||
return Math::Max(1, (height + 3) / 4);
|
||||
default:
|
||||
return height;
|
||||
}
|
||||
}
|
||||
|
||||
int PixelFormatExtensions::ComputeComponentsCount(const PixelFormat format)
|
||||
int32 PixelFormatExtensions::ComputeComponentsCount(const PixelFormat format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
@@ -599,6 +611,8 @@ int PixelFormatExtensions::ComputeComponentsCount(const PixelFormat format)
|
||||
case PixelFormat::B8G8R8A8_UNorm_sRGB:
|
||||
case PixelFormat::B8G8R8X8_Typeless:
|
||||
case PixelFormat::B8G8R8X8_UNorm_sRGB:
|
||||
case PixelFormat::ASTC_4x4_UNorm:
|
||||
case PixelFormat::ASTC_4x4_UNorm_sRGB:
|
||||
return 4;
|
||||
case PixelFormat::R32G32B32_Typeless:
|
||||
case PixelFormat::R32G32B32_Float:
|
||||
@@ -678,6 +692,8 @@ PixelFormat PixelFormatExtensions::TosRGB(const PixelFormat format)
|
||||
return PixelFormat::B8G8R8X8_UNorm_sRGB;
|
||||
case PixelFormat::BC7_UNorm:
|
||||
return PixelFormat::BC7_UNorm_sRGB;
|
||||
case PixelFormat::ASTC_4x4_UNorm:
|
||||
return PixelFormat::ASTC_4x4_UNorm_sRGB;
|
||||
default:
|
||||
return format;
|
||||
}
|
||||
@@ -701,6 +717,8 @@ PixelFormat PixelFormatExtensions::ToNonsRGB(const PixelFormat format)
|
||||
return PixelFormat::B8G8R8X8_UNorm;
|
||||
case PixelFormat::BC7_UNorm_sRGB:
|
||||
return PixelFormat::BC7_UNorm;
|
||||
case PixelFormat::ASTC_4x4_UNorm_sRGB:
|
||||
return PixelFormat::ASTC_4x4_UNorm;
|
||||
default:
|
||||
return format;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user