From 64abeddc2bdb34881c427c834aedac8ed65cfec6 Mon Sep 17 00:00:00 2001 From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> Date: Fri, 11 Aug 2023 13:27:52 -0700 Subject: [PATCH] simplify IGL 1: Combine Clear and SetClearColor, remove support for non-color buffers (not supported by GDI+, never actually used) --- src/BizHawk.Bizware.BizwareGL/IGL.cs | 19 +++++++------------ src/BizHawk.Bizware.BizwareGL/IGL_GdiPlus.cs | 17 ++--------------- .../enums/ClearBufferMask.cs | 15 --------------- src/BizHawk.Bizware.Graphics/D3D9/IGL_D3D9.cs | 13 ++----------- .../OpenGL/IGL_OpenGL.cs | 10 ++-------- .../DisplayManager/DisplayManagerBase.cs | 3 +-- .../DisplayManager/Filters/Gui.cs | 6 ++---- 7 files changed, 16 insertions(+), 67 deletions(-) delete mode 100644 src/BizHawk.Bizware.BizwareGL/enums/ClearBufferMask.cs diff --git a/src/BizHawk.Bizware.BizwareGL/IGL.cs b/src/BizHawk.Bizware.BizwareGL/IGL.cs index 6601eaccf0..b921dcfd16 100644 --- a/src/BizHawk.Bizware.BizwareGL/IGL.cs +++ b/src/BizHawk.Bizware.BizwareGL/IGL.cs @@ -19,14 +19,9 @@ namespace BizHawk.Bizware.BizwareGL EDispMethod DispMethodEnum { get; } /// - /// Clears the specified buffer parts + /// Clears the color buffer with the specified color /// - void Clear(ClearBufferMask mask); - - /// - /// Sets the current clear color - /// - void SetClearColor(Color color); + void ClearColor(Color color); /// /// compile a fragment shader. This is the simplified method. A more complex method may be added later which will accept multiple sources and preprocessor definitions independently @@ -88,11 +83,6 @@ namespace BizHawk.Bizware.BizwareGL /// void SetPipelineUniform(PipelineUniform uniform, bool value); - /// - /// Binds array data for use with the currently-bound pipeline's VertexLayout - /// - void BindArrayData(IntPtr pData); - /// /// Begins a rendering scene; use before doing any draw calls, as per normal /// @@ -103,6 +93,11 @@ namespace BizHawk.Bizware.BizwareGL /// void EndScene(); + /// + /// Binds array data for use with the currently-bound pipeline's VertexLayout + /// + void BindArrayData(IntPtr pData); + /// /// Draws based on the currently set pipeline, VertexLayout and ArrayData. /// Count is the VERT COUNT not the primitive count diff --git a/src/BizHawk.Bizware.BizwareGL/IGL_GdiPlus.cs b/src/BizHawk.Bizware.BizwareGL/IGL_GdiPlus.cs index 0b9f519ac3..5b1bbe53e2 100644 --- a/src/BizHawk.Bizware.BizwareGL/IGL_GdiPlus.cs +++ b/src/BizHawk.Bizware.BizwareGL/IGL_GdiPlus.cs @@ -26,14 +26,8 @@ namespace BizHawk.Bizware.BizwareGL MyBufferedGraphicsContext.Dispose(); } - public void Clear(ClearBufferMask mask) - { - var g = GetCurrentGraphics(); - if ((mask & ClearBufferMask.ColorBufferBit) != 0) - { - g.Clear(_currentClearColor); - } - } + public void ClearColor(Color color) + => GetCurrentGraphics().Clear(color); public string API => "GDIPLUS"; @@ -43,13 +37,6 @@ namespace BizHawk.Bizware.BizwareGL return null; } - private Color _currentClearColor = Color.Transparent; - - public void SetClearColor(Color color) - { - _currentClearColor = color; - } - public void BindArrayData(IntPtr pData) { } diff --git a/src/BizHawk.Bizware.BizwareGL/enums/ClearBufferMask.cs b/src/BizHawk.Bizware.BizwareGL/enums/ClearBufferMask.cs deleted file mode 100644 index 3ef984c999..0000000000 --- a/src/BizHawk.Bizware.BizwareGL/enums/ClearBufferMask.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace BizHawk.Bizware.BizwareGL -{ - [Flags] - public enum ClearBufferMask - { - None = 0x0000, - DepthBufferBit = 0x0100, - AccumBufferBit = 0x0200, - StencilBufferBit = 0x0400, - ColorBufferBit = 0x4000, - CoverageBufferBitNv = 0x8000, - } -} diff --git a/src/BizHawk.Bizware.Graphics/D3D9/IGL_D3D9.cs b/src/BizHawk.Bizware.Graphics/D3D9/IGL_D3D9.cs index 438ab9b439..d4527ed658 100644 --- a/src/BizHawk.Bizware.Graphics/D3D9/IGL_D3D9.cs +++ b/src/BizHawk.Bizware.Graphics/D3D9/IGL_D3D9.cs @@ -182,17 +182,8 @@ namespace BizHawk.Bizware.Graphics } } - public void Clear(ClearBufferMask mask) - { - var flags = ClearFlags.None; - if ((mask & ClearBufferMask.ColorBufferBit) != 0) flags |= ClearFlags.Target; - if ((mask & ClearBufferMask.DepthBufferBit) != 0) flags |= ClearFlags.ZBuffer; - if ((mask & ClearBufferMask.StencilBufferBit) != 0) flags |= ClearFlags.Stencil; - _device.Clear(flags, _clearColor, 0.0f, 0); - } - - public void SetClearColor(Color color) - => _clearColor = color.ToSharpDXColor(); + public void ClearColor(Color color) + => _device.Clear(ClearFlags.Target, color.ToSharpDXColor(), 0.0f, 0); public IBlendState CreateBlendState( BlendingFactorSrc colorSource, diff --git a/src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs b/src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs index 3126f0d43e..abe5f9339e 100644 --- a/src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs +++ b/src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs @@ -19,7 +19,6 @@ using BizHawk.Common; using Silk.NET.OpenGL.Legacy; -using BizClearBufferMask = BizHawk.Bizware.BizwareGL.ClearBufferMask; using BizPrimitiveType = BizHawk.Bizware.BizwareGL.PrimitiveType; using BizShader = BizHawk.Bizware.BizwareGL.Shader; @@ -27,7 +26,6 @@ using BizShader = BizHawk.Bizware.BizwareGL.Shader; using BizTextureMagFilter = BizHawk.Bizware.BizwareGL.TextureMagFilter; using BizTextureMinFilter = BizHawk.Bizware.BizwareGL.TextureMinFilter; -using GLClearBufferMask = Silk.NET.OpenGL.Legacy.ClearBufferMask; using GLPrimitiveType = Silk.NET.OpenGL.Legacy.PrimitiveType; using GLVertexAttribPointerType = Silk.NET.OpenGL.Legacy.VertexAttribPointerType; @@ -77,14 +75,10 @@ namespace BizHawk.Bizware.Graphics GL.Dispose(); } - public void Clear(BizClearBufferMask mask) - { - GL.Clear((GLClearBufferMask)mask); // these are the same enum - } - - public void SetClearColor(Color color) + public void ClearColor(Color color) { GL.ClearColor(color); + GL.Clear(ClearBufferMask.ColorBufferBit); } public IGraphicsControl Internal_CreateGraphicsControl() diff --git a/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs b/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs index 2b29be8b9b..ccbdf54723 100644 --- a/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs +++ b/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs @@ -910,8 +910,7 @@ namespace BizHawk.Client.Common ActivateGraphicsControlContext(); _gl.BeginScene(); _gl.BindRenderTarget(null); - _gl.SetClearColor(Color.Black); - _gl.Clear(ClearBufferMask.ColorBufferBit); + _gl.ClearColor(Color.Black); _gl.EndScene(); SwapBuffersOfGraphicsControl(); } diff --git a/src/BizHawk.Client.Common/DisplayManager/Filters/Gui.cs b/src/BizHawk.Client.Common/DisplayManager/Filters/Gui.cs index 3c23c3f5c0..49a4fc6f2b 100644 --- a/src/BizHawk.Client.Common/DisplayManager/Filters/Gui.cs +++ b/src/BizHawk.Client.Common/DisplayManager/Filters/Gui.cs @@ -395,8 +395,7 @@ namespace BizHawk.Client.Common.Filters #endif // TODO: this could be more efficient (draw only in gap) - FilterProgram.GL.SetClearColor(Color.Black); - FilterProgram.GL.Clear(ClearBufferMask.ColorBufferBit); + FilterProgram.GL.ClearColor(Color.Black); FilterProgram.GuiRenderer.Begin(outputSize); FilterProgram.GuiRenderer.SetBlendState(FilterProgram.GL.BlendNoneCopy); @@ -662,8 +661,7 @@ namespace BizHawk.Client.Common.Filters return; } - FilterProgram.GL.SetClearColor(Color.FromArgb(BackgroundColor)); - FilterProgram.GL.Clear(ClearBufferMask.ColorBufferBit); + FilterProgram.GL.ClearColor(Color.FromArgb(BackgroundColor)); FilterProgram.GuiRenderer.Begin(OutputSize.Width, OutputSize.Height); FilterProgram.GuiRenderer.SetBlendState(FilterProgram.GL.BlendNoneCopy);