diff options
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); } } |
