From 53563657fe7ca29ff37b90b6470f50578895d4c8 Mon Sep 17 00:00:00 2001 From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> Date: Tue, 22 Aug 2023 17:16:48 -0700 Subject: [PATCH] Implement blending enable/disable for IGL_GDIPlus (more just moving it away from GDIPlusGuiRenderer) Fix GDI+ used for display method (got broken in some cleanup commits ago) Remove some things meant to be removed in the last commit (fixes debug build) --- src/BizHawk.Bizware.BizwareGL/IBlendState.cs | 6 --- .../GDIPlus/IGL_GDIPlus.cs | 9 ++++- .../Renderers/GDIPlusGuiRenderer.cs | 40 +++++++------------ .../Renderers/GuiRenderer.cs | 6 --- .../DisplayManager/Filters/Retro.cs | 6 +++ 5 files changed, 27 insertions(+), 40 deletions(-) delete mode 100644 src/BizHawk.Bizware.BizwareGL/IBlendState.cs diff --git a/src/BizHawk.Bizware.BizwareGL/IBlendState.cs b/src/BizHawk.Bizware.BizwareGL/IBlendState.cs deleted file mode 100644 index 0f29eb2d7d..0000000000 --- a/src/BizHawk.Bizware.BizwareGL/IBlendState.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace BizHawk.Bizware.BizwareGL -{ - public interface IBlendState - { - } -} diff --git a/src/BizHawk.Bizware.Graphics/GDIPlus/IGL_GDIPlus.cs b/src/BizHawk.Bizware.Graphics/GDIPlus/IGL_GDIPlus.cs index eec6ca9554..12672eebc8 100644 --- a/src/BizHawk.Bizware.Graphics/GDIPlus/IGL_GDIPlus.cs +++ b/src/BizHawk.Bizware.Graphics/GDIPlus/IGL_GDIPlus.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Drawing; +using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Numerics; @@ -39,12 +40,16 @@ namespace BizHawk.Bizware.Graphics public void EnableBlending() { - // TODO for real + var g = GetCurrentGraphics(); + g.CompositingMode = CompositingMode.SourceOver; + g.CompositingQuality = CompositingQuality.Default; } public void DisableBlending() { - // TODO for real + var g = GetCurrentGraphics(); + g.CompositingMode = CompositingMode.SourceCopy; + g.CompositingQuality = CompositingQuality.HighSpeed; } public Pipeline CreatePipeline(VertexLayout vertexLayout, Shader vertexShader, Shader fragmentShader, bool required, string memo) diff --git a/src/BizHawk.Bizware.Graphics/Renderers/GDIPlusGuiRenderer.cs b/src/BizHawk.Bizware.Graphics/Renderers/GDIPlusGuiRenderer.cs index b5115f21a9..25d0fa66e2 100644 --- a/src/BizHawk.Bizware.Graphics/Renderers/GDIPlusGuiRenderer.cs +++ b/src/BizHawk.Bizware.Graphics/Renderers/GDIPlusGuiRenderer.cs @@ -95,13 +95,15 @@ namespace BizHawk.Bizware.Graphics CurrentImageAttributes.SetColorMatrix(colorMatrix,ColorMatrixFlag.Default, ColorAdjustType.Bitmap); } - private bool _enableBlending; - public void EnableBlending() - => _enableBlending = true; + { + Owner.EnableBlending(); + } public void DisableBlending() - => _enableBlending = false; + { + Owner.DisableBlending(); + } private MatrixStack _Projection, _Modelview; @@ -133,7 +135,7 @@ namespace BizHawk.Bizware.Graphics public void Begin(int width, int height) { Begin(); - + Projection = Owner.CreateGuiProjectionMatrix(width, height); Modelview = Owner.CreateGuiViewMatrix(width, height); } @@ -142,11 +144,12 @@ namespace BizHawk.Bizware.Graphics { // uhhmmm I want to throw an exception if its already active, but its annoying. IsActive = true; - _enableBlending = false; + Owner.DisableBlending(); + CurrentImageAttributes?.Dispose(); CurrentImageAttributes = new(); - Modelview.Clear(); - Projection.Clear(); + Modelview?.Clear(); + Projection?.Clear(); } public void Flush() @@ -187,8 +190,8 @@ namespace BizHawk.Bizware.Graphics PointF[] destPoints = { new(x, y), - new(x+w, y), - new(x, y+h), + new(x + w, y), + new(x, y + h), }; g.DrawImage(gtex.SDBitmap, destPoints, new(x0, y0, x1 - x0, y1 - y0), GraphicsUnit.Pixel, CurrentImageAttributes); @@ -208,7 +211,7 @@ namespace BizHawk.Bizware.Graphics DrawInternal(art, x, y, width, height); } - private void PrepDraw(SDGraphics g, Texture2d tex) + private static void PrepDraw(SDGraphics g, Texture2d tex) { var tw = (GDIPlusTexture)tex.Opaque; @@ -224,21 +227,6 @@ namespace BizHawk.Bizware.Graphics TextureMagFilter.Nearest => InterpolationMode.NearestNeighbor, _ => g.InterpolationMode }; - - if (_enableBlending) - { - g.CompositingMode = CompositingMode.SourceOver; - g.CompositingQuality = CompositingQuality.Default; // ? - } - else - { - g.CompositingMode = CompositingMode.SourceCopy; - g.CompositingQuality = CompositingQuality.HighSpeed; - - // WARNING : DO NOT USE COLOR MATRIX TO WIPE THE ALPHA - // ITS SOOOOOOOOOOOOOOOOOOOOOOOOOOOO SLOW - // instead, we added kind of hacky support for 24bpp images - } } private void SetupMatrix(SDGraphics g) diff --git a/src/BizHawk.Bizware.Graphics/Renderers/GuiRenderer.cs b/src/BizHawk.Bizware.Graphics/Renderers/GuiRenderer.cs index 04ddfd3392..0d5df3a2bf 100644 --- a/src/BizHawk.Bizware.Graphics/Renderers/GuiRenderer.cs +++ b/src/BizHawk.Bizware.Graphics/Renderers/GuiRenderer.cs @@ -361,9 +361,6 @@ namespace BizHawk.Bizware.Graphics pData[31] = CornerColors[3].W; Owner.Draw(new(pData), 4); -#if DEBUG - Debug.Assert(BlendStateSet); -#endif } private void DrawSubrectInternal(Texture2d tex, float x, float y, float w, float h, float u0, float v0, float u1, float v1) @@ -381,9 +378,6 @@ namespace BizHawk.Bizware.Graphics // state cache private Texture2d sTexture; -#if DEBUG - private bool BlendStateSet; -#endif // shaders are hand-coded for each platform to make sure they stay as fast as possible diff --git a/src/BizHawk.Client.Common/DisplayManager/Filters/Retro.cs b/src/BizHawk.Client.Common/DisplayManager/Filters/Retro.cs index 5ebe402297..627b29035b 100644 --- a/src/BizHawk.Client.Common/DisplayManager/Filters/Retro.cs +++ b/src/BizHawk.Client.Common/DisplayManager/Filters/Retro.cs @@ -45,6 +45,12 @@ namespace BizHawk.Client.Common.Filters Passes = preset.Passes.ToArray(); Errors = string.Empty; + if (owner.API is not ("OPENGL" or "D3D9")) + { + Errors = $"Unsupported API {owner.API}"; + return; + } + // load up the shaders var shaders = new RetroShader[preset.Passes.Count]; for (var i = 0; i < preset.Passes.Count; i++)