From de87ed3edcd1afecc0d0b58e6edd9bdf2f146e76 Mon Sep 17 00:00:00 2001 From: gdk Date: Wed, 13 Apr 2022 21:04:32 -0300 Subject: [PATCH] Fix backbuffer not being cleared and scissor not being re-enabled on OpenGL --- Ryujinx.Graphics.OpenGL/Pipeline.cs | 30 ++++++++++++++++++++++++----- Ryujinx.Graphics.OpenGL/Window.cs | 2 ++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Ryujinx.Graphics.OpenGL/Pipeline.cs b/Ryujinx.Graphics.OpenGL/Pipeline.cs index 40b45f37a..02d4ab5cd 100644 --- a/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -1116,12 +1116,32 @@ namespace Ryujinx.Graphics.OpenGL { int vIndex = index * 4; - v[vIndex] = regions[index].X; - v[vIndex + 1] = regions[index].Y; - v[vIndex + 2] = regions[index].Width; - v[vIndex + 3] = regions[index].Height; + var region = regions[index]; - GL.Enable(IndexedEnableCap.ScissorTest, index); + bool enabled = (region.X | region.Y) != 0 || region.Width != 0xffff || region.Height != 0xffff; + uint mask = 1u << index; + + if (enabled) + { + v[vIndex] = region.X; + v[vIndex + 1] = region.Y; + v[vIndex + 2] = region.Width; + v[vIndex + 3] = region.Height; + + if ((_scissorEnables & mask) == 0) + { + _scissorEnables |= mask; + GL.Enable(IndexedEnableCap.ScissorTest, index); + } + } + else + { + if ((_scissorEnables & mask) != 0) + { + _scissorEnables &= ~mask; + GL.Disable(IndexedEnableCap.ScissorTest, index); + } + } } GL.ScissorArray(0, count, v); diff --git a/Ryujinx.Graphics.OpenGL/Window.cs b/Ryujinx.Graphics.OpenGL/Window.cs index cd8efd129..ae74558e9 100644 --- a/Ryujinx.Graphics.OpenGL/Window.cs +++ b/Ryujinx.Graphics.OpenGL/Window.cs @@ -106,6 +106,8 @@ namespace Ryujinx.Graphics.OpenGL GL.Disable(EnableCap.RasterizerDiscard); GL.Disable(IndexedEnableCap.ScissorTest, 0); + GL.Clear(ClearBufferMask.ColorBufferBit); + int srcX0, srcX1, srcY0, srcY1; float scale = view.ScaleFactor;