From 014c81190342197fe28d072b52fd1176b76f9447 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 14 Dec 2023 15:02:13 +0100 Subject: [PATCH] Add `PixelFormatExtensions::ComputeBlockSize` --- .../Engine/Graphics/PixelFormatExtensions.cpp | 31 +++++++++++++++++++ .../Engine/Graphics/PixelFormatExtensions.h | 7 +++++ 2 files changed, 38 insertions(+) diff --git a/Source/Engine/Graphics/PixelFormatExtensions.cpp b/Source/Engine/Graphics/PixelFormatExtensions.cpp index 991844b22..f79530337 100644 --- a/Source/Engine/Graphics/PixelFormatExtensions.cpp +++ b/Source/Engine/Graphics/PixelFormatExtensions.cpp @@ -660,6 +660,37 @@ int PixelFormatExtensions::ComputeComponentsCount(const PixelFormat format) } } +int32 PixelFormatExtensions::ComputeBlockSize(PixelFormat format) +{ + switch (format) + { + case PixelFormat::BC1_Typeless: + case PixelFormat::BC1_UNorm: + case PixelFormat::BC1_UNorm_sRGB: + case PixelFormat::BC2_Typeless: + case PixelFormat::BC2_UNorm: + case PixelFormat::BC2_UNorm_sRGB: + case PixelFormat::BC3_Typeless: + case PixelFormat::BC3_UNorm: + case PixelFormat::BC3_UNorm_sRGB: + case PixelFormat::BC4_Typeless: + case PixelFormat::BC4_UNorm: + case PixelFormat::BC4_SNorm: + case PixelFormat::BC5_Typeless: + case PixelFormat::BC5_UNorm: + case PixelFormat::BC5_SNorm: + case PixelFormat::BC6H_Typeless: + case PixelFormat::BC6H_Uf16: + case PixelFormat::BC6H_Sf16: + case PixelFormat::BC7_Typeless: + case PixelFormat::BC7_UNorm: + case PixelFormat::BC7_UNorm_sRGB: + return 4; + default: + return 1; + } +} + PixelFormat PixelFormatExtensions::TosRGB(const PixelFormat format) { switch (format) diff --git a/Source/Engine/Graphics/PixelFormatExtensions.h b/Source/Engine/Graphics/PixelFormatExtensions.h index 604bcb2c3..362e5634f 100644 --- a/Source/Engine/Graphics/PixelFormatExtensions.h +++ b/Source/Engine/Graphics/PixelFormatExtensions.h @@ -173,6 +173,13 @@ public: /// The components count. API_FUNCTION() static int ComputeComponentsCount(PixelFormat format); + /// + /// Computes the amount of pixels per-axis stored in the a single block of the format (eg. 4 for BC-family). Returns 1 for uncompressed formats. + /// + /// The . + /// The block pixels count. + API_FUNCTION() static int32 ComputeBlockSize(PixelFormat format); + /// /// Finds the equivalent sRGB format to the provided format. ///