diff options
Diffstat (limited to 'Ryujinx.Graphics.OpenGL')
-rw-r--r-- | Ryujinx.Graphics.OpenGL/Renderer.cs | 12 | ||||
-rw-r--r-- | Ryujinx.Graphics.OpenGL/Window.cs | 19 |
2 files changed, 31 insertions, 0 deletions
diff --git a/Ryujinx.Graphics.OpenGL/Renderer.cs b/Ryujinx.Graphics.OpenGL/Renderer.cs index a2be4373..001cac8d 100644 --- a/Ryujinx.Graphics.OpenGL/Renderer.cs +++ b/Ryujinx.Graphics.OpenGL/Renderer.cs @@ -28,6 +28,8 @@ namespace Ryujinx.Graphics.OpenGL private Sync _sync; + public event EventHandler<ScreenCaptureImageInfo> ScreenCaptured; + internal ResourcePool ResourcePool { get; } internal int BufferCount { get; private set; } @@ -196,5 +198,15 @@ namespace Ryujinx.Graphics.OpenGL { _sync.Wait(id); } + + public void Screenshot() + { + _window.ScreenCaptureRequested = true; + } + + public void OnScreenCaptured(ScreenCaptureImageInfo bitmap) + { + ScreenCaptured?.Invoke(this, bitmap); + } } } 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(); |