diff options
author | emmauss <emmausssss@gmail.com> | 2021-06-28 20:09:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-28 22:09:43 +0200 |
commit | 28618c58d7ee1ae63fc57deca791a64ab38b57af (patch) | |
tree | ce7e84d5301ca6222cb2cdad7cf82eb2a1682ce3 /Ryujinx.Graphics.OpenGL/Window.cs | |
parent | a79b39b91347816ea14677b58af738b70df03e9c (diff) |
Add Screenshot Feature (#2354)
* Add internal screenshot capabilities
* update version notice
Diffstat (limited to 'Ryujinx.Graphics.OpenGL/Window.cs')
-rw-r--r-- | Ryujinx.Graphics.OpenGL/Window.cs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Ryujinx.Graphics.OpenGL/Window.cs b/Ryujinx.Graphics.OpenGL/Window.cs index b7525ae5..35b04d6d 100644 --- a/Ryujinx.Graphics.OpenGL/Window.cs +++ b/Ryujinx.Graphics.OpenGL/Window.cs @@ -16,6 +16,8 @@ namespace Ryujinx.Graphics.OpenGL internal BackgroundContextWorker BackgroundContext { get; private set; } + internal bool ScreenCaptureRequested { get; set; } + public Window(Renderer renderer) { _renderer = renderer; @@ -106,6 +108,13 @@ namespace Ryujinx.Graphics.OpenGL int dstY0 = crop.FlipY ? dstPaddingY : _height - dstPaddingY; int dstY1 = crop.FlipY ? _height - dstPaddingY : dstPaddingY; + if (ScreenCaptureRequested) + { + CaptureFrame(srcX0, srcY0, srcX1, srcY1, view.Format.IsBgra8(), crop.FlipX, crop.FlipY); + + ScreenCaptureRequested = false; + } + GL.BlitFramebuffer( srcX0, srcY0, @@ -159,6 +168,16 @@ namespace Ryujinx.Graphics.OpenGL BackgroundContext = new BackgroundContextWorker(baseContext); } + public void CaptureFrame(int x, int y, int width, int height, bool isBgra, bool flipX, bool flipY) + { + long size = Math.Abs(4 * width * height); + byte[] bitmap = new byte[size]; + + GL.ReadPixels(x, y, width, height, isBgra ? PixelFormat.Bgra : PixelFormat.Rgba, PixelType.UnsignedByte, bitmap); + + _renderer.OnScreenCaptured(new ScreenCaptureImageInfo(width, height, isBgra, bitmap, flipX, flipY)); + } + public void Dispose() { BackgroundContext.Dispose(); |