From 58d501f7585a02d23cd02edeb6980bf84dee688d Mon Sep 17 00:00:00 2001 From: Thog Date: Thu, 13 Feb 2020 16:22:48 +0100 Subject: [PATCH] Make sure to clear alpha channel when presenting Texture This fix once and for all the transparency issue on Windows. --- Ryujinx.Graphics.OpenGL/Window.cs | 40 +++++++++++++++++++++---------- Ryujinx/Ui/GLRenderer.cs | 2 +- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/Ryujinx.Graphics.OpenGL/Window.cs b/Ryujinx.Graphics.OpenGL/Window.cs index 26fc6a64b8..2689a7c4a6 100644 --- a/Ryujinx.Graphics.OpenGL/Window.cs +++ b/Ryujinx.Graphics.OpenGL/Window.cs @@ -22,15 +22,30 @@ namespace Ryujinx.Graphics.OpenGL public void Present(ITexture texture, ImageCrop crop) { - TextureView view = (TextureView)texture; - GL.Disable(EnableCap.FramebufferSrgb); + CopyTextureToFrameBufferRGB(0, GetCopyFramebufferHandleLazy(), (TextureView)texture, crop); + + GL.Enable(EnableCap.FramebufferSrgb); + } + + public void SetSize(int width, int height) + { + _width = width; + _height = height; + } + + + private void CopyTextureToFrameBufferRGB(int drawFramebuffer, int readFramebuffer, TextureView view, ImageCrop crop) + { + bool[] oldFramebufferColorWritemask = new bool[4]; + int oldReadFramebufferHandle = GL.GetInteger(GetPName.ReadFramebufferBinding); int oldDrawFramebufferHandle = GL.GetInteger(GetPName.DrawFramebufferBinding); + GL.GetBoolean(GetIndexedPName.ColorWritemask, drawFramebuffer, oldFramebufferColorWritemask); - GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, 0); - GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, GetCopyFramebufferHandleLazy()); + GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, drawFramebuffer); + GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, readFramebuffer); GL.FramebufferTexture( FramebufferTarget.ReadFramebuffer, @@ -93,16 +108,17 @@ namespace Ryujinx.Graphics.OpenGL ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Linear); + // Remove Alpha channel + GL.ColorMask(drawFramebuffer, false, false, false, true); + GL.ClearBuffer(ClearBuffer.Color, 0, new float[] { 0.0f, 0.0f, 0.0f, 1.0f }); + GL.ColorMask(drawFramebuffer, + oldFramebufferColorWritemask[0], + oldFramebufferColorWritemask[1], + oldFramebufferColorWritemask[2], + oldFramebufferColorWritemask[3]); + GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, oldReadFramebufferHandle); GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, oldDrawFramebufferHandle); - - GL.Enable(EnableCap.FramebufferSrgb); - } - - public void SetSize(int width, int height) - { - _width = width; - _height = height; } private int GetCopyFramebufferHandleLazy() diff --git a/Ryujinx/Ui/GLRenderer.cs b/Ryujinx/Ui/GLRenderer.cs index 0e5c7bb11f..be76fb0240 100644 --- a/Ryujinx/Ui/GLRenderer.cs +++ b/Ryujinx/Ui/GLRenderer.cs @@ -53,7 +53,7 @@ namespace Ryujinx.Ui private Input.NpadController _primaryController; public GLRenderer(Switch device) - : base (new GraphicsMode(new ColorFormat(24)), + : base (new GraphicsMode(new ColorFormat()), 3, 3, GraphicsContextFlags.ForwardCompatible) {