diff options
author | gdkchan <gab.dark.100@gmail.com> | 2019-12-05 17:34:47 -0300 |
---|---|---|
committer | Thog <thog@protonmail.com> | 2020-01-09 02:13:00 +0100 |
commit | e25b7c9848b6ec486eb513297b5c536857665c7f (patch) | |
tree | c1ccb6c58bed0f7ece835359516330104feb8f4d /Ryujinx.Graphics.OpenGL/TextureView.cs | |
parent | 6a98c643cabeea25dc42e19fe475a687a034a532 (diff) |
Initial support for the guest OpenGL driver (NVIDIA and Nouveau)
Diffstat (limited to 'Ryujinx.Graphics.OpenGL/TextureView.cs')
-rw-r--r-- | Ryujinx.Graphics.OpenGL/TextureView.cs | 63 |
1 files changed, 47 insertions, 16 deletions
diff --git a/Ryujinx.Graphics.OpenGL/TextureView.cs b/Ryujinx.Graphics.OpenGL/TextureView.cs index 8fced290..769f0339 100644 --- a/Ryujinx.Graphics.OpenGL/TextureView.cs +++ b/Ryujinx.Graphics.OpenGL/TextureView.cs @@ -165,7 +165,29 @@ namespace Ryujinx.Graphics.OpenGL _renderer.TextureCopy.Copy(this, (TextureView)destination, srcRegion, dstRegion, linearFilter); } - public byte[] GetData(int face) + public byte[] GetData() + { + int size = 0; + + for (int level = 0; level < _info.Levels; level++) + { + size += _info.GetMipSize(level); + } + + byte[] data = new byte[size]; + + unsafe + { + fixed (byte* ptr = data) + { + WriteTo((IntPtr)ptr); + } + } + + return data; + } + + private void WriteTo(IntPtr ptr) { TextureTarget target = Target.Convert(); @@ -173,28 +195,37 @@ namespace Ryujinx.Graphics.OpenGL FormatInfo format = FormatTable.GetFormatInfo(_info.Format); - int depth = _info.GetDepthOrLayers(); + int faces = 1; if (target == TextureTarget.TextureCubeMap) { - target = TextureTarget.TextureCubeMapPositiveX + face; - } - - if (format.IsCompressed) - { - byte[] data = new byte[_info.Width * _info.Height * depth * 4]; - - GL.GetTexImage(target, 0, PixelFormat.Rgba, PixelType.UnsignedByte, data); + target = TextureTarget.TextureCubeMapPositiveX; - return data; + faces = 6; } - else - { - byte[] data = new byte[_info.GetMipSize(0)]; - GL.GetTexImage(target, 0, format.PixelFormat, format.PixelType, data); + for (int level = 0; level < _info.Levels; level++) + { + for (int face = 0; face < faces; face++) + { + int faceOffset = face * _info.GetMipSize2D(level); + + if (format.IsCompressed) + { + GL.GetCompressedTexImage(target + face, level, ptr + faceOffset); + } + else + { + GL.GetTexImage( + target + face, + level, + format.PixelFormat, + format.PixelType, + ptr + faceOffset); + } + } - return data; + ptr += _info.GetMipSize(level); } } |