mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-27 13:38:25 +01:00
SOURCE DUMP v1
This commit is contained in:
parent
bd62d51ec9
commit
fb20299e9d
7 changed files with 768360 additions and 0 deletions
50
brutal.texture/Brutal.Texture/Gli/GliConversionUtils.cs
Normal file
50
brutal.texture/Brutal.Texture/Gli/GliConversionUtils.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
namespace Brutal.TextureApi.Gli;
|
||||
|
||||
public static class GliConversionUtils
|
||||
{
|
||||
public static GliTexture ToGliTexture(this ITexture texture)
|
||||
{
|
||||
var gliTarget = GetTarget(texture);
|
||||
var gliNative = new Brutal.GliApi.Gli.Texture(
|
||||
gliTarget,
|
||||
texture.Format.ToGliFormat(),
|
||||
new(texture.Extent.X, texture.Extent.Y, texture.Extent.Z),
|
||||
texture.LayerCount,
|
||||
texture.FaceCount,
|
||||
texture.LevelCount,
|
||||
GliApi.Gli.Swizzles.Identity
|
||||
);
|
||||
var outTexture = new GliTexture(gliNative);
|
||||
texture.Data.CopyTo(outTexture.Data);
|
||||
return outTexture;
|
||||
}
|
||||
|
||||
public static Brutal.GliApi.Gli.Target GetTarget(ITexture texture)
|
||||
{
|
||||
return GetTarget(texture.Extent, texture.LayerCount, texture.IsCubemap);
|
||||
}
|
||||
|
||||
public static GliApi.Gli.Target GetTarget(TexelCount3 extent, int layerCount, bool isCubemap)
|
||||
{
|
||||
var isArray = layerCount > 1;
|
||||
|
||||
if (isCubemap)
|
||||
{
|
||||
return isArray ? GliApi.Gli.Target.CubeArray : GliApi.Gli.Target.Cube;
|
||||
}
|
||||
if (extent.Y is 1)
|
||||
{
|
||||
return isArray ? GliApi.Gli.Target._1DArray : GliApi.Gli.Target._1D;
|
||||
}
|
||||
|
||||
if (extent.Z is 1)
|
||||
{
|
||||
return isArray ? GliApi.Gli.Target._2DArray : GliApi.Gli.Target._2D;
|
||||
}
|
||||
|
||||
if (isArray)
|
||||
throw new NotImplementedException("Didn't anticipate Gli compatibility with 3d array textures");
|
||||
|
||||
return GliApi.Gli.Target._3D;
|
||||
}
|
||||
}
|
||||
430
brutal.texture/Brutal.Texture/Gli/GliFormatExtensions.cs
Normal file
430
brutal.texture/Brutal.Texture/Gli/GliFormatExtensions.cs
Normal file
|
|
@ -0,0 +1,430 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Brutal.TextureApi.Gli;
|
||||
|
||||
public static class GliFormatExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Convert a GliFormat to a TextureFormat
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Not all GliFormats are currently supported by this function due to ambiguity about whether they will convert correctly, and will throw a NotImplementedException if encountered
|
||||
/// </remarks>
|
||||
/// <param name="gliFormat">The GliFormat to convert</param>
|
||||
/// <returns>A corresponding TextureFormat</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static TextureFormat ToTextureFormat(this GliApi.Gli.Format gliFormat)
|
||||
{
|
||||
return gliFormat switch
|
||||
{
|
||||
GliApi.Gli.Format.Undefined => TextureFormat.Undefined,
|
||||
GliApi.Gli.Format.RG4_UNorm_Pack8 => TextureFormat.R4G4_UNorm_Pack8,
|
||||
GliApi.Gli.Format.RGBA4_UNorm_Pack16 => TextureFormat.R4G4B4A4_UNorm_Pack16,
|
||||
GliApi.Gli.Format.BGRA4_UNorm_Pack16 => TextureFormat.B4G4R4A4_UNorm_Pack16,
|
||||
GliApi.Gli.Format.R5G6B5_UNorm_Pack16 => TextureFormat.R5G6B5_UNorm_Pack16,
|
||||
GliApi.Gli.Format.B5G6R5_UNorm_Pack16 => TextureFormat.B5G6R5_UNorm_Pack16,
|
||||
GliApi.Gli.Format.RGB5A1_UNorm_Pack16 => TextureFormat.R5G5B5A1_UNorm_Pack16,
|
||||
GliApi.Gli.Format.BGR5A1_UNorm_Pack16 => TextureFormat.B5G5R5A1_UNorm_Pack16,
|
||||
GliApi.Gli.Format.A1RGB5_UNorm_Pack16 => TextureFormat.A1R5G5B5_UNorm_Pack16,
|
||||
GliApi.Gli.Format.R8_UNorm_Pack8 => TextureFormat.R8_UNorm,
|
||||
GliApi.Gli.Format.R8_SNorm_Pack8 => TextureFormat.R8_SNorm,
|
||||
GliApi.Gli.Format.R8_UScaled_Pack8 => TextureFormat.R8_UScaled,
|
||||
GliApi.Gli.Format.R8_SScaled_Pack8 => TextureFormat.R8_SScaled,
|
||||
GliApi.Gli.Format.R8_UInt_Pack8 => TextureFormat.R8_UInt,
|
||||
GliApi.Gli.Format.R8_SInt_Pack8 => TextureFormat.R8_SInt,
|
||||
GliApi.Gli.Format.R8_SRGB_Pack8 => TextureFormat.R8_SRGB,
|
||||
GliApi.Gli.Format.RG8_UNorm_Pack8 => TextureFormat.R8G8_UNorm,
|
||||
GliApi.Gli.Format.RG8_SNorm_Pack8 => TextureFormat.R8G8_SNorm,
|
||||
GliApi.Gli.Format.RG8_UScaled_Pack8 => TextureFormat.R8G8_UScaled,
|
||||
GliApi.Gli.Format.RG8_SScaled_Pack8 => TextureFormat.R8G8_SScaled,
|
||||
GliApi.Gli.Format.RG8_UInt_Pack8 => TextureFormat.R8G8_UInt,
|
||||
GliApi.Gli.Format.RG8_SInt_Pack8 => TextureFormat.R8G8_SInt,
|
||||
GliApi.Gli.Format.RG8_SRGB_Pack8 => TextureFormat.R8G8_SRGB,
|
||||
GliApi.Gli.Format.RGB8_UNorm_Pack8 => TextureFormat.R8G8B8_UNorm,
|
||||
GliApi.Gli.Format.RGB8_SNorm_Pack8 => TextureFormat.R8G8B8_SNorm,
|
||||
GliApi.Gli.Format.RGB8_UScaled_Pack8 => TextureFormat.R8G8B8_UScaled,
|
||||
GliApi.Gli.Format.RGB8_SScaled_Pack8 => TextureFormat.R8G8B8_SScaled,
|
||||
GliApi.Gli.Format.RGB8_UInt_Pack8 => TextureFormat.R8G8B8_UInt,
|
||||
GliApi.Gli.Format.RGB8_SInt_Pack8 => TextureFormat.R8G8B8_SInt,
|
||||
GliApi.Gli.Format.RGB8_SRGB_Pack8 => TextureFormat.R8G8B8_SRGB,
|
||||
GliApi.Gli.Format.BGR8_UNorm_Pack8 => TextureFormat.B8G8R8_UNorm,
|
||||
GliApi.Gli.Format.BGR8_SNorm_Pack8 => TextureFormat.B8G8R8_SNorm,
|
||||
GliApi.Gli.Format.BGR8_UScaled_Pack8 => TextureFormat.B8G8R8_UScaled,
|
||||
GliApi.Gli.Format.BGR8_SScaled_Pack8 => TextureFormat.B8G8R8_SScaled,
|
||||
GliApi.Gli.Format.BGR8_UInt_Pack8 => TextureFormat.B8G8R8_UInt,
|
||||
GliApi.Gli.Format.BGR8_SInt_Pack8 => TextureFormat.B8G8R8_SInt,
|
||||
GliApi.Gli.Format.BGR8_SRGB_Pack8 => TextureFormat.B8G8R8_SRGB,
|
||||
GliApi.Gli.Format.RGBA8_UNorm_Pack8 => TextureFormat.R8G8B8A8_UNorm,
|
||||
GliApi.Gli.Format.RGBA8_SNorm_Pack8 => TextureFormat.R8G8B8A8_SNorm,
|
||||
GliApi.Gli.Format.RGBA8_UScaled_Pack8 => TextureFormat.R8G8B8A8_UScaled,
|
||||
GliApi.Gli.Format.RGBA8_SScaled_Pack8 => TextureFormat.R8G8B8A8_SScaled,
|
||||
GliApi.Gli.Format.RGBA8_UInt_Pack8 => TextureFormat.R8G8B8A8_UInt,
|
||||
GliApi.Gli.Format.RGBA8_SInt_Pack8 => TextureFormat.R8G8B8A8_SInt,
|
||||
GliApi.Gli.Format.RGBA8_SRGB_Pack8 => TextureFormat.R8G8B8A8_SRGB,
|
||||
GliApi.Gli.Format.BGRA8_UNorm_Pack8 => TextureFormat.B8G8R8A8_UNorm,
|
||||
GliApi.Gli.Format.BGRA8_SNorm_Pack8 => TextureFormat.B8G8R8A8_SNorm,
|
||||
GliApi.Gli.Format.BGRA8_UScaled_Pack8 => TextureFormat.B8G8R8A8_UScaled,
|
||||
GliApi.Gli.Format.BGRA8_SScaled_Pack8 => TextureFormat.B8G8R8A8_SScaled,
|
||||
GliApi.Gli.Format.BGRA8_UInt_Pack8 => TextureFormat.B8G8R8A8_UInt,
|
||||
GliApi.Gli.Format.BGRA8_SInt_Pack8 => TextureFormat.B8G8R8A8_SInt,
|
||||
GliApi.Gli.Format.BGRA8_SRGB_Pack8 => TextureFormat.B8G8R8A8_SRGB,
|
||||
// Note: Vulkan seems to order the naming here for 32 bit packed formats from the least significant byte to the most significant byte, rather the memory layout order
|
||||
// See Enums.cs docstrings on the Format enum for more information
|
||||
GliApi.Gli.Format.RGBA8_UNorm_Pack32 => TextureFormat.A8B8G8R8_UNorm_Pack32,
|
||||
GliApi.Gli.Format.RGBA8_SNorm_Pack32 => TextureFormat.A8B8G8R8_SNorm_Pack32,
|
||||
GliApi.Gli.Format.RGBA8_UScaled_Pack32 => TextureFormat.A8B8G8R8_UScaled_Pack32,
|
||||
GliApi.Gli.Format.RGBA8_SScaled_Pack32 => TextureFormat.A8B8G8R8_SScaled_Pack32,
|
||||
GliApi.Gli.Format.RGBA8_UInt_Pack32 => TextureFormat.A8B8G8R8_UInt_Pack32,
|
||||
GliApi.Gli.Format.RGBA8_SInt_Pack32 => TextureFormat.A8B8G8R8_SInt_Pack32,
|
||||
GliApi.Gli.Format.RGBA8_SRGB_Pack32 => TextureFormat.A8B8G8R8_SRGB_Pack32,
|
||||
// These formats aren't named consistently between Gli and Vulkan, have removed support until we can confirm the correct mapping
|
||||
GliApi.Gli.Format.RGB10A2_UNorm_Pack32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGB10A2_SNorm_Pack32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGB10A2_UScaled_Pack32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGB10A2_SScaled_Pack32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGB10A2_UInt_Pack32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGB10A2_SInt_Pack32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.BGR10A2_UNorm_Pack32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.BGR10A2_SNorm_Pack32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.BGR10A2_UScaled_Pack32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.BGR10A2_SScaled_Pack32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.BGR10A2_UInt_Pack32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.BGR10A2_SInt_Pack32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.R16_UNorm_Pack16 => TextureFormat.R16_UNorm,
|
||||
GliApi.Gli.Format.R16_SNorm_Pack16 => TextureFormat.R16_SNorm,
|
||||
GliApi.Gli.Format.R16_UScaled_Pack16 => TextureFormat.R16_UScaled,
|
||||
GliApi.Gli.Format.R16_SScaled_Pack16 => TextureFormat.R16_SScaled,
|
||||
GliApi.Gli.Format.R16_UInt_Pack16 => TextureFormat.R16_UInt,
|
||||
GliApi.Gli.Format.R16_SInt_Pack16 => TextureFormat.R16_SInt,
|
||||
GliApi.Gli.Format.R16_SFloat_Pack16 => TextureFormat.R16_SFloat,
|
||||
GliApi.Gli.Format.RG16_UNorm_Pack16 => TextureFormat.R16G16_UNorm,
|
||||
GliApi.Gli.Format.RG16_SNorm_Pack16 => TextureFormat.R16G16_SNorm,
|
||||
GliApi.Gli.Format.RG16_UScaled_Pack16 => TextureFormat.R16G16_UScaled,
|
||||
GliApi.Gli.Format.RG16_SScaled_Pack16 => TextureFormat.R16G16_SScaled,
|
||||
GliApi.Gli.Format.RG16_UInt_Pack16 => TextureFormat.R16G16_UInt,
|
||||
GliApi.Gli.Format.RG16_SInt_Pack16 => TextureFormat.R16G16_SInt,
|
||||
GliApi.Gli.Format.RG16_SFloat_Pack16 => TextureFormat.R16G16_SFloat,
|
||||
GliApi.Gli.Format.RGB16_UNorm_Pack16 => TextureFormat.R16G16B16_UNorm,
|
||||
GliApi.Gli.Format.RGB16_SNorm_Pack16 => TextureFormat.R16G16B16_SNorm,
|
||||
GliApi.Gli.Format.RGB16_UScaled_Pack16 => TextureFormat.R16G16B16_UScaled,
|
||||
GliApi.Gli.Format.RGB16_SScaled_Pack16 => TextureFormat.R16G16B16_SScaled,
|
||||
GliApi.Gli.Format.RGB16_UInt_Pack16 => TextureFormat.R16G16B16_UInt,
|
||||
GliApi.Gli.Format.RGB16_SInt_Pack16 => TextureFormat.R16G16B16_SInt,
|
||||
GliApi.Gli.Format.RGB16_SFloat_Pack16 => TextureFormat.R16G16B16_SFloat,
|
||||
GliApi.Gli.Format.RGBA16_UNorm_Pack16 => TextureFormat.R16G16B16A16_UNorm,
|
||||
GliApi.Gli.Format.RGBA16_SNorm_Pack16 => TextureFormat.R16G16B16A16_SNorm,
|
||||
GliApi.Gli.Format.RGBA16_UScaled_Pack16 => TextureFormat.R16G16B16A16_UScaled,
|
||||
GliApi.Gli.Format.RGBA16_SScaled_Pack16 => TextureFormat.R16G16B16A16_SScaled,
|
||||
GliApi.Gli.Format.RGBA16_UInt_Pack16 => TextureFormat.R16G16B16A16_UInt,
|
||||
GliApi.Gli.Format.RGBA16_SInt_Pack16 => TextureFormat.R16G16B16A16_SInt,
|
||||
GliApi.Gli.Format.RGBA16_SFloat_Pack16 => TextureFormat.R16G16B16A16_SFloat,
|
||||
GliApi.Gli.Format.R32_UInt_Pack32 => TextureFormat.R32_UInt,
|
||||
GliApi.Gli.Format.R32_SInt_Pack32 => TextureFormat.R32_SInt,
|
||||
GliApi.Gli.Format.R32_SFloat_Pack32 => TextureFormat.R32_SFloat,
|
||||
GliApi.Gli.Format.RG32_UInt_Pack32 => TextureFormat.R32G32_UInt,
|
||||
GliApi.Gli.Format.RG32_SInt_Pack32 => TextureFormat.R32G32_SInt,
|
||||
GliApi.Gli.Format.RG32_SFloat_Pack32 => TextureFormat.R32G32_SFloat,
|
||||
GliApi.Gli.Format.RGB32_UInt_Pack32 => TextureFormat.R32G32B32_UInt,
|
||||
GliApi.Gli.Format.RGB32_SInt_Pack32 => TextureFormat.R32G32B32_SInt,
|
||||
GliApi.Gli.Format.RGB32_SFloat_Pack32 => TextureFormat.R32G32B32_SFloat,
|
||||
GliApi.Gli.Format.RGBA32_UInt_Pack32 => TextureFormat.R32G32B32A32_UInt,
|
||||
GliApi.Gli.Format.RGBA32_SInt_Pack32 => TextureFormat.R32G32B32A32_SInt,
|
||||
GliApi.Gli.Format.RGBA32_SFloat_Pack32 => TextureFormat.R32G32B32A32_SFloat,
|
||||
GliApi.Gli.Format.R64_UInt_Pack64 => TextureFormat.R64_UInt,
|
||||
GliApi.Gli.Format.R64_SInt_Pack64 => TextureFormat.R64_SInt,
|
||||
GliApi.Gli.Format.R64_SFloat_Pack64 => TextureFormat.R64_SFloat,
|
||||
GliApi.Gli.Format.RG64_UInt_Pack64 => TextureFormat.R64G64_UInt,
|
||||
GliApi.Gli.Format.RG64_SInt_Pack64 => TextureFormat.R64G64_SInt,
|
||||
GliApi.Gli.Format.RG64_SFloat_Pack64 => TextureFormat.R64G64_SFloat,
|
||||
GliApi.Gli.Format.RGB64_UInt_Pack64 => TextureFormat.R64G64B64_UInt,
|
||||
GliApi.Gli.Format.RGB64_SInt_Pack64 => TextureFormat.R64G64B64_SInt,
|
||||
GliApi.Gli.Format.RGB64_SFloat_Pack64 => TextureFormat.R64G64B64_SFloat,
|
||||
GliApi.Gli.Format.RGBA64_UInt_Pack64 => TextureFormat.R64G64B64A64_UInt,
|
||||
GliApi.Gli.Format.RGBA64_SInt_Pack64 => TextureFormat.R64G64B64A64_SInt,
|
||||
GliApi.Gli.Format.RGBA64_SFloat_Pack64 => TextureFormat.R64G64B64A64_SFloat,
|
||||
GliApi.Gli.Format.RG11B10_UFloat_Pack32 => TextureFormat.B10G11R11_UFloat_Pack32,
|
||||
GliApi.Gli.Format.RGB9E5_UFloat_Pack32 => TextureFormat.E5B9G9R9_UFloat_Pack32,
|
||||
GliApi.Gli.Format.D16_UNorm_Pack16 => TextureFormat.D16_UNorm,
|
||||
GliApi.Gli.Format.D24_UNorm_Pack32 => TextureFormat.X8D24_UNorm_Pack32,
|
||||
GliApi.Gli.Format.D32_SFloat_Pack32 => TextureFormat.D32_SFloat,
|
||||
GliApi.Gli.Format.S8_UInt_Pack8 => TextureFormat.S8_UInt,
|
||||
GliApi.Gli.Format.D16_UNorm_S8_UInt_Pack32 => TextureFormat.D16_UNormS8_UInt,
|
||||
GliApi.Gli.Format.D24_UNorm_S8_UInt_Pack32 => TextureFormat.D24_UNormS8_UInt,
|
||||
GliApi.Gli.Format.D32_SFloat_S8_UInt_Pack64 => TextureFormat.D32_SFloatS8_UInt,
|
||||
// Note: DXT1 is equivalent to BC1
|
||||
GliApi.Gli.Format.RGB_DXT1_UNorm_Block8 => TextureFormat.BC1Rgb_UNorm_Block,
|
||||
GliApi.Gli.Format.RGB_DXT1_SRGB_Block8 => TextureFormat.BC1Rgb_SRGB_Block,
|
||||
GliApi.Gli.Format.RGBA_DXT1_UNorm_Block8 => TextureFormat.BC1Rgba_UNorm_Block,
|
||||
GliApi.Gli.Format.RGBA_DXT1_SRGB_Block8 => TextureFormat.BC1Rgba_SRGB_Block,
|
||||
// Note: DXT2/3 is equivalent to BC2
|
||||
GliApi.Gli.Format.RGBA_DXT3_UNorm_Block16 => TextureFormat.BC2_UNorm_Block,
|
||||
GliApi.Gli.Format.RGBA_DXT3_SRGB_Block16 => TextureFormat.BC2_SRGB_Block,
|
||||
// Note: DXT4/5 is equivalent to BC3
|
||||
GliApi.Gli.Format.RGBA_DXT5_UNorm_Block16 => TextureFormat.BC3_UNorm_Block,
|
||||
GliApi.Gli.Format.RGBA_DXT5_SRGB_Block16 => TextureFormat.BC3_SRGB_Block,
|
||||
// Note: ATI1 is equivalent to BC4
|
||||
GliApi.Gli.Format.R_ATI1N_UNorm_Block8 => TextureFormat.BC4_UNorm_Block,
|
||||
GliApi.Gli.Format.R_ATI1N_SNorm_Block8 => TextureFormat.BC4_SNorm_Block,
|
||||
// Note: ATI2 is equivalent to BC5
|
||||
GliApi.Gli.Format.RG_ATI2N_UNorm_Block16 => TextureFormat.BC5_UNorm_Block,
|
||||
GliApi.Gli.Format.RG_ATI2N_SNorm_Block16 => TextureFormat.BC5_SNorm_Block,
|
||||
// It's not clear what the Vulkan equivalent of these formats are
|
||||
GliApi.Gli.Format.RGB_BP_UFloat_Block16 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGB_BP_SFloat_Block16 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGBA_BP_UNorm_Block16 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGBA_BP_SRGB_Block16 => throw new NotImplementedException(),
|
||||
// ETC formats
|
||||
GliApi.Gli.Format.RGB_ETC2_UNorm_Block8 => TextureFormat.ETC2R8G8B8_UNorm_Block,
|
||||
GliApi.Gli.Format.RGB_ETC2_SRGB_Block8 => TextureFormat.ETC2R8G8B8_SRGB_Block,
|
||||
GliApi.Gli.Format.RGBA_ETC2_UNorm_Block8 => throw new NotImplementedException(), // It's not clear what the Vulkan equivalent of this format is
|
||||
GliApi.Gli.Format.RGBA_ETC2_SRGB_Block8 => throw new NotImplementedException(), // It's not clear what the Vulkan equivalent of this format is
|
||||
GliApi.Gli.Format.RGBA_ETC2_UNorm_Block16 => TextureFormat.ETC2R8G8B8A8_UNorm_Block,
|
||||
GliApi.Gli.Format.RGBA_ETC2_SRGB_Block16 => TextureFormat.ETC2R8G8B8A8_SRGB_Block,
|
||||
GliApi.Gli.Format.R_EAC_UNorm_Block8 => TextureFormat.EACR11_UNorm_Block,
|
||||
GliApi.Gli.Format.R_EAC_SNorm_Block8 => TextureFormat.EACR11_SNorm_Block,
|
||||
GliApi.Gli.Format.RG_EAC_UNorm_Block16 => TextureFormat.EACR11G11_UNorm_Block,
|
||||
GliApi.Gli.Format.RG_EAC_SNorm_Block16 => TextureFormat.EACR11G11_SNorm_Block,
|
||||
// ASTC formats
|
||||
GliApi.Gli.Format.RGBA_ASTC_4X4_UNorm_Block16 => TextureFormat.ASTC4X4_UNorm_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_4X4_SRGB_Block16 => TextureFormat.ASTC4X4_SRGB_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_5X4_UNorm_Block16 => TextureFormat.ASTC5X4_UNorm_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_5X4_SRGB_Block16 => TextureFormat.ASTC5X4_SRGB_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_5X5_UNorm_Block16 => TextureFormat.ASTC5X5_UNorm_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_5X5_SRGB_Block16 => TextureFormat.ASTC5X5_SRGB_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_6X5_UNorm_Block16 => TextureFormat.ASTC6X5_UNorm_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_6X5_SRGB_Block16 => TextureFormat.ASTC6X5_SRGB_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_6X6_UNorm_Block16 => TextureFormat.ASTC6X6_UNorm_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_6X6_SRGB_Block16 => TextureFormat.ASTC6X6_SRGB_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_8X5_UNorm_Block16 => TextureFormat.ASTC8X5_UNorm_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_8X5_SRGB_Block16 => TextureFormat.ASTC8X5_SRGB_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_8X6_UNorm_Block16 => TextureFormat.ASTC8X6_UNorm_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_8X6_SRGB_Block16 => TextureFormat.ASTC8X6_SRGB_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_8X8_UNorm_Block16 => TextureFormat.ASTC8X8_UNorm_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_8X8_SRGB_Block16 => TextureFormat.ASTC8X8_SRGB_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_10X5_UNorm_Block16 => TextureFormat.ASTC10X5_UNorm_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_10X5_SRGB_Block16 => TextureFormat.ASTC10X5_SRGB_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_10X6_UNorm_Block16 => TextureFormat.ASTC10X6_UNorm_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_10X6_SRGB_Block16 => TextureFormat.ASTC10X6_SRGB_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_10X8_UNorm_Block16 => TextureFormat.ASTC10X8_UNorm_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_10X8_SRGB_Block16 => TextureFormat.ASTC10X8_SRGB_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_10X10_UNorm_Block16 => TextureFormat.ASTC10X10_UNorm_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_10X10_SRGB_Block16 => TextureFormat.ASTC10X10_SRGB_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_12X10_UNorm_Block16 => TextureFormat.ASTC12X10_UNorm_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_12X10_SRGB_Block16 => TextureFormat.ASTC12X10_SRGB_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_12X12_UNorm_Block16 => TextureFormat.ASTC12X12_UNorm_Block,
|
||||
GliApi.Gli.Format.RGBA_ASTC_12X12_SRGB_Block16 => TextureFormat.ASTC12X12_SRGB_Block,
|
||||
// PVRTC formats - requires VK_IMG_format_pvrtc extension, not currently exposed
|
||||
GliApi.Gli.Format.RGB_PVRTC1_8X8_UNorm_Block32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGB_PVRTC1_8X8_SRGB_Block32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGB_PVRTC1_16X8_UNorm_Block32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGB_PVRTC1_16X8_SRGB_Block32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGBA_PVRTC1_8X8_UNorm_Block32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGBA_PVRTC1_8X8_SRGB_Block32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGBA_PVRTC1_16X8_UNorm_Block32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGBA_PVRTC1_16X8_SRGB_Block32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGBA_PVRTC2_4X4_UNorm_Block8 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGBA_PVRTC2_4X4_SRGB_Block8 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGBA_PVRTC2_8X4_UNorm_Block8 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGBA_PVRTC2_8X4_SRGB_Block8 => throw new NotImplementedException(),
|
||||
// Unknown whether these formats are supported by Vulkan
|
||||
GliApi.Gli.Format.RGB_ETC_UNorm_Block8 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGB_ATC_UNorm_Block8 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGBA_ATCA_UNorm_Block16 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RGBA_ATCI_UNorm_Block16 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.L8_UNorm_Pack8 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.A8_UNorm_Pack8 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.LA8_UNorm_Pack8 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.L16_UNorm_Pack16 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.A16_UNorm_Pack16 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.LA16_UNorm_Pack16 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.BGR8_UNorm_Pack32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.BGR8_SRGB_Pack32 => throw new NotImplementedException(),
|
||||
GliApi.Gli.Format.RG3B2_UNorm_Pack8 => throw new NotImplementedException(),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(gliFormat), gliFormat, null),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a TextureFormat to a GliFormat
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Not all formats are currently supported by this function due to ambiguity about whether they will convert correctly
|
||||
/// </remarks>
|
||||
/// <param name="format">The TextureFormat to convert</param>
|
||||
/// <returns>A corresponding GliFormat</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static GliApi.Gli.Format ToGliFormat(this TextureFormat format)
|
||||
{
|
||||
return format switch
|
||||
{
|
||||
TextureFormat.Undefined => GliApi.Gli.Format.Undefined,
|
||||
TextureFormat.R4G4_UNorm_Pack8 => GliApi.Gli.Format.RG4_UNorm_Pack8,
|
||||
TextureFormat.R4G4B4A4_UNorm_Pack16 => GliApi.Gli.Format.RGBA4_UNorm_Pack16,
|
||||
TextureFormat.B4G4R4A4_UNorm_Pack16 => GliApi.Gli.Format.BGRA4_UNorm_Pack16,
|
||||
TextureFormat.R5G6B5_UNorm_Pack16 => GliApi.Gli.Format.R5G6B5_UNorm_Pack16,
|
||||
TextureFormat.B5G6R5_UNorm_Pack16 => GliApi.Gli.Format.B5G6R5_UNorm_Pack16,
|
||||
TextureFormat.R5G5B5A1_UNorm_Pack16 => GliApi.Gli.Format.RGB5A1_UNorm_Pack16,
|
||||
TextureFormat.B5G5R5A1_UNorm_Pack16 => GliApi.Gli.Format.BGR5A1_UNorm_Pack16,
|
||||
TextureFormat.A1R5G5B5_UNorm_Pack16 => GliApi.Gli.Format.A1RGB5_UNorm_Pack16,
|
||||
TextureFormat.R8_UNorm => GliApi.Gli.Format.R8_UNorm_Pack8,
|
||||
TextureFormat.R8_SNorm => GliApi.Gli.Format.R8_SNorm_Pack8,
|
||||
TextureFormat.R8_UScaled => GliApi.Gli.Format.R8_UScaled_Pack8,
|
||||
TextureFormat.R8_SScaled => GliApi.Gli.Format.R8_SScaled_Pack8,
|
||||
TextureFormat.R8_UInt => GliApi.Gli.Format.R8_UInt_Pack8,
|
||||
TextureFormat.R8_SInt => GliApi.Gli.Format.R8_SInt_Pack8,
|
||||
TextureFormat.R8_SRGB => GliApi.Gli.Format.R8_SRGB_Pack8,
|
||||
TextureFormat.R8G8_UNorm => GliApi.Gli.Format.RG8_UNorm_Pack8,
|
||||
TextureFormat.R8G8_SNorm => GliApi.Gli.Format.RG8_SNorm_Pack8,
|
||||
TextureFormat.R8G8_UScaled => GliApi.Gli.Format.RG8_UScaled_Pack8,
|
||||
TextureFormat.R8G8_SScaled => GliApi.Gli.Format.RG8_SScaled_Pack8,
|
||||
TextureFormat.R8G8_UInt => GliApi.Gli.Format.RG8_UInt_Pack8,
|
||||
TextureFormat.R8G8_SInt => GliApi.Gli.Format.RG8_SInt_Pack8,
|
||||
TextureFormat.R8G8_SRGB => GliApi.Gli.Format.RG8_SRGB_Pack8,
|
||||
TextureFormat.R8G8B8_UNorm => GliApi.Gli.Format.RGB8_UNorm_Pack8,
|
||||
TextureFormat.R8G8B8_SNorm => GliApi.Gli.Format.RGB8_SNorm_Pack8,
|
||||
TextureFormat.R8G8B8_UScaled => GliApi.Gli.Format.RGB8_UScaled_Pack8,
|
||||
TextureFormat.R8G8B8_SScaled => GliApi.Gli.Format.RGB8_SScaled_Pack8,
|
||||
TextureFormat.R8G8B8_UInt => GliApi.Gli.Format.RGB8_UInt_Pack8,
|
||||
TextureFormat.R8G8B8_SInt => GliApi.Gli.Format.RGB8_SInt_Pack8,
|
||||
TextureFormat.R8G8B8_SRGB => GliApi.Gli.Format.RGB8_SRGB_Pack8,
|
||||
TextureFormat.B8G8R8_UNorm => GliApi.Gli.Format.BGR8_UNorm_Pack8,
|
||||
TextureFormat.B8G8R8_SNorm => GliApi.Gli.Format.BGR8_SNorm_Pack8,
|
||||
TextureFormat.B8G8R8_UScaled => GliApi.Gli.Format.BGR8_UScaled_Pack8,
|
||||
TextureFormat.B8G8R8_SScaled => GliApi.Gli.Format.BGR8_SScaled_Pack8,
|
||||
TextureFormat.B8G8R8_UInt => GliApi.Gli.Format.BGR8_UInt_Pack8,
|
||||
TextureFormat.B8G8R8_SInt => GliApi.Gli.Format.BGR8_SInt_Pack8,
|
||||
TextureFormat.B8G8R8_SRGB => GliApi.Gli.Format.BGR8_SRGB_Pack8,
|
||||
TextureFormat.R8G8B8A8_UNorm => GliApi.Gli.Format.RGBA8_UNorm_Pack8,
|
||||
TextureFormat.R8G8B8A8_SNorm => GliApi.Gli.Format.RGBA8_SNorm_Pack8,
|
||||
TextureFormat.R8G8B8A8_UScaled => GliApi.Gli.Format.RGBA8_UScaled_Pack8,
|
||||
TextureFormat.R8G8B8A8_SScaled => GliApi.Gli.Format.RGBA8_SScaled_Pack8,
|
||||
TextureFormat.R8G8B8A8_UInt => GliApi.Gli.Format.RGBA8_UInt_Pack8,
|
||||
TextureFormat.R8G8B8A8_SInt => GliApi.Gli.Format.RGBA8_SInt_Pack8,
|
||||
TextureFormat.R8G8B8A8_SRGB => GliApi.Gli.Format.RGBA8_SRGB_Pack8,
|
||||
TextureFormat.B8G8R8A8_UNorm => GliApi.Gli.Format.BGRA8_UNorm_Pack8,
|
||||
TextureFormat.B8G8R8A8_SNorm => GliApi.Gli.Format.BGRA8_SNorm_Pack8,
|
||||
TextureFormat.B8G8R8A8_UScaled => GliApi.Gli.Format.BGRA8_UScaled_Pack8,
|
||||
TextureFormat.B8G8R8A8_SScaled => GliApi.Gli.Format.BGRA8_SScaled_Pack8,
|
||||
TextureFormat.B8G8R8A8_UInt => GliApi.Gli.Format.BGRA8_UInt_Pack8,
|
||||
TextureFormat.B8G8R8A8_SInt => GliApi.Gli.Format.BGRA8_SInt_Pack8,
|
||||
TextureFormat.B8G8R8A8_SRGB => GliApi.Gli.Format.BGRA8_SRGB_Pack8,
|
||||
TextureFormat.A8B8G8R8_UNorm_Pack32 => GliApi.Gli.Format.RGBA8_UNorm_Pack32,
|
||||
TextureFormat.A8B8G8R8_SNorm_Pack32 => GliApi.Gli.Format.RGBA8_SNorm_Pack32,
|
||||
TextureFormat.A8B8G8R8_UScaled_Pack32 => GliApi.Gli.Format.RGBA8_UScaled_Pack32,
|
||||
TextureFormat.A8B8G8R8_SScaled_Pack32 => GliApi.Gli.Format.RGBA8_SScaled_Pack32,
|
||||
TextureFormat.A8B8G8R8_UInt_Pack32 => GliApi.Gli.Format.RGBA8_UInt_Pack32,
|
||||
TextureFormat.A8B8G8R8_SInt_Pack32 => GliApi.Gli.Format.RGBA8_SInt_Pack32,
|
||||
TextureFormat.A8B8G8R8_SRGB_Pack32 => GliApi.Gli.Format.RGBA8_SRGB_Pack32,
|
||||
TextureFormat.R16_UNorm => GliApi.Gli.Format.R16_UNorm_Pack16,
|
||||
TextureFormat.R16_SNorm => GliApi.Gli.Format.R16_SNorm_Pack16,
|
||||
TextureFormat.R16_UScaled => GliApi.Gli.Format.R16_UScaled_Pack16,
|
||||
TextureFormat.R16_SScaled => GliApi.Gli.Format.R16_SScaled_Pack16,
|
||||
TextureFormat.R16_UInt => GliApi.Gli.Format.R16_UInt_Pack16,
|
||||
TextureFormat.R16_SInt => GliApi.Gli.Format.R16_SInt_Pack16,
|
||||
TextureFormat.R16_SFloat => GliApi.Gli.Format.R16_SFloat_Pack16,
|
||||
TextureFormat.R16G16_UNorm => GliApi.Gli.Format.RG16_UNorm_Pack16,
|
||||
TextureFormat.R16G16_SNorm => GliApi.Gli.Format.RG16_SNorm_Pack16,
|
||||
TextureFormat.R16G16_UScaled => GliApi.Gli.Format.RG16_UScaled_Pack16,
|
||||
TextureFormat.R16G16_SScaled => GliApi.Gli.Format.RG16_SScaled_Pack16,
|
||||
TextureFormat.R16G16_UInt => GliApi.Gli.Format.RG16_UInt_Pack16,
|
||||
TextureFormat.R16G16_SInt => GliApi.Gli.Format.RG16_SInt_Pack16,
|
||||
TextureFormat.R16G16_SFloat => GliApi.Gli.Format.RG16_SFloat_Pack16,
|
||||
TextureFormat.R16G16B16_UNorm => GliApi.Gli.Format.RGB16_UNorm_Pack16,
|
||||
TextureFormat.R16G16B16_SNorm => GliApi.Gli.Format.RGB16_SNorm_Pack16,
|
||||
TextureFormat.R16G16B16_UScaled => GliApi.Gli.Format.RGB16_UScaled_Pack16,
|
||||
TextureFormat.R16G16B16_SScaled => GliApi.Gli.Format.RGB16_SScaled_Pack16,
|
||||
TextureFormat.R16G16B16_UInt => GliApi.Gli.Format.RGB16_UInt_Pack16,
|
||||
TextureFormat.R16G16B16_SInt => GliApi.Gli.Format.RGB16_SInt_Pack16,
|
||||
TextureFormat.R16G16B16_SFloat => GliApi.Gli.Format.RGB16_SFloat_Pack16,
|
||||
TextureFormat.R16G16B16A16_UNorm => GliApi.Gli.Format.RGBA16_UNorm_Pack16,
|
||||
TextureFormat.R16G16B16A16_SNorm => GliApi.Gli.Format.RGBA16_SNorm_Pack16,
|
||||
TextureFormat.R16G16B16A16_UScaled => GliApi.Gli.Format.RGBA16_UScaled_Pack16,
|
||||
TextureFormat.R16G16B16A16_SScaled => GliApi.Gli.Format.RGBA16_SScaled_Pack16,
|
||||
TextureFormat.R16G16B16A16_UInt => GliApi.Gli.Format.RGBA16_UInt_Pack16,
|
||||
TextureFormat.R16G16B16A16_SInt => GliApi.Gli.Format.RGBA16_SInt_Pack16,
|
||||
TextureFormat.R16G16B16A16_SFloat => GliApi.Gli.Format.RGBA16_SFloat_Pack16,
|
||||
TextureFormat.R32_UInt => GliApi.Gli.Format.R32_UInt_Pack32,
|
||||
TextureFormat.R32_SInt => GliApi.Gli.Format.R32_SInt_Pack32,
|
||||
TextureFormat.R32_SFloat => GliApi.Gli.Format.R32_SFloat_Pack32,
|
||||
TextureFormat.R32G32_UInt => GliApi.Gli.Format.RG32_UInt_Pack32,
|
||||
TextureFormat.R32G32_SInt => GliApi.Gli.Format.RG32_SInt_Pack32,
|
||||
TextureFormat.R32G32_SFloat => GliApi.Gli.Format.RG32_SFloat_Pack32,
|
||||
TextureFormat.R32G32B32_UInt => GliApi.Gli.Format.RGB32_UInt_Pack32,
|
||||
TextureFormat.R32G32B32_SInt => GliApi.Gli.Format.RGB32_SInt_Pack32,
|
||||
TextureFormat.R32G32B32_SFloat => GliApi.Gli.Format.RGB32_SFloat_Pack32,
|
||||
TextureFormat.R32G32B32A32_UInt => GliApi.Gli.Format.RGBA32_UInt_Pack32,
|
||||
TextureFormat.R32G32B32A32_SInt => GliApi.Gli.Format.RGBA32_SInt_Pack32,
|
||||
TextureFormat.R32G32B32A32_SFloat => GliApi.Gli.Format.RGBA32_SFloat_Pack32,
|
||||
TextureFormat.R64_UInt => GliApi.Gli.Format.R64_UInt_Pack64,
|
||||
TextureFormat.R64_SInt => GliApi.Gli.Format.R64_SInt_Pack64,
|
||||
TextureFormat.R64_SFloat => GliApi.Gli.Format.R64_SFloat_Pack64,
|
||||
TextureFormat.R64G64_UInt => GliApi.Gli.Format.RG64_UInt_Pack64,
|
||||
TextureFormat.R64G64_SInt => GliApi.Gli.Format.RG64_SInt_Pack64,
|
||||
TextureFormat.R64G64_SFloat => GliApi.Gli.Format.RG64_SFloat_Pack64,
|
||||
TextureFormat.R64G64B64_UInt => GliApi.Gli.Format.RGB64_UInt_Pack64,
|
||||
TextureFormat.R64G64B64_SInt => GliApi.Gli.Format.RGB64_SInt_Pack64,
|
||||
TextureFormat.R64G64B64_SFloat => GliApi.Gli.Format.RGB64_SFloat_Pack64,
|
||||
TextureFormat.R64G64B64A64_UInt => GliApi.Gli.Format.RGBA64_UInt_Pack64,
|
||||
TextureFormat.R64G64B64A64_SInt => GliApi.Gli.Format.RGBA64_SInt_Pack64,
|
||||
TextureFormat.R64G64B64A64_SFloat => GliApi.Gli.Format.RGBA64_SFloat_Pack64,
|
||||
TextureFormat.B10G11R11_UFloat_Pack32 => GliApi.Gli.Format.RG11B10_UFloat_Pack32,
|
||||
TextureFormat.E5B9G9R9_UFloat_Pack32 => GliApi.Gli.Format.RGB9E5_UFloat_Pack32,
|
||||
TextureFormat.D16_UNorm => GliApi.Gli.Format.D16_UNorm_Pack16,
|
||||
TextureFormat.X8D24_UNorm_Pack32 => GliApi.Gli.Format.D24_UNorm_Pack32,
|
||||
TextureFormat.D32_SFloat => GliApi.Gli.Format.D32_SFloat_Pack32,
|
||||
TextureFormat.S8_UInt => GliApi.Gli.Format.S8_UInt_Pack8,
|
||||
TextureFormat.D16_UNormS8_UInt => GliApi.Gli.Format.D16_UNorm_S8_UInt_Pack32,
|
||||
TextureFormat.D24_UNormS8_UInt => GliApi.Gli.Format.D24_UNorm_S8_UInt_Pack32,
|
||||
TextureFormat.D32_SFloatS8_UInt => GliApi.Gli.Format.D32_SFloat_S8_UInt_Pack64,
|
||||
TextureFormat.BC1Rgb_UNorm_Block => GliApi.Gli.Format.RGB_DXT1_UNorm_Block8,
|
||||
TextureFormat.BC1Rgb_SRGB_Block => GliApi.Gli.Format.RGB_DXT1_SRGB_Block8,
|
||||
TextureFormat.BC1Rgba_UNorm_Block => GliApi.Gli.Format.RGBA_DXT1_UNorm_Block8,
|
||||
TextureFormat.BC1Rgba_SRGB_Block => GliApi.Gli.Format.RGBA_DXT1_SRGB_Block8,
|
||||
TextureFormat.BC2_UNorm_Block => GliApi.Gli.Format.RGBA_DXT3_UNorm_Block16,
|
||||
TextureFormat.BC2_SRGB_Block => GliApi.Gli.Format.RGBA_DXT3_SRGB_Block16,
|
||||
TextureFormat.BC3_UNorm_Block => GliApi.Gli.Format.RGBA_DXT5_UNorm_Block16,
|
||||
TextureFormat.BC3_SRGB_Block => GliApi.Gli.Format.RGBA_DXT5_SRGB_Block16,
|
||||
TextureFormat.BC4_UNorm_Block => GliApi.Gli.Format.R_ATI1N_UNorm_Block8,
|
||||
TextureFormat.BC4_SNorm_Block => GliApi.Gli.Format.R_ATI1N_SNorm_Block8,
|
||||
TextureFormat.BC5_UNorm_Block => GliApi.Gli.Format.RG_ATI2N_UNorm_Block16,
|
||||
TextureFormat.BC5_SNorm_Block => GliApi.Gli.Format.RG_ATI2N_SNorm_Block16,
|
||||
TextureFormat.ETC2R8G8B8_UNorm_Block => GliApi.Gli.Format.RGB_ETC2_UNorm_Block8,
|
||||
TextureFormat.ETC2R8G8B8_SRGB_Block => GliApi.Gli.Format.RGB_ETC2_SRGB_Block8,
|
||||
TextureFormat.ETC2R8G8B8A8_UNorm_Block => GliApi.Gli.Format.RGBA_ETC2_UNorm_Block16,
|
||||
TextureFormat.ETC2R8G8B8A8_SRGB_Block => GliApi.Gli.Format.RGBA_ETC2_SRGB_Block16,
|
||||
TextureFormat.EACR11_UNorm_Block => GliApi.Gli.Format.R_EAC_UNorm_Block8,
|
||||
TextureFormat.EACR11_SNorm_Block => GliApi.Gli.Format.R_EAC_SNorm_Block8,
|
||||
TextureFormat.EACR11G11_UNorm_Block => GliApi.Gli.Format.RG_EAC_UNorm_Block16,
|
||||
TextureFormat.EACR11G11_SNorm_Block => GliApi.Gli.Format.RG_EAC_SNorm_Block16,
|
||||
TextureFormat.ASTC4X4_UNorm_Block => GliApi.Gli.Format.RGBA_ASTC_4X4_UNorm_Block16,
|
||||
TextureFormat.ASTC4X4_SRGB_Block => GliApi.Gli.Format.RGBA_ASTC_4X4_SRGB_Block16,
|
||||
TextureFormat.ASTC5X4_UNorm_Block => GliApi.Gli.Format.RGBA_ASTC_5X4_UNorm_Block16,
|
||||
TextureFormat.ASTC5X4_SRGB_Block => GliApi.Gli.Format.RGBA_ASTC_5X4_SRGB_Block16,
|
||||
TextureFormat.ASTC5X5_UNorm_Block => GliApi.Gli.Format.RGBA_ASTC_5X5_UNorm_Block16,
|
||||
TextureFormat.ASTC5X5_SRGB_Block => GliApi.Gli.Format.RGBA_ASTC_5X5_SRGB_Block16,
|
||||
TextureFormat.ASTC6X5_UNorm_Block => GliApi.Gli.Format.RGBA_ASTC_6X5_UNorm_Block16,
|
||||
TextureFormat.ASTC6X5_SRGB_Block => GliApi.Gli.Format.RGBA_ASTC_6X5_SRGB_Block16,
|
||||
TextureFormat.ASTC6X6_UNorm_Block => GliApi.Gli.Format.RGBA_ASTC_6X6_UNorm_Block16,
|
||||
TextureFormat.ASTC6X6_SRGB_Block => GliApi.Gli.Format.RGBA_ASTC_6X6_SRGB_Block16,
|
||||
TextureFormat.ASTC8X5_UNorm_Block => GliApi.Gli.Format.RGBA_ASTC_8X5_UNorm_Block16,
|
||||
TextureFormat.ASTC8X5_SRGB_Block => GliApi.Gli.Format.RGBA_ASTC_8X5_SRGB_Block16,
|
||||
TextureFormat.ASTC8X6_UNorm_Block => GliApi.Gli.Format.RGBA_ASTC_8X6_UNorm_Block16,
|
||||
TextureFormat.ASTC8X6_SRGB_Block => GliApi.Gli.Format.RGBA_ASTC_8X6_SRGB_Block16,
|
||||
TextureFormat.ASTC8X8_UNorm_Block => GliApi.Gli.Format.RGBA_ASTC_8X8_UNorm_Block16,
|
||||
TextureFormat.ASTC8X8_SRGB_Block => GliApi.Gli.Format.RGBA_ASTC_8X8_SRGB_Block16,
|
||||
TextureFormat.ASTC10X5_UNorm_Block => GliApi.Gli.Format.RGBA_ASTC_10X5_UNorm_Block16,
|
||||
TextureFormat.ASTC10X5_SRGB_Block => GliApi.Gli.Format.RGBA_ASTC_10X5_SRGB_Block16,
|
||||
TextureFormat.ASTC10X6_UNorm_Block => GliApi.Gli.Format.RGBA_ASTC_10X6_UNorm_Block16,
|
||||
TextureFormat.ASTC10X6_SRGB_Block => GliApi.Gli.Format.RGBA_ASTC_10X6_SRGB_Block16,
|
||||
TextureFormat.ASTC10X8_UNorm_Block => GliApi.Gli.Format.RGBA_ASTC_10X8_UNorm_Block16,
|
||||
TextureFormat.ASTC10X8_SRGB_Block => GliApi.Gli.Format.RGBA_ASTC_10X8_SRGB_Block16,
|
||||
TextureFormat.ASTC10X10_UNorm_Block => GliApi.Gli.Format.RGBA_ASTC_10X10_UNorm_Block16,
|
||||
TextureFormat.ASTC10X10_SRGB_Block => GliApi.Gli.Format.RGBA_ASTC_10X10_SRGB_Block16,
|
||||
TextureFormat.ASTC12X10_UNorm_Block => GliApi.Gli.Format.RGBA_ASTC_12X10_UNorm_Block16,
|
||||
TextureFormat.ASTC12X10_SRGB_Block => GliApi.Gli.Format.RGBA_ASTC_12X10_SRGB_Block16,
|
||||
TextureFormat.ASTC12X12_UNorm_Block => GliApi.Gli.Format.RGBA_ASTC_12X12_UNorm_Block16,
|
||||
TextureFormat.ASTC12X12_SRGB_Block => GliApi.Gli.Format.RGBA_ASTC_12X12_SRGB_Block16,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(format), format, null),
|
||||
};
|
||||
}
|
||||
}
|
||||
42
brutal.texture/Brutal.Texture/Gli/GliTexture.cs
Normal file
42
brutal.texture/Brutal.Texture/Gli/GliTexture.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using Brutal.GliApi;
|
||||
|
||||
namespace Brutal.TextureApi.Gli;
|
||||
|
||||
public class GliTexture(Brutal.GliApi.Gli.Texture nativeTexture) : ITexture
|
||||
{
|
||||
public unsafe Span<byte> ImageData(int level, int layer, int faceOrSlice)
|
||||
{
|
||||
var sliceSize = _impl.ImageSize(level) / Extent.Z;
|
||||
|
||||
if (_impl.Target == Brutal.GliApi.Gli.Target._3D)
|
||||
return new(_impl.ImageData(level, layer, 0) + sliceSize * faceOrSlice, (int)sliceSize);
|
||||
|
||||
return new(_impl.ImageData(level, layer, faceOrSlice), (int)sliceSize);
|
||||
}
|
||||
|
||||
public unsafe Span<byte> Data => new(_impl.Data, (int)_impl.Size);
|
||||
public TexelCount3 Extent => new(_impl.Extent.X, _impl.Extent.Y, _impl.Extent.Z);
|
||||
public TextureFormat Format => _impl.Format.ToTextureFormat();
|
||||
public int LayerCount => (int)_impl.Layers;
|
||||
public int LevelCount => (int)_impl.Levels;
|
||||
public int FaceCount => (int)_impl.Faces;
|
||||
public bool IsCubemap => _impl.Target.IsCube();
|
||||
public bool IsArray => _impl.Target.IsArray();
|
||||
public int DimensionCount => _impl.Target.DimensionCount();
|
||||
|
||||
public ByteSize RowPitch(int level)
|
||||
{
|
||||
if (level < 0 || level >= LevelCount)
|
||||
throw new ArgumentOutOfRangeException(nameof(level), level, $"Level must be in range [0, {LevelCount})");
|
||||
return ByteSize.Of(_impl.ImageRowPitch(level));
|
||||
}
|
||||
|
||||
public static implicit operator Brutal.GliApi.Gli.Texture(GliTexture texture) => texture._impl;
|
||||
|
||||
private readonly GliApi.Gli.Texture _impl = nativeTexture;
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
_impl.Dispose();
|
||||
}
|
||||
}
|
||||
9
brutal.texture/Brutal.Texture/Gli/GliTextureException.cs
Normal file
9
brutal.texture/Brutal.Texture/Gli/GliTextureException.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using Brutal.TextureApi;
|
||||
|
||||
namespace Brutal.TextureApi.Gli;
|
||||
|
||||
public class GliTextureException : TextureException
|
||||
{
|
||||
public GliTextureException(string message)
|
||||
: base(message) { }
|
||||
}
|
||||
36
brutal.texture/Brutal.Texture/Gli/GliTextureLoader.cs
Normal file
36
brutal.texture/Brutal.Texture/Gli/GliTextureLoader.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using System.Collections.Frozen;
|
||||
using Brutal.Pointers.Extensions;
|
||||
|
||||
namespace Brutal.TextureApi.Gli;
|
||||
|
||||
public static partial class Loader
|
||||
{
|
||||
public static GliTexture LoadFromFile(string filePath)
|
||||
{
|
||||
var nativeTexture = new GliApi.Gli.Texture(filePath);
|
||||
|
||||
if (nativeTexture.IsNull())
|
||||
{
|
||||
nativeTexture.Dispose();
|
||||
throw new GliTextureException($"Failed to load texture from filePath \"{filePath}\"");
|
||||
}
|
||||
|
||||
return new GliTexture(nativeTexture);
|
||||
}
|
||||
|
||||
public static unsafe GliTexture LoadFromMemory(ReadOnlySpan<byte> data)
|
||||
{
|
||||
var nativeTexture = new GliApi.Gli.Texture(data);
|
||||
|
||||
if (nativeTexture.IsNull())
|
||||
{
|
||||
nativeTexture.Dispose();
|
||||
throw new GliTextureException($"Failed to load texture from data at 0x{(nint)data.AsPointer()}");
|
||||
}
|
||||
|
||||
return new GliTexture(nativeTexture);
|
||||
}
|
||||
|
||||
public static FrozenSet<string> SupportedExtensions { get; } =
|
||||
FrozenSet.Create(StringComparer.OrdinalIgnoreCase, [".dds", ".ktx", ".kmg"]);
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
namespace Brutal.TextureApi.Gli;
|
||||
|
||||
public class GliTextureSaveException(string message) : GliTextureException(message);
|
||||
59
brutal.texture/Brutal.Texture/Gli/GliTextureWriter.cs
Normal file
59
brutal.texture/Brutal.Texture/Gli/GliTextureWriter.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
namespace Brutal.TextureApi.Gli;
|
||||
|
||||
public static partial class Writer
|
||||
{
|
||||
public static void SaveToFile(ITexture texture, string filePath)
|
||||
{
|
||||
if (texture is GliTexture gliTexture)
|
||||
{
|
||||
SaveToFileImpl(gliTexture, filePath);
|
||||
return;
|
||||
}
|
||||
|
||||
SaveToFile(
|
||||
new TextureDescriptor
|
||||
{
|
||||
Data = texture.Data,
|
||||
Extent = texture.Extent,
|
||||
Format = texture.Format,
|
||||
LayerCount = texture.LayerCount,
|
||||
FaceCount = texture.FaceCount,
|
||||
MipmapCount = texture.LevelCount,
|
||||
IsCubemap = texture.IsCubemap,
|
||||
},
|
||||
filePath
|
||||
);
|
||||
}
|
||||
|
||||
public static void SaveToFile(TextureDescriptor descriptor, string filePath)
|
||||
{
|
||||
var gliTarget = GliConversionUtils.GetTarget(descriptor.Extent, descriptor.LayerCount, descriptor.IsCubemap);
|
||||
|
||||
using var gliNative = new GliApi.Gli.Texture(
|
||||
gliTarget,
|
||||
descriptor.Format.ToGliFormat(),
|
||||
new(descriptor.Extent.X, descriptor.Extent.Y, descriptor.Extent.Z),
|
||||
descriptor.LayerCount,
|
||||
descriptor.FaceCount,
|
||||
descriptor.MipmapCount,
|
||||
GliApi.Gli.Swizzles.Identity
|
||||
);
|
||||
|
||||
unsafe
|
||||
{
|
||||
descriptor.Data.CopyTo(new Span<byte>(gliNative.Data, descriptor.Data.Length));
|
||||
}
|
||||
|
||||
SaveToFileImpl(gliNative, filePath);
|
||||
}
|
||||
|
||||
private static void SaveToFileImpl(GliApi.Gli.Texture texture, string filePath)
|
||||
{
|
||||
var result = texture.Save(filePath);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
throw new GliTextureSaveException($"Failed to save texture to file at path: \"{filePath}\".");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue