ATC and ASTC support (#1410)

* ATC & ASTC support

- Add update format enum for bimg additions
- renderer_gl ATC and ATSC support
- renderer_mtl ASTC support
- renderer_vk ASTC support
- updates to other backends for new enums
- Support emulated ATC

* cleanup

* Add texture_compression test files for ATC/ASTC formats

* Update 'update' example for ATC formats

- Generalise tile code a little
- Add ATC variants
- Ignoring ASTC for now as not emulated -- should we add empty
  checkerboard emulate though?
This commit is contained in:
Andrew Willmott 2018-06-11 17:23:41 +01:00 committed by Branimir Karadžić
parent a267922971
commit acd99728b7
17 changed files with 124 additions and 20 deletions

View File

@ -171,15 +171,19 @@ public:
// Create vertex stream declaration.
PosTexcoordVertex::init();
m_textures[0] = loadTexture("textures/texture_compression_bc1.ktx", BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP);
m_textures[1] = loadTexture("textures/texture_compression_bc2.ktx", BGFX_TEXTURE_U_CLAMP);
m_textures[2] = loadTexture("textures/texture_compression_bc3.ktx", BGFX_TEXTURE_V_CLAMP);
m_textures[3] = loadTexture("textures/texture_compression_etc1.ktx", BGFX_TEXTURE_U_BORDER|BGFX_TEXTURE_V_BORDER|BGFX_TEXTURE_BORDER_COLOR(1) );
m_textures[4] = loadTexture("textures/texture_compression_etc2.ktx");
m_textures[5] = loadTexture("textures/texture_compression_ptc12.pvr");
m_textures[6] = loadTexture("textures/texture_compression_ptc14.pvr");
m_textures[7] = loadTexture("textures/texture_compression_ptc22.pvr");
m_textures[8] = loadTexture("textures/texture_compression_ptc24.pvr");
m_textures[ 0] = loadTexture("textures/texture_compression_bc1.ktx", BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP);
m_textures[ 1] = loadTexture("textures/texture_compression_bc2.ktx", BGFX_TEXTURE_U_CLAMP);
m_textures[ 2] = loadTexture("textures/texture_compression_bc3.ktx", BGFX_TEXTURE_V_CLAMP);
m_textures[ 3] = loadTexture("textures/texture_compression_etc1.ktx", BGFX_TEXTURE_U_BORDER | BGFX_TEXTURE_V_BORDER | BGFX_TEXTURE_BORDER_COLOR(1));
m_textures[ 4] = loadTexture("textures/texture_compression_etc2.ktx");
m_textures[ 5] = loadTexture("textures/texture_compression_ptc12.pvr");
m_textures[ 6] = loadTexture("textures/texture_compression_ptc14.pvr");
m_textures[ 7] = loadTexture("textures/texture_compression_ptc22.pvr");
m_textures[ 8] = loadTexture("textures/texture_compression_ptc24.pvr");
m_textures[ 9] = loadTexture("textures/texture_compression_atc.dds");
m_textures[10] = loadTexture("textures/texture_compression_atci.dds");
m_textures[11] = loadTexture("textures/texture_compression_atce.dds");
BX_STATIC_ASSERT(12 == BX_COUNTOF(m_textures));
const bgfx::Caps* caps = bgfx::getCaps();
m_texture3DSupported = !!(caps->supported & BGFX_CAPS_TEXTURE_3D);
@ -519,13 +523,16 @@ public:
// Set view and projection matrix for view 1.
const float aspectRatio = float(m_height)/float(m_width);
const float size = 11.0f;
const float margin = 0.7f;
const float sizeX = 0.5f * BX_COUNTOF(m_textures) * 2.1f + margin;
const float sizeY = sizeX * aspectRatio;
const bgfx::Caps* caps = bgfx::getCaps();
bx::mtxOrtho(proj, -size, size, size*aspectRatio, -size*aspectRatio, 0.0f, 1000.0f, 0.0f, caps->homogeneousDepth);
bx::mtxOrtho(proj, -sizeX, sizeX, sizeY, -sizeY, 0.0f, 1000.0f, 0.0f, caps->homogeneousDepth);
bgfx::setViewTransform(1, NULL, proj);
float mtx[16];
bx::mtxTranslate(mtx, -size+2.0f - BX_COUNTOF(m_textures)*0.1f*0.5f, 1.9f, 0.0f);
bx::mtxTranslate(mtx, -sizeX + margin + 1.0f, 1.9f, 0.0f);
// Set model matrix for rendering.
bgfx::setTransform(mtx);
@ -543,11 +550,11 @@ public:
// Submit primitive for rendering to view 1.
bgfx::submit(1, m_programCmp);
const float xpos = -size+2.0f - BX_COUNTOF(m_textures)*0.1f*0.5f;
const float xpos = -sizeX + margin + 1.0f;
for (uint32_t ii = 0; ii < BX_COUNTOF(m_textures); ++ii)
{
bx::mtxTranslate(mtx, xpos + ii*2.1f, size-6.5f, 0.0f);
bx::mtxTranslate(mtx, xpos + ii*2.1f, sizeY - margin - 1.0f, 0.0f);
// Set model matrix for rendering.
bgfx::setTransform(mtx);
@ -568,7 +575,7 @@ public:
for (uint32_t ii = 0; ii < m_numTextures3d; ++ii)
{
bx::mtxTranslate(mtx, xpos + (ii+3)*2.1f, -size+6.5f, 0.0f);
bx::mtxTranslate(mtx, xpos + (ii+(BX_COUNTOF(m_textures) - m_numTextures3d)*0.5f)*2.1f, -sizeY + margin + 1.0f, 0.0f);
// Set model matrix for rendering.
bgfx::setTransform(mtx);
@ -589,7 +596,7 @@ public:
for (uint32_t ii = 0; ii < 4; ++ii)
{
bx::mtxTranslate(mtx, xpos + (size-2.0f)*2.1f, -size+6.5f + ii*2.1f, 0.0f);
bx::mtxTranslate(mtx, sizeX - margin - 1.0f, -sizeY + margin + 1.0f + ii*2.1f, 0.0f);
// Set model matrix for rendering.
bgfx::setTransform(mtx);
@ -643,7 +650,7 @@ public:
uint8_t m_gg;
uint8_t m_bb;
bgfx::TextureHandle m_textures[9];
bgfx::TextureHandle m_textures[12];
bgfx::TextureHandle m_textures3d[3];
bgfx::TextureHandle m_texture2d;
bgfx::TextureHandle m_textureCube[3];

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -183,7 +183,7 @@ namespace bgfx
ASTC8x6, //!< ASTC 8x6 2.67 BPP
ASTC10x5, //!< ASTC 10x5 2.56 BPP
Unknown, // Compressed formats above.
Unknown, // Compressed formats above.
R1,
A8,

View File

@ -1404,6 +1404,9 @@ namespace bgfx
TextureFormat::PTC14A,
TextureFormat::PTC22,
TextureFormat::PTC24,
TextureFormat::ATC,
TextureFormat::ATCE,
TextureFormat::ATCI,
TextureFormat::BGRA8, // GL doesn't support BGRA8 without extensions.
TextureFormat::RGBA8, // D3D9 doesn't support RGBA8
};
@ -4467,6 +4470,15 @@ BGFX_TEXTURE_FORMAT_BIMG(PTC12A);
BGFX_TEXTURE_FORMAT_BIMG(PTC14A);
BGFX_TEXTURE_FORMAT_BIMG(PTC22);
BGFX_TEXTURE_FORMAT_BIMG(PTC24);
BGFX_TEXTURE_FORMAT_BIMG(ATC);
BGFX_TEXTURE_FORMAT_BIMG(ATCE);
BGFX_TEXTURE_FORMAT_BIMG(ATCI);
BGFX_TEXTURE_FORMAT_BIMG(ASTC4x4);
BGFX_TEXTURE_FORMAT_BIMG(ASTC5x5);
BGFX_TEXTURE_FORMAT_BIMG(ASTC6x6);
BGFX_TEXTURE_FORMAT_BIMG(ASTC8x5);
BGFX_TEXTURE_FORMAT_BIMG(ASTC8x6);
BGFX_TEXTURE_FORMAT_BIMG(ASTC10x5);
BGFX_TEXTURE_FORMAT_BIMG(Unknown);
BGFX_TEXTURE_FORMAT_BIMG(R1);
BGFX_TEXTURE_FORMAT_BIMG(A8);

View File

@ -218,7 +218,6 @@ namespace bgfx { namespace d3d11
{ DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ASTC8x6
{ DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ASTC10x5
{ DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // Unknown
{ DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // Unknown
{ DXGI_FORMAT_R1_UNORM, DXGI_FORMAT_R1_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R1
{ DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // A8
{ DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R8

View File

@ -195,7 +195,6 @@ namespace bgfx { namespace d3d12
{ DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC14A
{ DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC22
{ DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC24
{ DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC24
{ DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ATC
{ DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ATCE
{ DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ATCI

View File

@ -201,6 +201,15 @@ namespace bgfx { namespace gl
{ GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_ZERO, false }, // PTC14A
{ GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_ZERO, GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_ZERO, false }, // PTC22
{ GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_ZERO, GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_ZERO, false }, // PTC24
{ GL_ATC_RGB_AMD, GL_ZERO, GL_ATC_RGB_AMD, GL_ZERO, false }, // ATC
{ GL_ATC_RGBA_EXPLICIT_ALPHA_AMD, GL_ZERO, GL_ATC_RGBA_EXPLICIT_ALPHA_AMD, GL_ZERO, false }, // ATCE
{ GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, GL_ZERO, GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, GL_ZERO, false }, // ATCI
{ GL_COMPRESSED_RGBA_ASTC_4x4_KHR, GL_COMPRESSED_SRGB8_ASTC_4x4_KHR, GL_COMPRESSED_RGBA_ASTC_4x4_KHR, GL_ZERO, false }, // ASTC4x4
{ GL_COMPRESSED_RGBA_ASTC_5x5_KHR, GL_COMPRESSED_SRGB8_ASTC_5x5_KHR, GL_COMPRESSED_RGBA_ASTC_5x5_KHR, GL_ZERO, false }, // ASTC5x5
{ GL_COMPRESSED_RGBA_ASTC_6x6_KHR, GL_COMPRESSED_SRGB8_ASTC_6x6_KHR, GL_COMPRESSED_RGBA_ASTC_6x6_KHR, GL_ZERO, false }, // ASTC6x6
{ GL_COMPRESSED_RGBA_ASTC_8x5_KHR, GL_COMPRESSED_SRGB8_ASTC_8x5_KHR, GL_COMPRESSED_RGBA_ASTC_8x5_KHR, GL_ZERO, false }, // ASTC8x5
{ GL_COMPRESSED_RGBA_ASTC_8x6_KHR, GL_COMPRESSED_SRGB8_ASTC_8x6_KHR, GL_COMPRESSED_RGBA_ASTC_8x6_KHR, GL_ZERO, false }, // ASTC8x6
{ GL_COMPRESSED_RGBA_ASTC_10x5_KHR, GL_COMPRESSED_SRGB8_ASTC_10x5_KHR, GL_COMPRESSED_RGBA_ASTC_10x5_KHR, GL_ZERO, false }, // ASTC10x5
{ GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false }, // Unknown
{ GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false }, // ATC
{ GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false }, // ATCE

View File

@ -457,6 +457,66 @@ typedef uint64_t GLuint64;
# define GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT 0x8A57
#endif // GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT
#ifndef ATC_RGB_AMD
#define GL_ATC_RGB_AMD 0x8C92
#endif
#ifndef GL_ATC_RGBA_EXPLICIT_ALPHA_AMD
# define GL_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93
#endif
#ifndef ATC_RGBA_INTERPOLATED_ALPHA_AMD
# define GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE
#endif
#ifndef GL_COMPRESSED_RGBA_ASTC_4x4_KHR
# define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0
#endif
#ifndef GL_COMPRESSED_RGBA_ASTC_5x5_KHR
# define GL_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2
#endif
#ifndef GL_COMPRESSED_RGBA_ASTC_6x6_KHR
# define GL_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4
#endif
#ifndef GL_COMPRESSED_RGBA_ASTC_8x5_KHR
# define GL_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5
#endif
#ifndef GL_COMPRESSED_RGBA_ASTC_8x6_KHR
# define GL_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6
#endif
#ifndef GL_COMPRESSED_RGBA_ASTC_10x5_KHR
# define GL_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8
#endif
#ifndef GL_COMPRESSED_SRGB8_ASTC_4x4_KHR
# define GL_COMPRESSED_SRGB8_ASTC_4x4_KHR 0x93D0
#endif
#ifndef GL_COMPRESSED_SRGB8_ASTC_5x5_KHR
# define GL_COMPRESSED_SRGB8_ASTC_5x5_KHR 0x93D2
#endif
#ifndef GL_COMPRESSED_SRGB8_ASTC_6x6_KHR
# define GL_COMPRESSED_SRGB8_ASTC_6x6_KHR 0x93D4
#endif
#ifndef GL_COMPRESSED_SRGB8_ASTC_8x5_KHR
# define GL_COMPRESSED_SRGB8_ASTC_8x5_KHR 0x93D5
#endif
#ifndef GL_COMPRESSED_SRGB8_ASTC_8x6_KHR
# define GL_COMPRESSED_SRGB8_ASTC_8x6_KHR 0x93D6
#endif
#ifndef GL_COMPRESSED_SRGB8_ASTC_10x5_KHR
# define GL_COMPRESSED_SRGB8_ASTC_10x5_KHR 0x93D8
#endif
#ifndef GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
# define GL_COMPRESSED_RGBA_BPTC_UNORM_ARB 0x8E8C
#endif // GL_COMPRESSED_RGBA_BPTC_UNORM_ARB

View File

@ -262,6 +262,24 @@ namespace bgfx { namespace mtl
{ MTLPixelFormat(166/*PVRTC_RGBA_4BPP*/), MTLPixelFormat(167/*PVRTC_RGBA_4BPP_sRGB*/) }, // PTC14A
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // PTC22
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // PTC24
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // ATC
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // ATCE
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // ATCI
#if BX_PLATFORM_IOS
{ MTLPixelFormatASTC_4x4_LDR, MTLPixelFormatASTC_4x4_sRGB }, // ASTC4x4
{ MTLPixelFormatASTC_5x5_LDR, MTLPixelFormatASTC_5x5_sRGB }, // ASTC5x5
{ MTLPixelFormatASTC_6x6_LDR, MTLPixelFormatASTC_6x6_sRGB }, // ASTC6x6
{ MTLPixelFormatASTC_8x5_LDR, MTLPixelFormatASTC_8x5_sRGB }, // ASTC8x5
{ MTLPixelFormatASTC_8x6_LDR, MTLPixelFormatASTC_8x6_sRGB }, // ASTC8x6
{ MTLPixelFormatASTC_10x5_LDR, MTLPixelFormatASTC_10x5_sRGB }, // ASTC10x5
#else
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // ASTC4x4
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // ASTC5x5
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // ASTC6x6
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // ASTC8x5
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // ASTC8x6
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // ASTC10x5
#endif
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // Unknown
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // R1
{ MTLPixelFormatA8Unorm, MTLPixelFormatInvalid }, // A8