// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. #pragma once #include "Engine/Scripting/ScriptingType.h" #include "PixelFormat.h" /// /// Extensions to . /// API_CLASS(Static) class FLAXENGINE_API PixelFormatExtensions { DECLARE_SCRIPTING_TYPE_NO_SPAWN(PixelFormatExtensions); public: /// /// Initializes cache. /// static void Init(); public: /// /// Calculates the size of a in bytes. /// /// The Pixel format. /// size of in bytes API_FUNCTION() FORCE_INLINE static int32 SizeInBytes(const PixelFormat format) { return SizeInBits(format) / 8; } /// /// Calculates the size of a in bits. /// /// The pixel format. /// The size in bits API_FUNCTION() static int32 SizeInBits(PixelFormat format); /// /// Calculate the size of the alpha channel in bits depending on the pixel format. /// /// The pixel format /// The size in bits API_FUNCTION() static int32 AlphaSizeInBits(PixelFormat format); /// /// Determines whether the specified contains alpha channel. /// /// The Pixel Format. /// true if the specified has alpha; otherwise, false. API_FUNCTION() FORCE_INLINE static bool HasAlpha(const PixelFormat format) { return AlphaSizeInBits(format) != 0; } /// /// Determines whether the specified is depth stencil. /// /// The Pixel Format. /// true if the specified is depth stencil; otherwise, false. API_FUNCTION() static bool IsDepthStencil(PixelFormat format); /// /// Determines whether the specified has stencil bits. /// /// The Pixel Format. /// true if the specified has stencil bits; otherwise, false. API_FUNCTION() static bool HasStencil(PixelFormat format); /// /// Determines whether the specified is Typeless. /// /// The . /// Enable/disable partially typeless formats. /// true if the specified is Typeless; otherwise, false. API_FUNCTION() static bool IsTypeless(PixelFormat format, bool partialTypeless = true); /// /// Returns true if the is valid. /// /// A format to validate /// True if the is valid. API_FUNCTION() static bool IsValid(PixelFormat format); /// /// Returns true if the is a compressed format. /// /// The format to check for compressed. /// True if the is a compressed format. API_FUNCTION() static bool IsCompressed(PixelFormat format); /// /// Returns true if the is a compressed format from BC formats family (BC1, BC2, BC3, BC4, BC5, BC6H, BC7). /// /// The format to check for compressed. /// True if the is a compressed format from BC formats family. API_FUNCTION() static bool IsCompressedBC(PixelFormat format); /// /// Returns true if the is a compressed format from ASTC formats family (various block sizes). /// /// The format to check for compressed. /// True if the is a compressed format from ASTC formats family. API_FUNCTION() static bool IsCompressedASTC(PixelFormat format); /// /// Determines whether the specified is video. /// /// The . /// true if the specified is video; otherwise, false. API_FUNCTION() static bool IsVideo(PixelFormat format); /// /// Determines whether the specified is a sRGB format. /// /// The . /// true if the specified is a sRGB format; otherwise, false. API_FUNCTION() static bool IsSRGB(PixelFormat format); /// /// Determines whether the specified is HDR (either 16 or 32bits Float) /// /// The format. /// true if the specified pixel format is HDR (Floating poInt); otherwise, false. API_FUNCTION() static bool IsHDR(PixelFormat format); /// /// Determines whether the specified format is in RGBA order. /// /// The format. /// true if the specified format is in RGBA order; otherwise, false. API_FUNCTION() static bool IsRgbAOrder(PixelFormat format); /// /// Determines whether the specified format is in BGRA order. /// /// The format. /// true if the specified format is in BGRA order; otherwise, false. API_FUNCTION() static bool IsBGRAOrder(PixelFormat format); /// /// Determines whether the specified format contains normalized data. It indicates that values stored in an integer format are to be mapped to the range [-1,1] (for signed values) or [0,1] (for unsigned values) when they are accessed and converted to floating point. /// /// The . /// True if given format contains normalized data type, otherwise false. API_FUNCTION() static bool IsNormalized(PixelFormat format); /// /// Determines whether the specified format is integer data type (signed or unsigned). /// /// The . /// True if given format contains integer data type (signed or unsigned), otherwise false. API_FUNCTION() static bool IsInteger(PixelFormat format); /// /// Computes the format components count (number of R, G, B, A channels). /// /// The . /// The components count. API_FUNCTION() static int32 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. /// /// The non sRGB format. /// The equivalent sRGB format if any, the provided format else. API_FUNCTION() static PixelFormat TosRGB(PixelFormat format); /// /// Finds the equivalent non sRGB format to the provided sRGB format. /// /// The non sRGB format. /// The equivalent non sRGB format if any, the provided format else. API_FUNCTION() static PixelFormat ToNonsRGB(PixelFormat format); /// /// Converts the format to typeless. /// /// The format. /// The typeless format. API_FUNCTION() static PixelFormat MakeTypeless(PixelFormat format); /// /// Converts the typeless format to float. /// /// The typeless format. /// The float format. API_FUNCTION() static PixelFormat MakeTypelessFloat(PixelFormat format); /// /// Converts the typeless format to unorm. /// /// The typeless format. /// The unorm format. API_FUNCTION() static PixelFormat MakeTypelessUNorm(PixelFormat format); public: static PixelFormat FindShaderResourceFormat(PixelFormat format, bool sRGB); static PixelFormat FindUnorderedAccessFormat(PixelFormat format); static PixelFormat FindDepthStencilFormat(PixelFormat format); static PixelFormat FindUncompressedFormat(PixelFormat format); };