aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2018-09-18 01:30:35 -0300
committerGitHub <noreply@github.com>2018-09-18 01:30:35 -0300
commitd4187aaa9d7194aa26d04aee838edbc3a38f1862 (patch)
tree06fe725c1067b4aeca21749799b835d85e7d2787 /Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs
parentbec95cacc1061f91373a1e3a1411981af7fe2e4e (diff)
Allow "reinterpretation" of framebuffer/zeta formats (#418)
* (Re)Implement format reinterpretation, other changes * Implement writeback to guest memory, some refactoring * More refactoring, implement reinterpretation the old way again * Clean up * Some fixes on M2MF (old Dma engine), added partial support for P2MF, fix conditional ssy, add Z24S8 zeta format, other fixes * nit: Formatting * Address PR feedback
Diffstat (limited to 'Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs')
-rw-r--r--Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs161
1 files changed, 75 insertions, 86 deletions
diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs
index 7e1c0e53..3347afbd 100644
--- a/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs
+++ b/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs
@@ -28,17 +28,65 @@ namespace Ryujinx.Graphics.Gal.OpenGL
GL.DeleteTexture(CachedImage.Handle);
}
- public void Create(long Key, byte[] Data, GalImage Image)
+ public void Create(long Key, int Size, GalImage Image)
{
int Handle = GL.GenTexture();
- TextureCache.AddOrUpdate(Key, new ImageHandler(Handle, Image), (uint)Data.Length);
+ GL.BindTexture(TextureTarget.Texture2D, Handle);
+
+ const int Level = 0; //TODO: Support mipmap textures.
+ const int Border = 0;
+
+ TextureCache.AddOrUpdate(Key, new ImageHandler(Handle, Image), (uint)Size);
+
+ GalImageFormat TypeLess = Image.Format & GalImageFormat.FormatMask;
+
+ bool IsASTC = TypeLess >= GalImageFormat.ASTC_BEGIN && TypeLess <= GalImageFormat.ASTC_END;
+
+ if (ImageUtils.IsCompressed(Image.Format) && !IsASTC)
+ {
+ InternalFormat InternalFmt = OGLEnumConverter.GetCompressedImageFormat(Image.Format);
+
+ GL.CompressedTexImage2D(
+ TextureTarget.Texture2D,
+ Level,
+ InternalFmt,
+ Image.Width,
+ Image.Height,
+ Border,
+ Size,
+ IntPtr.Zero);
+ }
+ else
+ {
+ (PixelInternalFormat InternalFmt,
+ PixelFormat Format,
+ PixelType Type) = OGLEnumConverter.GetImageFormat(Image.Format);
+
+ GL.TexImage2D(
+ TextureTarget.Texture2D,
+ Level,
+ InternalFmt,
+ Image.Width,
+ Image.Height,
+ Border,
+ Format,
+ Type,
+ IntPtr.Zero);
+ }
+ }
+
+ public void Create(long Key, byte[] Data, GalImage Image)
+ {
+ int Handle = GL.GenTexture();
GL.BindTexture(TextureTarget.Texture2D, Handle);
const int Level = 0; //TODO: Support mipmap textures.
const int Border = 0;
+ TextureCache.AddOrUpdate(Key, new ImageHandler(Handle, Image), (uint)Data.Length);
+
GalImageFormat TypeLess = Image.Format & GalImageFormat.FormatMask;
bool IsASTC = TypeLess >= GalImageFormat.ASTC_BEGIN && TypeLess <= GalImageFormat.ASTC_END;
@@ -62,8 +110,8 @@ namespace Ryujinx.Graphics.Gal.OpenGL
//TODO: Use KHR_texture_compression_astc_hdr when available
if (IsASTC)
{
- int TextureBlockWidth = GetAstcBlockWidth(Image.Format);
- int TextureBlockHeight = GetAstcBlockHeight(Image.Format);
+ int TextureBlockWidth = ImageUtils.GetBlockWidth(Image.Format);
+ int TextureBlockHeight = ImageUtils.GetBlockHeight(Image.Format);
Data = ASTCDecoder.DecodeToRGBA8888(
Data,
@@ -85,12 +133,14 @@ namespace Ryujinx.Graphics.Gal.OpenGL
Image.Format = GalImageFormat.R8G8 | (Image.Format & GalImageFormat.TypeMask);
}
- (PixelInternalFormat InternalFormat, PixelFormat Format, PixelType Type) = OGLEnumConverter.GetImageFormat(Image.Format);
+ (PixelInternalFormat InternalFmt,
+ PixelFormat Format,
+ PixelType Type) = OGLEnumConverter.GetImageFormat(Image.Format);
GL.TexImage2D(
TextureTarget.Texture2D,
Level,
- InternalFormat,
+ InternalFmt,
Image.Width,
Image.Height,
Border,
@@ -98,112 +148,51 @@ namespace Ryujinx.Graphics.Gal.OpenGL
Type,
Data);
}
-
- int SwizzleR = (int)OGLEnumConverter.GetTextureSwizzle(Image.XSource);
- int SwizzleG = (int)OGLEnumConverter.GetTextureSwizzle(Image.YSource);
- int SwizzleB = (int)OGLEnumConverter.GetTextureSwizzle(Image.ZSource);
- int SwizzleA = (int)OGLEnumConverter.GetTextureSwizzle(Image.WSource);
-
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleR, SwizzleR);
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleG, SwizzleG);
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleB, SwizzleB);
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleA, SwizzleA);
}
- public void CreateFb(long Key, long Size, GalImage Image)
+ public bool TryGetImage(long Key, out GalImage Image)
{
- if (!TryGetImage(Key, out ImageHandler CachedImage))
+ if (TextureCache.TryGetValue(Key, out ImageHandler CachedImage))
{
- CachedImage = new ImageHandler();
-
- TextureCache.AddOrUpdate(Key, CachedImage, Size);
- }
+ Image = CachedImage.Image;
- CachedImage.EnsureSetup(Image);
- }
-
- public bool TryGetImage(long Key, out ImageHandler CachedImage)
- {
- if (TextureCache.TryGetValue(Key, out CachedImage))
- {
return true;
}
- CachedImage = null;
+ Image = default(GalImage);
return false;
}
- private static int GetAstcBlockWidth(GalImageFormat Format)
+ public bool TryGetImageHandler(long Key, out ImageHandler CachedImage)
{
- switch (Format)
- {
- case GalImageFormat.ASTC_4x4 | GalImageFormat.Unorm: return 4;
- case GalImageFormat.ASTC_5x5 | GalImageFormat.Unorm: return 5;
- case GalImageFormat.ASTC_6x6 | GalImageFormat.Unorm: return 6;
- case GalImageFormat.ASTC_8x8 | GalImageFormat.Unorm: return 8;
- case GalImageFormat.ASTC_10x10 | GalImageFormat.Unorm: return 10;
- case GalImageFormat.ASTC_12x12 | GalImageFormat.Unorm: return 12;
- case GalImageFormat.ASTC_5x4 | GalImageFormat.Unorm: return 5;
- case GalImageFormat.ASTC_6x5 | GalImageFormat.Unorm: return 6;
- case GalImageFormat.ASTC_8x6 | GalImageFormat.Unorm: return 8;
- case GalImageFormat.ASTC_10x8 | GalImageFormat.Unorm: return 10;
- case GalImageFormat.ASTC_12x10 | GalImageFormat.Unorm: return 12;
- case GalImageFormat.ASTC_8x5 | GalImageFormat.Unorm: return 8;
- case GalImageFormat.ASTC_10x5 | GalImageFormat.Unorm: return 10;
- case GalImageFormat.ASTC_10x6 | GalImageFormat.Unorm: return 10;
- }
-
- throw new ArgumentException(nameof(Format));
- }
-
- private static int GetAstcBlockHeight(GalImageFormat Format)
- {
- switch (Format)
- {
- case GalImageFormat.ASTC_4x4 | GalImageFormat.Unorm: return 4;
- case GalImageFormat.ASTC_5x5 | GalImageFormat.Unorm: return 5;
- case GalImageFormat.ASTC_6x6 | GalImageFormat.Unorm: return 6;
- case GalImageFormat.ASTC_8x8 | GalImageFormat.Unorm: return 8;
- case GalImageFormat.ASTC_10x10 | GalImageFormat.Unorm: return 10;
- case GalImageFormat.ASTC_12x12 | GalImageFormat.Unorm: return 12;
- case GalImageFormat.ASTC_5x4 | GalImageFormat.Unorm: return 4;
- case GalImageFormat.ASTC_6x5 | GalImageFormat.Unorm: return 5;
- case GalImageFormat.ASTC_8x6 | GalImageFormat.Unorm: return 6;
- case GalImageFormat.ASTC_10x8 | GalImageFormat.Unorm: return 8;
- case GalImageFormat.ASTC_12x10 | GalImageFormat.Unorm: return 10;
- case GalImageFormat.ASTC_8x5 | GalImageFormat.Unorm: return 5;
- case GalImageFormat.ASTC_10x5 | GalImageFormat.Unorm: return 5;
- case GalImageFormat.ASTC_10x6 | GalImageFormat.Unorm: return 6;
- }
-
- throw new ArgumentException(nameof(Format));
- }
-
- public bool TryGetCachedTexture(long Key, long DataSize, out GalImage Image)
- {
- if (TextureCache.TryGetSize(Key, out long Size) && Size == DataSize)
+ if (TextureCache.TryGetValue(Key, out CachedImage))
{
- if (TextureCache.TryGetValue(Key, out ImageHandler CachedImage))
- {
- Image = CachedImage.Image;
-
- return true;
- }
+ return true;
}
- Image = default(GalImage);
+ CachedImage = null;
return false;
}
- public void Bind(long Key, int Index)
+ public void Bind(long Key, int Index, GalImage Image)
{
if (TextureCache.TryGetValue(Key, out ImageHandler CachedImage))
{
GL.ActiveTexture(TextureUnit.Texture0 + Index);
GL.BindTexture(TextureTarget.Texture2D, CachedImage.Handle);
+
+ int[] SwizzleRgba = new int[]
+ {
+ (int)OGLEnumConverter.GetTextureSwizzle(Image.XSource),
+ (int)OGLEnumConverter.GetTextureSwizzle(Image.YSource),
+ (int)OGLEnumConverter.GetTextureSwizzle(Image.ZSource),
+ (int)OGLEnumConverter.GetTextureSwizzle(Image.WSource)
+ };
+
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleRgba, SwizzleRgba);
}
}