Skip to content

Commit

Permalink
[Formats] Added ASTC and ETC2 texture formats.
Browse files Browse the repository at this point in the history
- Added several more values to Format enum for ASTC (4x4 - 12x12) and ETC1/ETC2 compression.
- Deprecated ImageFormat::BC* image formats:
  Use generic value ImageFormat::Compressed instead;
  Actual compression format is specified via hardware texture format, not the CPU image format.
- Also updated wrapper generator.
  • Loading branch information
LukasBanana committed Aug 30, 2024
1 parent 994ab8d commit daa7814
Show file tree
Hide file tree
Showing 17 changed files with 692 additions and 69 deletions.
32 changes: 32 additions & 0 deletions include/LLGL-C/LLGLWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,37 @@ typedef enum LLGLFormat
LLGLFormatBC4SNorm,
LLGLFormatBC5UNorm,
LLGLFormatBC5SNorm,
LLGLFormatASTC4x4,
LLGLFormatASTC4x4_sRGB,
LLGLFormatASTC5x4,
LLGLFormatASTC5x4_sRGB,
LLGLFormatASTC5x5,
LLGLFormatASTC5x5_sRGB,
LLGLFormatASTC6x5,
LLGLFormatASTC6x5_sRGB,
LLGLFormatASTC6x6,
LLGLFormatASTC6x6_sRGB,
LLGLFormatASTC8x5,
LLGLFormatASTC8x5_sRGB,
LLGLFormatASTC8x6,
LLGLFormatASTC8x6_sRGB,
LLGLFormatASTC8x8,
LLGLFormatASTC8x8_sRGB,
LLGLFormatASTC10x5,
LLGLFormatASTC10x5_sRGB,
LLGLFormatASTC10x6,
LLGLFormatASTC10x6_sRGB,
LLGLFormatASTC10x8,
LLGLFormatASTC10x8_sRGB,
LLGLFormatASTC10x10,
LLGLFormatASTC10x10_sRGB,
LLGLFormatASTC12x10,
LLGLFormatASTC12x10_sRGB,
LLGLFormatASTC12x12,
LLGLFormatASTC12x12_sRGB,
LLGLFormatETC1UNorm,
LLGLFormatETC2UNorm,
LLGLFormatETC2UNorm_sRGB,
}
LLGLFormat;

Expand All @@ -170,6 +201,7 @@ typedef enum LLGLImageFormat
LLGLImageFormatDepth,
LLGLImageFormatDepthStencil,
LLGLImageFormatStencil,
LLGLImageFormatCompressed,
LLGLImageFormatBC1,
LLGLImageFormatBC2,
LLGLImageFormatBC3,
Expand Down
49 changes: 44 additions & 5 deletions include/LLGL/Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,41 @@ enum class Format
BC4SNorm, //!< Compressed color format: S3TC BC4 compressed red channel with normalized signed integer component 64-bit per 4x4 block.
BC5UNorm, //!< Compressed color format: S3TC BC5 compressed red and green channels with normalized unsigned integer components in 64-bit per 4x4 block.
BC5SNorm, //!< Compressed color format: S3TC BC5 compressed red and green channels with normalized signed integer components in 128-bit per 4x4 block.

/* --- Advanced scalable texture compression (ASTC) formats --- */
ASTC4x4, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 4x4 block (8.00 bit rate). \note Only supported with: OpenGLES.
ASTC4x4_sRGB, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 4x4 block (8.00 bit rate) in non-linear sRGB color space. \note Only supported with: OpenGLES.
ASTC5x4, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 5x4 block (6.40 bit rate). \note Only supported with: OpenGLES.
ASTC5x4_sRGB, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 5x4 block (6.40 bit rate) in non-linear sRGB color space. \note Only supported with: OpenGLES.
ASTC5x5, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 5x5 block (5.12 bit rate). \note Only supported with: OpenGLES.
ASTC5x5_sRGB, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 5x5 block (5.12 bit rate) in non-linear sRGB color space. \note Only supported with: OpenGLES.
ASTC6x5, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 6x5 block (4.27 bit rate). \note Only supported with: OpenGLES.
ASTC6x5_sRGB, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 6x5 block (4.27 bit rate) in non-linear sRGB color space. \note Only supported with: OpenGLES.
ASTC6x6, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 6x6 block (3.56 bit rate). \note Only supported with: OpenGLES.
ASTC6x6_sRGB, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 6x6 block (3.56 bit rate) in non-linear sRGB color space. \note Only supported with: OpenGLES.
ASTC8x5, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 8x5 block (3.20 bit rate). \note Only supported with: OpenGLES.
ASTC8x5_sRGB, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 8x5 block (3.20 bit rate) in non-linear sRGB color space. \note Only supported with: OpenGLES.
ASTC8x6, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 8x6 block (2.67 bit rate). \note Only supported with: OpenGLES.
ASTC8x6_sRGB, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 8x6 block (2.67 bit rate) in non-linear sRGB color space. \note Only supported with: OpenGLES.
ASTC8x8, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 8x8 block (2.00 bit rate). \note Only supported with: OpenGLES.
ASTC8x8_sRGB, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 8x8 block (2.00 bit rate) in non-linear sRGB color space. \note Only supported with: OpenGLES.
ASTC10x5, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 10x5 block (2.56 bit rate). \note Only supported with: OpenGLES.
ASTC10x5_sRGB, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 10x5 block (2.56 bit rate) in non-linear sRGB color space. \note Only supported with: OpenGLES.
ASTC10x6, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 10x6 block (2.13 bit rate). \note Only supported with: OpenGLES.
ASTC10x6_sRGB, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 10x6 block (2.13 bit rate) in non-linear sRGB color space. \note Only supported with: OpenGLES.
ASTC10x8, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 10x8 block (1.60 bit rate). \note Only supported with: OpenGLES.
ASTC10x8_sRGB, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 10x8 block (1.60 bit rate) in non-linear sRGB color space. \note Only supported with: OpenGLES.
ASTC10x10, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 10x10 block (1.28 bit rate). \note Only supported with: OpenGLES.
ASTC10x10_sRGB, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 10x10 block (1.28 bit rate) in non-linear sRGB color space. \note Only supported with: OpenGLES.
ASTC12x10, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 12x10 block (1.07 bit rate). \note Only supported with: OpenGLES.
ASTC12x10_sRGB, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 12x10 block (1.07 bit rate) in non-linear sRGB color space. \note Only supported with: OpenGLES.
ASTC12x12, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 12x12 block (0.89 bit rate). \note Only supported with: OpenGLES.
ASTC12x12_sRGB, //!< Compressed color format: ASTC compressed RGBA format in 128-bit per 12x12 block (0.89 bit rate) in non-linear sRGB color space. \note Only supported with: OpenGLES.

/* --- Ericsson texture compression (ETC) formats --- */
ETC1UNorm, //!< Compressed color format: ETC1 compressed RGB with normalized unsigned integer components in 64-bit per 4x4 block. \note Only supported with: OpenGLES.
ETC2UNorm, //!< Compressed color format: ETC2 compressed RGB with normalized unsigned integer components in 64-bit per 4x4 block. \note Only supported with: OpenGLES.
ETC2UNorm_sRGB, //!< Compressed color format: ETC2 compressed RGB with normalized unsigned integer components in 64-bit per 4x4 block in non-linear sRGB color space. \note Only supported with: OpenGLES.
};

/**
Expand Down Expand Up @@ -253,11 +288,15 @@ enum class ImageFormat
Stencil, //!< Stencil component.

/* Compressed formats */
BC1, //!< Block compression BC1.
BC2, //!< Block compression BC2.
BC3, //!< Block compression BC3.
BC4, //!< Block compression BC4.
BC5, //!< Block compression BC5.
Compressed, //!< Compressed image format. The actual compression format must be specified with \c Format.

// DEPRECATED
BC1, //!< Block compression BC1. \deprecated Since 0.04b; Use ImageFormat::Compressed instead!
BC2, //!< Block compression BC2. \deprecated Since 0.04b; Use ImageFormat::Compressed instead!
BC3, //!< Block compression BC3. \deprecated Since 0.04b; Use ImageFormat::Compressed instead!
BC4, //!< Block compression BC4. \deprecated Since 0.04b; Use ImageFormat::Compressed instead!
BC5, //!< Block compression BC5. \deprecated Since 0.04b; Use ImageFormat::Compressed instead!
// /DEPRECATED
};

/**
Expand Down
9 changes: 9 additions & 0 deletions include/LLGL/ImageFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ LLGL_EXPORT DynamicByteArray ConvertImageBuffer(
unsigned threadCount = 0
);

//! \deprecated Since 0.04b; Use second version with explicit compression format instead!
LLGL_DEPRECATED("This version of DecompressImageBufferToRGBA8UNorm() is deprecated since 0.04b; Use second version with explicit compression format instead!")
LLGL_EXPORT DynamicByteArray DecompressImageBufferToRGBA8UNorm(
const ImageView& srcImageView,
const Extent2D& extent,
unsigned threadCount = 0
);

/**
\brief Decompresses the specified image buffer to RGBA format with 8-bit unsigned normalized integers.
\param[in] srcImageView Specifies the source image image.
Expand All @@ -243,6 +251,7 @@ the maximal count of threads the system supports will be used (e.g. 4 on a quad-
\return Byte buffer with the decompressed image data or null if the compression format is not supported for decompression.
*/
LLGL_EXPORT DynamicByteArray DecompressImageBufferToRGBA8UNorm(
Format compressedFormat,
const ImageView& srcImageView,
const Extent2D& extent,
unsigned threadCount = 0
Expand Down
9 changes: 8 additions & 1 deletion scripts/WrapperGen/llgl_translator_csharp.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@ def translateInitializer(init, type, isParamList = False):
self.statement('/* ----- Constants ----- */')
self.statement()

def translateConstInit(struct, init):
structBaseIdent = struct.name + '::'
if init.startswith(structBaseIdent):
return init[len(structBaseIdent):]
else:
return init

for struct in constStructs:
self.statement('public enum {} : int'.format(struct.name))
self.openScope()
Expand All @@ -293,7 +300,7 @@ def translateInitializer(init, type, isParamList = False):
declList.append(Translator.Declaration('', field.name, field.init))

for decl in declList.decls:
self.statement(decl.name + declList.spaces(1, decl.name) + ' = ' + decl.init + ',')
self.statement(f'{decl.name}{declList.spaces(1, decl.name)} = {translateConstInit(struct, decl.init)},')

self.closeScope()
self.statement()
Expand Down
9 changes: 8 additions & 1 deletion scripts/WrapperGen/llgl_translator_golang.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,21 @@ def toTypenameWithoutStdSuffix(typename):
self.statement()
self.openScope('const (')

def translateConstInit(struct, init):
structBaseIdent = struct.name + '::'
if init.startswith(structBaseIdent):
return init[len(structBaseIdent):]
else:
return init

for struct in constStructs:
# Write struct field declarations
declList = Translator.DeclarationList()
for field in struct.fields:
declList.append(Translator.Declaration('', f'{struct.name}{field.name}', field.init))

for decl in declList.decls:
self.statement(f'{decl.name}{declList.spaces(1, decl.name)} = {decl.init}')
self.statement(f'{decl.name}{declList.spaces(1, decl.name)} = {translateConstInit(struct, decl.init)}')

self.closeScope(')')
self.statement()
Expand Down
31 changes: 27 additions & 4 deletions sources/Core/ImageFlags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,26 @@ LLGL_EXPORT DynamicByteArray ConvertImageBuffer(
return dstImage;
}

LLGL_DEPRECATED_IGNORE_PUSH()

LLGL_EXPORT DynamicByteArray DecompressImageBufferToRGBA8UNorm(
const ImageView& srcImageView,
const Extent2D& extent,
unsigned threadCount)
{
switch (srcImageView.format)
{
case ImageFormat::BC1:
return DecompressImageBufferToRGBA8UNorm(Format::BC1UNorm, srcImageView, extent, threadCount);
default:
return nullptr;
}
}

LLGL_DEPRECATED_IGNORE_POP()

LLGL_EXPORT DynamicByteArray DecompressImageBufferToRGBA8UNorm(
Format compressedFormat,
const ImageView& srcImageView,
const Extent2D& extent,
unsigned threadCount)
Expand All @@ -741,10 +760,14 @@ LLGL_EXPORT DynamicByteArray DecompressImageBufferToRGBA8UNorm(
threadCount = std::thread::hardware_concurrency();

/* Check for BC compression */
if (srcImageView.format == ImageFormat::BC1)
return DecompressBC1ToRGBA8UNorm(extent, reinterpret_cast<const char*>(srcImageView.data), srcImageView.dataSize, threadCount);

return nullptr;
switch (compressedFormat)
{
case Format::BC1UNorm:
case Format::BC1UNorm_sRGB:
return DecompressBC1ToRGBA8UNorm(extent, reinterpret_cast<const char*>(srcImageView.data), srcImageView.dataSize, threadCount);
default:
return nullptr;
}
}

// Returns the 1D flattened buffer position for a 3D image coordinate ('bpp' denotes the bytes per pixel)
Expand Down
47 changes: 42 additions & 5 deletions sources/Core/TypeNames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,41 @@ LLGL_EXPORT const char* ToString(const Format val)
case T::BC4SNorm: return "BC4SNorm";
case T::BC5UNorm: return "BC5UNorm";
case T::BC5SNorm: return "BC5SNorm";

/* --- Advanced scalable texture compression (ASTC) formats --- */
case T::ASTC4x4: return "ASTC4x4";
case T::ASTC4x4_sRGB: return "ASTC4x4_sRGB";
case T::ASTC5x4: return "ASTC5x4";
case T::ASTC5x4_sRGB: return "ASTC5x4_sRGB";
case T::ASTC5x5: return "ASTC5x5";
case T::ASTC5x5_sRGB: return "ASTC5x5_sRGB";
case T::ASTC6x5: return "ASTC6x5";
case T::ASTC6x5_sRGB: return "ASTC6x5_sRGB";
case T::ASTC6x6: return "ASTC6x6";
case T::ASTC6x6_sRGB: return "ASTC6x6_sRGB";
case T::ASTC8x5: return "ASTC8x5";
case T::ASTC8x5_sRGB: return "ASTC8x5_sRGB";
case T::ASTC8x6: return "ASTC8x6";
case T::ASTC8x6_sRGB: return "ASTC8x6_sRGB";
case T::ASTC8x8: return "ASTC8x8";
case T::ASTC8x8_sRGB: return "ASTC8x8_sRGB";
case T::ASTC10x5: return "ASTC10x5";
case T::ASTC10x5_sRGB: return "ASTC10x5_sRGB";
case T::ASTC10x6: return "ASTC10x6";
case T::ASTC10x6_sRGB: return "ASTC10x6_sRGB";
case T::ASTC10x8: return "ASTC10x8";
case T::ASTC10x8_sRGB: return "ASTC10x8_sRGB";
case T::ASTC10x10: return "ASTC10x10";
case T::ASTC10x10_sRGB: return "ASTC10x10_sRGB";
case T::ASTC12x10: return "ASTC12x10";
case T::ASTC12x10_sRGB: return "ASTC12x10_sRGB";
case T::ASTC12x12: return "ASTC12x12";
case T::ASTC12x12_sRGB: return "ASTC12x12_sRGB";

/* --- Ericsson texture compression (ETC) formats --- */
case T::ETC1UNorm: return "ETC1UNorm";
case T::ETC2UNorm: return "ETC2UNorm";
case T::ETC2UNorm_sRGB: return "ETC2UNorm_sRGB";
}

return nullptr;
Expand Down Expand Up @@ -269,11 +304,13 @@ LLGL_EXPORT const char* ToString(const ImageFormat val)
case T::Stencil: return "Stencil";

/* Compressed formats */
case T::BC1: return "BC1";
case T::BC2: return "BC2";
case T::BC3: return "BC3";
case T::BC4: return "BC4";
case T::BC5: return "BC5";
case T::Compressed: return "Compressed";

case T::BC1: return "BC1 (DEPRECATED)";
case T::BC2: return "BC2 (DEPRECATED)";
case T::BC3: return "BC3 (DEPRECATED)";
case T::BC4: return "BC4 (DEPRECATED)";
case T::BC5: return "BC5 (DEPRECATED)";
}

return nullptr;
Expand Down
35 changes: 35 additions & 0 deletions sources/Renderer/DXCommon/DXTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,41 @@ DXGI_FORMAT ToDXGIFormat(const Format format)
case Format::BC4SNorm: return DXGI_FORMAT_BC4_SNORM;
case Format::BC5UNorm: return DXGI_FORMAT_BC5_UNORM;
case Format::BC5SNorm: return DXGI_FORMAT_BC5_SNORM;

/* --- Advanced scalable texture compression (ASTC) formats --- */
case Format::ASTC4x4: break;
case Format::ASTC4x4_sRGB: break;
case Format::ASTC5x4: break;
case Format::ASTC5x4_sRGB: break;
case Format::ASTC5x5: break;
case Format::ASTC5x5_sRGB: break;
case Format::ASTC6x5: break;
case Format::ASTC6x5_sRGB: break;
case Format::ASTC6x6: break;
case Format::ASTC6x6_sRGB: break;
case Format::ASTC8x5: break;
case Format::ASTC8x5_sRGB: break;
case Format::ASTC8x6: break;
case Format::ASTC8x6_sRGB: break;
case Format::ASTC8x8: break;
case Format::ASTC8x8_sRGB: break;
case Format::ASTC10x5: break;
case Format::ASTC10x5_sRGB: break;
case Format::ASTC10x6: break;
case Format::ASTC10x6_sRGB: break;
case Format::ASTC10x8: break;
case Format::ASTC10x8_sRGB: break;
case Format::ASTC10x10: break;
case Format::ASTC10x10_sRGB: break;
case Format::ASTC12x10: break;
case Format::ASTC12x10_sRGB: break;
case Format::ASTC12x12: break;
case Format::ASTC12x12_sRGB: break;

/* --- Ericsson texture compression (ETC) formats --- */
case Format::ETC1UNorm: break;
case Format::ETC2UNorm: break;
case Format::ETC2UNorm_sRGB: break;
}
MapFailed("Format", "DXGI_FORMAT");
}
Expand Down
Loading

0 comments on commit daa7814

Please sign in to comment.