Add Screenshot Feature (#2354)

* Add internal screenshot  capabilities

* update version notice
This commit is contained in:
emmauss 2021-06-28 20:09:43 +00:00 committed by GitHub
parent a79b39b913
commit 28618c58d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 220 additions and 56 deletions

View file

@ -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();