Some small gpu improvements and shader improvements, add support for ASTC 4x4 textures (slow!)

This commit is contained in:
gdkchan 2018-06-02 00:50:56 -03:00
parent aeb1bbf50c
commit 53a6922f87
11 changed files with 332 additions and 100 deletions

View file

@ -1,4 +1,6 @@
using OpenTK.Graphics.OpenGL;
using Ryujinx.Graphics.Gal.Texture;
using System;
namespace Ryujinx.Graphics.Gal.OpenGL
{
@ -36,6 +38,11 @@ namespace Ryujinx.Graphics.Gal.OpenGL
}
else
{
if (Texture.Format >= GalTextureFormat.Astc2D4x4)
{
ConvertAstcTextureToRgba(Texture);
}
const PixelInternalFormat InternalFmt = PixelInternalFormat.Rgba;
(PixelFormat Format, PixelType Type) = OGLEnumConverter.GetTextureFormat(Texture.Format);
@ -63,6 +70,62 @@ namespace Ryujinx.Graphics.Gal.OpenGL
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleA, SwizzleA);
}
private void ConvertAstcTextureToRgba(GalTexture Texture)
{
Texture.Data = ASTCDecoder.DecodeToRGBA8888(
Texture.Data,
GetAstcBlockWidth(Texture.Format),
GetAstcBlockHeight(Texture.Format), 1,
Texture.Width,
Texture.Height, 1);
}
private int GetAstcBlockWidth(GalTextureFormat Format)
{
switch (Format)
{
case GalTextureFormat.Astc2D4x4: return 4;
case GalTextureFormat.Astc2D5x5: return 5;
case GalTextureFormat.Astc2D6x6: return 6;
case GalTextureFormat.Astc2D8x8: return 8;
case GalTextureFormat.Astc2D10x10: return 10;
case GalTextureFormat.Astc2D12x12: return 12;
case GalTextureFormat.Astc2D5x4: return 5;
case GalTextureFormat.Astc2D6x5: return 6;
case GalTextureFormat.Astc2D8x6: return 8;
case GalTextureFormat.Astc2D10x8: return 10;
case GalTextureFormat.Astc2D12x10: return 12;
case GalTextureFormat.Astc2D8x5: return 8;
case GalTextureFormat.Astc2D10x5: return 10;
case GalTextureFormat.Astc2D10x6: return 10;
}
throw new ArgumentException(nameof(Format));
}
private int GetAstcBlockHeight(GalTextureFormat Format)
{
switch (Format)
{
case GalTextureFormat.Astc2D4x4: return 4;
case GalTextureFormat.Astc2D5x5: return 5;
case GalTextureFormat.Astc2D6x6: return 6;
case GalTextureFormat.Astc2D8x8: return 8;
case GalTextureFormat.Astc2D10x10: return 10;
case GalTextureFormat.Astc2D12x12: return 12;
case GalTextureFormat.Astc2D5x4: return 4;
case GalTextureFormat.Astc2D6x5: return 5;
case GalTextureFormat.Astc2D8x6: return 6;
case GalTextureFormat.Astc2D10x8: return 8;
case GalTextureFormat.Astc2D12x10: return 10;
case GalTextureFormat.Astc2D8x5: return 5;
case GalTextureFormat.Astc2D10x5: return 5;
case GalTextureFormat.Astc2D10x6: return 6;
}
throw new ArgumentException(nameof(Format));
}
public void Bind(int Index)
{
int Handle = EnsureTextureInitialized(Index);