namespace Brutal.TextureApi.Abstractions;
///
/// Holds information about a .
///
///
///
/// Planar formats are not represented well by a FormatDescriptor. While a FormatDescriptor might be instantiated for a planar
/// texture format, the properties of the FormatDescriptor should not be relied upon.
///
///
/// This structure is taken from libktx in the file KTX-SOFTWARE\lib\vk_format.h
///
public readonly record struct FormatDescriptor
{
[Flags]
public enum DescriptorFlags
{
None = 0,
PackedBit = 1,
CompressedBit = 2,
DepthBit = 4,
StencilBit = 8,
PlanarBit = 16,
}
public FormatDescriptor(
DescriptorFlags flags,
uint blockSizeInBits,
uint blockWidth,
uint blockHeight,
uint blockDepth,
uint minBlockX,
uint minBlockY
)
{
Flags = flags;
BlockSizeInBits = blockSizeInBits;
BlockWidth = blockWidth;
BlockHeight = blockHeight;
BlockDepth = blockDepth;
MinBlocksX = minBlockX;
MinBlocksY = minBlockY;
}
public bool IsBlockCompressed => (Flags & DescriptorFlags.CompressedBit) != 0;
public bool IsPacked => (Flags & DescriptorFlags.PackedBit) != 0;
public bool IsDepth => (Flags & DescriptorFlags.DepthBit) != 0;
public bool IsStencil => (Flags & DescriptorFlags.StencilBit) != 0;
public bool IsPlanar => (Flags & DescriptorFlags.PlanarBit) != 0;
///
/// Returns the size of a block in bytes
///
public ByteSize BlockSizeInBytes => (ByteSize)(BlockSizeInBits >> 3);
///
/// Extent of a block. i.e how many texels wide, high and deep a block one block of this TextureFormat is.
/// For non block-compressed formats this will be equivalent to TexelCount(1,1,1)
///
public TexelCount3 BlockExtent => new((int)BlockWidth, (int)BlockHeight, (int)BlockDepth);
public DescriptorFlags Flags { get; }
public uint BlockSizeInBits { get; }
///
/// Width of block in texels. For compressed formats this is how many pixels wide the block represents.
///
public uint BlockWidth { get; }
///
/// Height of block in texels. For compressed formats this is how many pixels high the block represents.
///
public uint BlockHeight { get; }
///
/// Depth of the block in texels. For compressed formats this is how many pixels deep the block represents.
///
public uint BlockDepth { get; }
///
/// Minimum number of blocks wide the format must have
///
public uint MinBlocksX { get; }
///
/// Minimum number of blocks high the format must have
///
public uint MinBlocksY { get; }
}