diff options
| author | ReinUsesLisp <reinuseslisp@airmail.cc> | 2018-09-19 18:26:49 -0300 |
|---|---|---|
| committer | gdkchan <gab.dark.100@gmail.com> | 2018-09-19 18:26:49 -0300 |
| commit | bed13f2022e3b81d694e51e1c29ee66f4a18f5f9 (patch) | |
| tree | d9b6782550f8a5e23229d271246656e7584af813 /Ryujinx.Graphics/Gal/OpenGL/OGLRenderTarget.cs | |
| parent | e04221b293370dac53e4e874cddd4f9a2a64b52f (diff) | |
General improvements for GpuResourceManager (#421)
* General improvements to GpuResourceManager
* Address feedback
* Address feedback
Diffstat (limited to 'Ryujinx.Graphics/Gal/OpenGL/OGLRenderTarget.cs')
| -rw-r--r-- | Ryujinx.Graphics/Gal/OpenGL/OGLRenderTarget.cs | 42 |
1 files changed, 16 insertions, 26 deletions
diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLRenderTarget.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLRenderTarget.cs index 7dde32d8..ff5dc1b8 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLRenderTarget.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLRenderTarget.cs @@ -56,6 +56,8 @@ namespace Ryujinx.Graphics.Gal.OpenGL private int DepthAttachment; private int StencilAttachment; + private int CopyPBO; + public OGLRenderTarget(OGLTexture Texture) { ColorAttachments = new int[8]; @@ -358,45 +360,33 @@ namespace Ryujinx.Graphics.Gal.OpenGL return; } - byte[] Data = GetData(Key); - - GL.PixelStore(PixelStoreParameter.UnpackRowLength, OldImage.Width); + if (CopyPBO == 0) + { + CopyPBO = GL.GenBuffer(); + } - Texture.Create(Key, Data, NewImage); + GL.BindBuffer(BufferTarget.PixelPackBuffer, CopyPBO); - GL.PixelStore(PixelStoreParameter.UnpackRowLength, 0); - } + GL.BufferData(BufferTarget.PixelPackBuffer, Math.Max(ImageUtils.GetSize(OldImage), ImageUtils.GetSize(NewImage)), IntPtr.Zero, BufferUsageHint.StreamCopy); - public byte[] GetData(long Key) - { if (!Texture.TryGetImageHandler(Key, out ImageHandler CachedImage)) { - return null; - } - - if (SrcFb == 0) - { - SrcFb = GL.GenFramebuffer(); + throw new InvalidOperationException(); } - GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, SrcFb); - - FramebufferAttachment Attachment = GetAttachment(CachedImage); - - GL.FramebufferTexture(FramebufferTarget.ReadFramebuffer, Attachment, CachedImage.Handle, 0); + (_, PixelFormat Format, PixelType Type) = OGLEnumConverter.GetImageFormat(CachedImage.Format); - int Size = ImageUtils.GetSize(CachedImage.Image); + GL.BindTexture(TextureTarget.Texture2D, CachedImage.Handle); - byte[] Data = new byte[Size]; + GL.GetTexImage(TextureTarget.Texture2D, 0, Format, Type, IntPtr.Zero); - int Width = CachedImage.Width; - int Height = CachedImage.Height; + GL.BindBuffer(BufferTarget.PixelPackBuffer, 0); - (_, PixelFormat Format, PixelType Type) = OGLEnumConverter.GetImageFormat(CachedImage.Format); + GL.BindBuffer(BufferTarget.PixelUnpackBuffer, CopyPBO); - GL.ReadPixels(0, 0, Width, Height, Format, Type, Data); + Texture.Create(Key, ImageUtils.GetSize(NewImage), NewImage); - return Data; + GL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0); } private static FramebufferAttachment GetAttachment(ImageHandler CachedImage) |
