using AcDream.App.Rendering.Gpu; using AcDream.App.Rendering.Gpu.Gl; using Silk.NET.OpenGL; namespace AcDream.App.Tests.Rendering.Gpu.Gl; public sealed class GlGpuTextureFormatMappingTests { [Fact] public void Rgba8AndItsRenderTargetVariantShareTheSameGlShape() { GlTextureFormatInfo plain = GlGpuTextureFormatMapping.Resolve(GpuTextureFormat.Rgba8Unorm); GlTextureFormatInfo target = GlGpuTextureFormatMapping.Resolve(GpuTextureFormat.Rgba8UnormRenderTarget); Assert.Equal(plain, target); Assert.Equal(SizedInternalFormat.Rgba8, plain.SizedInternalFormat); Assert.Equal(PixelFormat.Rgba, plain.UploadPixelFormat); Assert.Equal(PixelType.UnsignedByte, plain.UploadPixelType); Assert.False(plain.IsCompressed); Assert.Equal(4, plain.LayerByteCount(1, 1)); Assert.Equal(4 * 16 * 16, plain.LayerByteCount(16, 16)); } [Fact] public void R8IsOneByteUncompressed() { GlTextureFormatInfo info = GlGpuTextureFormatMapping.Resolve(GpuTextureFormat.R8Unorm); Assert.Equal(SizedInternalFormat.R8, info.SizedInternalFormat); Assert.False(info.IsCompressed); Assert.Equal(1, info.LayerByteCount(1, 1)); Assert.Equal(64, info.LayerByteCount(8, 8)); } [Fact] public void Bc1IsCompressedFourByFourEightByteBlocks() => AssertBcFormat(GpuTextureFormat.Bc1Unorm, expectedBlockBytes: 8); [Fact] public void Bc2IsCompressedFourByFourSixteenByteBlocks() => AssertBcFormat(GpuTextureFormat.Bc2Unorm, expectedBlockBytes: 16); [Fact] public void Bc3IsCompressedFourByFourSixteenByteBlocks() => AssertBcFormat(GpuTextureFormat.Bc3Unorm, expectedBlockBytes: 16); private static void AssertBcFormat(GpuTextureFormat format, int expectedBlockBytes) { GlTextureFormatInfo info = GlGpuTextureFormatMapping.Resolve(format); Assert.True(info.IsCompressed); Assert.Equal(4, info.BlockDimension); Assert.Equal(expectedBlockBytes, info.BlockOrTexelBytes); // A single 4x4 block for a 4x4 texture. Assert.Equal(expectedBlockBytes, info.LayerByteCount(4, 4)); // Partial blocks round up: a 5x5 texture needs a 2x2 block grid. Assert.Equal(expectedBlockBytes * 4, info.LayerByteCount(5, 5)); } [Fact] public void Depth24Stencil8IsAttachmentShapedNotCompressed() { GlTextureFormatInfo info = GlGpuTextureFormatMapping.Resolve(GpuTextureFormat.Depth24Stencil8); Assert.Equal(SizedInternalFormat.Depth24Stencil8, info.SizedInternalFormat); Assert.Equal(PixelFormat.DepthStencil, info.UploadPixelFormat); Assert.Equal(PixelType.UnsignedInt248, info.UploadPixelType); Assert.False(info.IsCompressed); } [Fact] public void EveryGpuTextureFormatValueResolvesWithoutThrowing() { foreach (GpuTextureFormat format in Enum.GetValues()) GlGpuTextureFormatMapping.Resolve(format); } }