From 47100ec8c1b3cabc7d53654163c1dd30b58d483d Mon Sep 17 00:00:00 2001 From: gdkchan Date: Fri, 13 Apr 2018 22:42:55 -0300 Subject: [PATCH] [GPU] Avoid drawing the frame buffer with alpha blend enabled, use correct blend enable register, clear the buffer before drawing --- Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs | 19 +++++++++++++++++-- Ryujinx.Graphics/Gpu/NvGpuEngine3d.cs | 2 +- Ryujinx.Graphics/Gpu/NvGpuEngine3dReg.cs | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs index 818af3b3a8..cca61e1810 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs @@ -184,6 +184,10 @@ namespace Ryujinx.Graphics.Gal.OpenGL { EnsureInitialized(); + bool AlphaBlendEnable = GL.GetInteger(GetPName.Blend) != 0; + + GL.Disable(EnableCap.Blend); + GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, CurrTexHandle); @@ -192,6 +196,10 @@ namespace Ryujinx.Graphics.Gal.OpenGL GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); + GL.Clear( + ClearBufferMask.ColorBufferBit | + ClearBufferMask.DepthBufferBit); + GL.BindVertexArray(VaoHandle); GL.UseProgram(Shader.Handle); @@ -202,6 +210,11 @@ namespace Ryujinx.Graphics.Gal.OpenGL GL.BindFramebuffer(FramebufferTarget.Framebuffer, CurrFbHandle); GL.UseProgram(CurrentProgram); + + if (AlphaBlendEnable) + { + GL.Enable(EnableCap.Blend); + } } } @@ -289,9 +302,11 @@ namespace Ryujinx.Graphics.Gal.OpenGL { GL.BindTexture(TextureTarget.Texture2D, Handle); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); + const int MinFilter = (int)TextureMinFilter.Linear; + const int MagFilter = (int)TextureMagFilter.Linear; - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, MinFilter); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, MagFilter); (PixelFormat Format, PixelType Type) = OGLEnumConverter.GetTextureFormat(GalTextureFormat.A8B8G8R8); diff --git a/Ryujinx.Graphics/Gpu/NvGpuEngine3d.cs b/Ryujinx.Graphics/Gpu/NvGpuEngine3d.cs index 1142e4aa69..fd13367c41 100644 --- a/Ryujinx.Graphics/Gpu/NvGpuEngine3d.cs +++ b/Ryujinx.Graphics/Gpu/NvGpuEngine3d.cs @@ -168,7 +168,7 @@ namespace Ryujinx.Graphics.Gpu private void SetAlphaBlending() { //TODO: Support independent blend properly. - bool Enable = (ReadRegister(NvGpuEngine3dReg.IBlendEnable) & 1) != 0; + bool Enable = (ReadRegister(NvGpuEngine3dReg.IBlendNEnable) & 1) != 0; Gpu.Renderer.SetBlendEnable(Enable); diff --git a/Ryujinx.Graphics/Gpu/NvGpuEngine3dReg.cs b/Ryujinx.Graphics/Gpu/NvGpuEngine3dReg.cs index cb0b9d983d..4f1dce94b3 100644 --- a/Ryujinx.Graphics/Gpu/NvGpuEngine3dReg.cs +++ b/Ryujinx.Graphics/Gpu/NvGpuEngine3dReg.cs @@ -16,6 +16,7 @@ namespace Ryujinx.Graphics.Gpu BlendFuncSrcAlpha = 0x4d4, BlendFuncDstAlpha = 0x4d6, BlendEnableMaster = 0x4d7, + IBlendNEnable = 0x4d8, VertexArrayElemBase = 0x50d, TexHeaderPoolOffset = 0x55d, TexSamplerPoolOffset = 0x557,