diff --git a/src/BizHawk.Bizware.Graphics/D3D11/D3D11Resources.cs b/src/BizHawk.Bizware.Graphics/D3D11/D3D11Resources.cs index 7fa57deb01..590eeba7e2 100644 --- a/src/BizHawk.Bizware.Graphics/D3D11/D3D11Resources.cs +++ b/src/BizHawk.Bizware.Graphics/D3D11/D3D11Resources.cs @@ -18,7 +18,8 @@ namespace BizHawk.Bizware.Graphics public ID3D11DeviceContext Context; public IDXGIFactory1 Factory1; public IDXGIFactory2 Factory2; - public ID3D11BlendState BlendEnableState; + public ID3D11BlendState BlendNormalState; + public ID3D11BlendState BlendAlphaState; public ID3D11BlendState BlendDisableState; public ID3D11SamplerState PointSamplerState; public ID3D11SamplerState LinearSamplerState; @@ -84,11 +85,13 @@ namespace BizHawk.Bizware.Graphics bd.RenderTarget[0].DestinationBlendAlpha = Blend.InverseSourceAlpha; bd.RenderTarget[0].BlendOperationAlpha = BlendOperation.Add; bd.RenderTarget[0].RenderTargetWriteMask = ColorWriteEnable.All; - BlendEnableState = Device.CreateBlendState(bd); + BlendNormalState = Device.CreateBlendState(bd); - bd.RenderTarget[0].BlendEnable = false; bd.RenderTarget[0].SourceBlend = Blend.One; bd.RenderTarget[0].DestinationBlend = Blend.Zero; + BlendAlphaState = Device.CreateBlendState(bd); + + bd.RenderTarget[0].BlendEnable = false; BlendDisableState = Device.CreateBlendState(bd); PointSamplerState = Device.CreateSamplerState(SamplerDescription.PointClamp); @@ -141,8 +144,10 @@ namespace BizHawk.Bizware.Graphics RasterizerState?.Dispose(); RasterizerState = null; - BlendEnableState?.Dispose(); - BlendEnableState = null; + BlendNormalState?.Dispose(); + BlendNormalState = null; + BlendAlphaState?.Dispose(); + BlendAlphaState = null; BlendDisableState?.Dispose(); BlendDisableState = null; diff --git a/src/BizHawk.Bizware.Graphics/D3D11/IGL_D3D11.cs b/src/BizHawk.Bizware.Graphics/D3D11/IGL_D3D11.cs index cc8e6acfa9..43eb8c99e8 100644 --- a/src/BizHawk.Bizware.Graphics/D3D11/IGL_D3D11.cs +++ b/src/BizHawk.Bizware.Graphics/D3D11/IGL_D3D11.cs @@ -25,7 +25,8 @@ namespace BizHawk.Bizware.Graphics private ID3D11DeviceContext Context => _resources.Context; private IDXGIFactory1 Factory1 => _resources.Factory1; private IDXGIFactory2 Factory2 => _resources.Factory2; - private ID3D11BlendState BlendEnableState => _resources.BlendEnableState; + private ID3D11BlendState BlendNormalState => _resources.BlendNormalState; + private ID3D11BlendState BlendAlphaState => _resources.BlendAlphaState; private ID3D11BlendState BlendDisableState => _resources.BlendDisableState; private ID3D11RasterizerState RasterizerState => _resources.RasterizerState; @@ -184,8 +185,11 @@ namespace BizHawk.Bizware.Graphics public void ClearColor(Color color) => Context.ClearRenderTargetView(CurRenderTarget?.RTV ?? _controlSwapChain.RTV, new(color.R, color.B, color.G, color.A)); - public void EnableBlending() - => Context.OMSetBlendState(BlendEnableState); + public void EnableBlendNormal() + => Context.OMSetBlendState(BlendNormalState); + + public void EnableBlendAlpha() + => Context.OMSetBlendState(BlendAlphaState); public void DisableBlending() => Context.OMSetBlendState(BlendDisableState); diff --git a/src/BizHawk.Bizware.Graphics/GDIPlus/IGL_GDIPlus.cs b/src/BizHawk.Bizware.Graphics/GDIPlus/IGL_GDIPlus.cs index 2e50824c76..967866482f 100644 --- a/src/BizHawk.Bizware.Graphics/GDIPlus/IGL_GDIPlus.cs +++ b/src/BizHawk.Bizware.Graphics/GDIPlus/IGL_GDIPlus.cs @@ -25,7 +25,14 @@ namespace BizHawk.Bizware.Graphics public void ClearColor(Color color) => GetCurrentGraphics().Clear(color); - public void EnableBlending() + public void EnableBlendNormal() + { + var g = GetCurrentGraphics(); + g.CompositingMode = CompositingMode.SourceOver; + g.CompositingQuality = CompositingQuality.Default; + } + + public void EnableBlendAlpha() { var g = GetCurrentGraphics(); g.CompositingMode = CompositingMode.SourceOver; diff --git a/src/BizHawk.Bizware.Graphics/Interfaces/IGL.cs b/src/BizHawk.Bizware.Graphics/Interfaces/IGL.cs index 3f4f457111..d62624bca9 100644 --- a/src/BizHawk.Bizware.Graphics/Interfaces/IGL.cs +++ b/src/BizHawk.Bizware.Graphics/Interfaces/IGL.cs @@ -57,7 +57,13 @@ namespace BizHawk.Bizware.Graphics /// /// Enables normal (non-premultiplied) alpha blending. /// - void EnableBlending(); + void EnableBlendNormal(); + + /// + /// Enables alpha blending (non-alpha values are copied from the source fragment). + /// This mimics GDI+ blending + /// + void EnableBlendAlpha(); /// /// Disables blending (alpha values are copied from the source fragment) diff --git a/src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs b/src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs index 2d9ae729dc..08da8bd395 100644 --- a/src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs +++ b/src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs @@ -41,13 +41,20 @@ namespace BizHawk.Bizware.Graphics GL.Clear(ClearBufferMask.ColorBufferBit); } - public void EnableBlending() + public void EnableBlendNormal() { GL.Enable(EnableCap.Blend); GL.BlendEquation(GLEnum.FuncAdd); GL.BlendFuncSeparate(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha, BlendingFactor.One, BlendingFactor.OneMinusSrcAlpha); } + public void EnableBlendAlpha() + { + GL.Enable(EnableCap.Blend); + GL.BlendEquation(GLEnum.FuncAdd); + GL.BlendFuncSeparate(BlendingFactor.One, BlendingFactor.Zero, BlendingFactor.One, BlendingFactor.OneMinusSrcAlpha); + } + public void DisableBlending() => GL.Disable(EnableCap.Blend); diff --git a/src/BizHawk.Bizware.Graphics/Renderers/GDIPlusGuiRenderer.cs b/src/BizHawk.Bizware.Graphics/Renderers/GDIPlusGuiRenderer.cs index 716adcab23..4d568baae9 100644 --- a/src/BizHawk.Bizware.Graphics/Renderers/GDIPlusGuiRenderer.cs +++ b/src/BizHawk.Bizware.Graphics/Renderers/GDIPlusGuiRenderer.cs @@ -88,7 +88,7 @@ namespace BizHawk.Bizware.Graphics } public void EnableBlending() - => Owner.EnableBlending(); + => Owner.EnableBlendNormal(); public void DisableBlending() => Owner.DisableBlending(); diff --git a/src/BizHawk.Bizware.Graphics/Renderers/GuiRenderer.cs b/src/BizHawk.Bizware.Graphics/Renderers/GuiRenderer.cs index 6100076d18..2b2e401466 100644 --- a/src/BizHawk.Bizware.Graphics/Renderers/GuiRenderer.cs +++ b/src/BizHawk.Bizware.Graphics/Renderers/GuiRenderer.cs @@ -120,7 +120,7 @@ namespace BizHawk.Bizware.Graphics public void EnableBlending() { Flush(); - Owner.EnableBlending(); + Owner.EnableBlendNormal(); } public void DisableBlending() diff --git a/src/BizHawk.Bizware.Graphics/Renderers/ImGui2DRenderer.cs b/src/BizHawk.Bizware.Graphics/Renderers/ImGui2DRenderer.cs index d4c41879dc..dd80d587b7 100644 --- a/src/BizHawk.Bizware.Graphics/Renderers/ImGui2DRenderer.cs +++ b/src/BizHawk.Bizware.Graphics/Renderers/ImGui2DRenderer.cs @@ -153,7 +153,8 @@ namespace BizHawk.Bizware.Graphics { None, DisableBlending, - EnableBlending, + EnableBlendAlpha, + EnableBlendNormal, DrawString, } @@ -161,7 +162,7 @@ namespace BizHawk.Bizware.Graphics { if (EnableBlending) { - _igl.EnableBlending(); + _igl.EnableBlendAlpha(); } else { @@ -223,8 +224,11 @@ namespace BizHawk.Bizware.Graphics case DrawCallbackId.DisableBlending: _igl.DisableBlending(); break; - case DrawCallbackId.EnableBlending: - _igl.EnableBlending(); + case DrawCallbackId.EnableBlendAlpha: + _igl.EnableBlendAlpha(); + break; + case DrawCallbackId.EnableBlendNormal: + _igl.EnableBlendNormal(); break; case DrawCallbackId.DrawString: { @@ -277,7 +281,7 @@ namespace BizHawk.Bizware.Graphics { ClearStringOutput(); // synthesize an add image command for our string bitmap - _imGuiDrawList.AddCallback((IntPtr)DrawCallbackId.EnableBlending, IntPtr.Zero); + _imGuiDrawList.AddCallback((IntPtr)DrawCallbackId.EnableBlendNormal, IntPtr.Zero); DrawImage(_stringOutput, 0, 0); } @@ -311,7 +315,7 @@ namespace BizHawk.Bizware.Graphics break; // CompositingMode.SourceOver means enable blending case false when value == CompositingMode.SourceOver: - _imGuiDrawList.AddCallback((IntPtr)DrawCallbackId.EnableBlending, IntPtr.Zero); + _imGuiDrawList.AddCallback((IntPtr)DrawCallbackId.EnableBlendAlpha, IntPtr.Zero); _pendingBlendEnable = true; break; } diff --git a/src/BizHawk.Bizware.Graphics/Renderers/SDLImGui2DRenderer.cs b/src/BizHawk.Bizware.Graphics/Renderers/SDLImGui2DRenderer.cs index dfeab62d33..3f1df6741f 100644 --- a/src/BizHawk.Bizware.Graphics/Renderers/SDLImGui2DRenderer.cs +++ b/src/BizHawk.Bizware.Graphics/Renderers/SDLImGui2DRenderer.cs @@ -165,7 +165,8 @@ namespace BizHawk.Bizware.Graphics case DrawCallbackId.DisableBlending: _ = SDL_SetRenderDrawBlendMode(sdlRenderer, SDL_BlendMode.SDL_BLENDMODE_NONE); break; - case DrawCallbackId.EnableBlending: + case DrawCallbackId.EnableBlendAlpha: + case DrawCallbackId.EnableBlendNormal: _ = SDL_SetRenderDrawBlendMode(sdlRenderer, SDL_BlendMode.SDL_BLENDMODE_BLEND); break; case DrawCallbackId.DrawString: