diff --git a/src/BizHawk.Bizware.BizwareGL/Extensions/IGLExtensions.cs b/src/BizHawk.Bizware.BizwareGL/Extensions/IGLExtensions.cs new file mode 100644 index 0000000000..703717fd5f --- /dev/null +++ b/src/BizHawk.Bizware.BizwareGL/Extensions/IGLExtensions.cs @@ -0,0 +1,71 @@ +using System.IO; +using System.Drawing; +using System.Numerics; + +namespace BizHawk.Bizware.BizwareGL +{ + public static class IGLExtensions + { + /// + /// Loads a texture from disk + /// + public static Texture2d LoadTexture(this IGL igl, string path) + { + using var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); + return igl.LoadTexture(fs); + } + + /// + /// Loads a texture from the stream + /// + public static Texture2d LoadTexture(this IGL igl, Stream stream) + { + using var bmp = new BitmapBuffer(stream, new()); + return igl.LoadTexture(bmp); + } + + /// + /// Loads a texture from the System.Drawing.Bitmap + /// + public static Texture2d LoadTexture(this IGL igl, Bitmap bitmap) + { + using var bmp = new BitmapBuffer(bitmap, new()); + return igl.LoadTexture(bmp); + } + + /// + /// Loads a texture from the BitmapBuffer + /// + public static Texture2d LoadTexture(this IGL igl, BitmapBuffer buffer) + { + var ret = igl.CreateTexture(buffer.Width, buffer.Height); + igl.LoadTextureData(ret, buffer); + return ret; + } + + /// + /// sets the viewport (and scissor) according to the provided specifications + /// + public static void SetViewport(this IGL igl, int width, int height) + => igl.SetViewport(0, 0, width, height); + + /// + /// sets the viewport (and scissor) according to the provided specifications + /// + public static void SetViewport(this IGL igl, Size size) + => igl.SetViewport(0, 0, size.Width, size.Height); + + /// + /// generates a proper 2d othographic projection for the given destination size, suitable for use in a GUI + /// + public static Matrix4x4 CreateGuiProjectionMatrix(this IGL igl, Size dims) + => igl.CreateGuiProjectionMatrix(dims.Width, dims.Height); + + /// + /// generates a proper view transform for a standard 2d ortho projection, including half-pixel jitter if necessary and + /// re-establishing of a normal 2d graphics top-left origin. suitable for use in a GUI + /// + public static Matrix4x4 CreateGuiViewMatrix(this IGL igl, Size dims, bool autoflip = true) + => igl.CreateGuiViewMatrix(dims.Width, dims.Height, autoflip); + } +} diff --git a/src/BizHawk.Bizware.BizwareGL/IGL.cs b/src/BizHawk.Bizware.BizwareGL/IGL.cs index 39a3c12c71..9253a0e482 100644 --- a/src/BizHawk.Bizware.BizwareGL/IGL.cs +++ b/src/BizHawk.Bizware.BizwareGL/IGL.cs @@ -1,5 +1,4 @@ using System; -using System.IO; using System.Drawing; using System.Numerics; @@ -14,7 +13,9 @@ namespace BizHawk.Bizware.BizwareGL /// public interface IGL : IDisposable { - /// HACK + /// + /// Returns the display method represented by this IGL + /// EDispMethod DispMethodEnum { get; } /// @@ -82,16 +83,6 @@ namespace BizHawk.Bizware.BizwareGL /// void SetPipelineUniform(PipelineUniform uniform, bool value); - /// - /// Begins a rendering scene; use before doing any draw calls, as per normal - /// - void BeginScene(); - - /// - /// Indicates end of scene rendering; use after all draw calls as per normal - /// - void EndScene(); - /// /// Draws based on the currently set pipeline /// data contains vertexes based on the pipeline's VertexLayout @@ -122,7 +113,7 @@ namespace BizHawk.Bizware.BizwareGL /// /// Creates a texture with the specified dimensions - /// TODO - pass in specifications somehow + /// The texture will use a clamping address mode /// Texture2d CreateTexture(int width, int height); @@ -136,8 +127,6 @@ namespace BizHawk.Bizware.BizwareGL /// Sets the texture's filtering mode /// The default is linear = false (i.e. nearest neighbor) /// - /// - /// public void SetTextureFilter(Texture2d texture, bool linear); /// @@ -145,85 +134,32 @@ namespace BizHawk.Bizware.BizwareGL /// void LoadTextureData(Texture2d tex, BitmapBuffer bmp); - /// - /// Loads a texture from disk - /// - Texture2d LoadTexture(string path); - - /// - /// Loads a texture from the stream - /// - Texture2d LoadTexture(Stream stream); - - /// - /// Loads a texture from the BitmapBuffer - /// - Texture2d LoadTexture(BitmapBuffer buffer); - - /// - /// Loads a texture from the System.Drawing.Bitmap - /// - Texture2d LoadTexture(Bitmap bitmap); - /// /// sets the viewport (and scissor) according to the provided specifications /// void SetViewport(int x, int y, int width, int height); - /// - /// sets the viewport (and scissor) according to the provided specifications - /// - void SetViewport(int width, int height); - -#if false // Unused and WinForms unavailable on .NET Standard - /// - /// sets the viewport (and scissor) according to the client area of the provided control - /// - void SetViewport(System.Windows.Forms.Control control); -#endif - - /// - /// sets the viewport (and scissor) according to the provided specifications - /// - void SetViewport(Size size); - /// /// generates a proper 2d othographic projection for the given destination size, suitable for use in a GUI /// - Matrix4x4 CreateGuiProjectionMatrix(int w, int h); - - /// - /// generates a proper 2d othographic projection for the given destination size, suitable for use in a GUI - /// - Matrix4x4 CreateGuiProjectionMatrix(Size dims); + Matrix4x4 CreateGuiProjectionMatrix(int width, int height); /// /// generates a proper view transform for a standard 2d ortho projection, including half-pixel jitter if necessary and /// re-establishing of a normal 2d graphics top-left origin. suitable for use in a GUI /// - Matrix4x4 CreateGuiViewMatrix(int w, int h, bool autoflip = true); - - /// - /// generates a proper view transform for a standard 2d ortho projection, including half-pixel jitter if necessary and - /// re-establishing of a normal 2d graphics top-left origin. suitable for use in a GUI - /// - Matrix4x4 CreateGuiViewMatrix(Size dims, bool autoflip = true); + Matrix4x4 CreateGuiViewMatrix(int width, int height, bool autoflip = true); /// /// Creates a render target. Only includes a color buffer. Pixel format control TBD /// - RenderTarget CreateRenderTarget(int w, int h); + RenderTarget CreateRenderTarget(int width, int height); /// /// Binds a RenderTarget for current rendering /// void BindRenderTarget(RenderTarget rt); - /// - /// Returns a string representing the API employed by this context - /// - string API { get; } - /// /// Frees the provided render target. Same as disposing the resource. /// diff --git a/src/BizHawk.Bizware.Graphics/D3D11/IGL_D3D11.cs b/src/BizHawk.Bizware.Graphics/D3D11/IGL_D3D11.cs index 09c732adb9..ad078213dc 100644 --- a/src/BizHawk.Bizware.Graphics/D3D11/IGL_D3D11.cs +++ b/src/BizHawk.Bizware.Graphics/D3D11/IGL_D3D11.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Drawing; -using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Numerics; @@ -16,7 +15,6 @@ using Vortice.Direct3D11; using Vortice.Direct3D11.Shader; using Vortice.DXGI; -// todo - do a better job selecting shader model? base on caps somehow? try several and catch compilation exceptions (yuck, exceptions) namespace BizHawk.Bizware.Graphics { /// @@ -159,8 +157,6 @@ namespace BizHawk.Bizware.Graphics private readonly HashSet _pixelShaders = new(); private readonly HashSet _pipelines = new(); - public string API => "D3D11"; - public IGL_D3D11() { if (OSTailoredCode.IsUnixHost) @@ -974,18 +970,6 @@ namespace BizHawk.Bizware.Graphics tw.LinearFiltering = linear; } - public Texture2d LoadTexture(Bitmap bitmap) - { - using var bmp = new BitmapBuffer(bitmap, new()); - return LoadTexture(bmp); - } - - public Texture2d LoadTexture(Stream stream) - { - using var bmp = new BitmapBuffer(stream, new()); - return LoadTexture(bmp); - } - private ID3D11Texture2D CreateTextureForShader(int width, int height) { return Device.CreateTexture2D( @@ -1015,7 +999,6 @@ namespace BizHawk.Bizware.Graphics return null; } - /// GDI+ call returned unexpected data public unsafe void LoadTextureData(Texture2d tex, BitmapBuffer bmp) { if (bmp.Width != tex.IntWidth || bmp.Height != tex.IntHeight) @@ -1057,13 +1040,6 @@ namespace BizHawk.Bizware.Graphics } } - public Texture2d LoadTexture(BitmapBuffer bmp) - { - var ret = CreateTexture(bmp.Width, bmp.Height); - LoadTextureData(ret, bmp); - return ret; - } - /// Vortice call returned unexpected data public BitmapBuffer ResolveTexture2d(Texture2d tex) { @@ -1111,32 +1087,20 @@ namespace BizHawk.Bizware.Graphics } } - public Texture2d LoadTexture(string path) - { - using var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); - return LoadTexture(fs); - } - - public Matrix4x4 CreateGuiProjectionMatrix(int w, int h) - => CreateGuiProjectionMatrix(new(w, h)); - - public Matrix4x4 CreateGuiViewMatrix(int w, int h, bool autoFlip) - => CreateGuiViewMatrix(new(w, h), autoFlip); - - public Matrix4x4 CreateGuiProjectionMatrix(Size dims) + public Matrix4x4 CreateGuiProjectionMatrix(int width, int height) { var ret = Matrix4x4.Identity; - ret.M11 = 2.0f / dims.Width; - ret.M22 = 2.0f / dims.Height; + ret.M11 = 2.0f / width; + ret.M22 = 2.0f / height; return ret; } - public Matrix4x4 CreateGuiViewMatrix(Size dims, bool autoFlip) + public Matrix4x4 CreateGuiViewMatrix(int width, int height, bool autoFlip) { var ret = Matrix4x4.Identity; ret.M22 = -1.0f; - ret.M41 = -dims.Width * 0.5f; - ret.M42 = dims.Height * 0.5f; + ret.M41 = width * -0.5f; + ret.M42 = height * 0.5f; // auto-flipping isn't needed on D3D return ret; @@ -1148,12 +1112,6 @@ namespace BizHawk.Bizware.Graphics Context.RSSetScissorRect(x, y, width, height); } - public void SetViewport(int width, int height) - => SetViewport(0, 0, width, height); - - public void SetViewport(Size size) - => SetViewport(size.Width, size.Height); - public void FreeRenderTarget(RenderTarget rt) { var rw = (RenderTargetWrapper)rt.Opaque; @@ -1176,13 +1134,13 @@ namespace BizHawk.Bizware.Graphics cpuAccessFlags: CpuAccessFlags.None); } - public RenderTarget CreateRenderTarget(int w, int h) + public RenderTarget CreateRenderTarget(int width, int height) { - var tex = CreateTextureForRenderTarget(w, h); + var tex = CreateTextureForRenderTarget(width, height); var srvd = new ShaderResourceViewDescription(ShaderResourceViewDimension.Texture2D, Format.B8G8R8A8_UNorm, mostDetailedMip: 0, mipLevels: 1); var srv = Device.CreateShaderResourceView(tex, srvd); var tw = new TextureWrapper { Texture = tex, SRV = srv }; - var tex2d = new Texture2d(this, tw, w, h); + var tex2d = new Texture2d(this, tw, width, height); var rtvd = new RenderTargetViewDescription(RenderTargetViewDimension.Texture2D, Format.B8G8R8A8_UNorm); var rw = new RenderTargetWrapper { RTV = Device.CreateRenderTargetView(tw.Texture, rtvd) }; @@ -1264,13 +1222,5 @@ namespace BizHawk.Bizware.Graphics Context.Draw(count, 0); } - - public void BeginScene() - { - } - - public void EndScene() - { - } } } diff --git a/src/BizHawk.Bizware.Graphics/GDIPlus/IGL_GDIPlus.cs b/src/BizHawk.Bizware.Graphics/GDIPlus/IGL_GDIPlus.cs index 94598e05b0..b5ece3b511 100644 --- a/src/BizHawk.Bizware.Graphics/GDIPlus/IGL_GDIPlus.cs +++ b/src/BizHawk.Bizware.Graphics/GDIPlus/IGL_GDIPlus.cs @@ -1,5 +1,4 @@ using System; -using System.IO; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; @@ -24,8 +23,6 @@ namespace BizHawk.Bizware.Graphics public void ClearColor(Color color) => GetCurrentGraphics().Clear(color); - public string API => "GDIPLUS"; - public void FreeTexture(Texture2d tex) { var gtex = (GDIPlusTexture)tex.Opaque; @@ -116,21 +113,12 @@ namespace BizHawk.Bizware.Graphics public void SetTextureFilter(Texture2d texture, bool linear) => ((GDIPlusTexture) texture.Opaque).LinearFiltering = linear; - public Texture2d LoadTexture(Bitmap bitmap) - { - var sdBitmap = (Bitmap)bitmap.Clone(); - var gtex = new GDIPlusTexture { SDBitmap = sdBitmap }; - return new(this, gtex, bitmap.Width, bitmap.Height); - } - - public Texture2d LoadTexture(Stream stream) - { - using var bmp = new BitmapBuffer(stream, new()); - return LoadTexture(bmp); - } - public Texture2d CreateTexture(int width, int height) - => null; + { + var sdBitmap = new Bitmap(width, height); + var gtex = new GDIPlusTexture { SDBitmap = sdBitmap }; + return new(this, gtex, width, height); + } public Texture2d WrapGLTexture2d(IntPtr glTexId, int width, int height) { @@ -144,14 +132,6 @@ namespace BizHawk.Bizware.Graphics bmp.ToSysdrawingBitmap(gtex.SDBitmap); } - public Texture2d LoadTexture(BitmapBuffer bmp) - { - // definitely needed (by TextureFrugalizer at least) - var sdBitmap = bmp.ToSysdrawingBitmap(); - var gtex = new GDIPlusTexture { SDBitmap = sdBitmap }; - return new(this, gtex, bmp.Width, bmp.Height); - } - public BitmapBuffer ResolveTexture2d(Texture2d tex) { var gtex = (GDIPlusTexture)tex.Opaque; @@ -164,29 +144,13 @@ namespace BizHawk.Bizware.Graphics return bb; } - public Texture2d LoadTexture(string path) - { - using var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); - return LoadTexture(fs); - } - - public Matrix4x4 CreateGuiProjectionMatrix(int w, int h) - { - return CreateGuiProjectionMatrix(new(w, h)); - } - - public Matrix4x4 CreateGuiViewMatrix(int w, int h, bool autoFlip) - { - return CreateGuiViewMatrix(new(w, h), autoFlip); - } - - public Matrix4x4 CreateGuiProjectionMatrix(Size dims) + public Matrix4x4 CreateGuiProjectionMatrix(int width, int height) { // see CreateGuiViewMatrix for more return Matrix4x4.Identity; } - public Matrix4x4 CreateGuiViewMatrix(Size dims, bool autoFlip) + public Matrix4x4 CreateGuiViewMatrix(int width, int height, bool autoFlip) { // on account of gdi+ working internally with a default view exactly like we want, we don't need to setup a new one here // furthermore, we _cant_, without inverting the GuiView and GuiProjection before drawing, to completely undo it @@ -198,39 +162,19 @@ namespace BizHawk.Bizware.Graphics { } - public void SetViewport(int width, int height) - { - } - - public void SetViewport(Size size) - { - SetViewport(size.Width, size.Height); - } - - public void BeginScene() - { - } - - public void EndScene() - { - // maybe an inconsistent semantic with other implementations.. - // but accomplishes the needed goal of getting the current RT to render - BindRenderTarget(null); - } - public void FreeRenderTarget(RenderTarget rt) { var grt = (GDIPlusRenderTarget)rt.Opaque; grt.Dispose(); } - public RenderTarget CreateRenderTarget(int w, int h) + public RenderTarget CreateRenderTarget(int width, int height) { var gtex = new GDIPlusTexture { - SDBitmap = new(w, h, PixelFormat.Format32bppArgb) + SDBitmap = new(width, height, PixelFormat.Format32bppArgb) }; - var tex = new Texture2d(this, gtex, w, h); + var tex = new Texture2d(this, gtex, width, height); var grt = new GDIPlusRenderTarget(() => BufferedGraphicsContext); var rt = new RenderTarget(this, grt, tex); diff --git a/src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs b/src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs index 8f3cafd973..e7514e418e 100644 --- a/src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs +++ b/src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs @@ -10,7 +10,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; -using System.IO; using System.Linq; using System.Numerics; @@ -38,8 +37,6 @@ namespace BizHawk.Bizware.Graphics private Pipeline _currPipeline; private RenderTarget _currRenderTarget; - public string API => "OPENGL"; - // this IGL either requires at least OpenGL 3.0 public static bool Available => OpenGLVersion.SupportsVersion(3, 0); @@ -53,14 +50,6 @@ namespace BizHawk.Bizware.Graphics GL = GL.GetApi(SDL2OpenGLContext.GetGLProcAddress); } - public void BeginScene() - { - } - - public void EndScene() - { - } - public void Dispose() { GL.Dispose(); @@ -491,34 +480,22 @@ namespace BizHawk.Bizware.Graphics GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)(linear ? TextureMagFilter.Linear : TextureMagFilter.Nearest)); } - public Texture2d LoadTexture(Bitmap bitmap) + public Texture2d CreateTexture(int width, int height) { - using var bmp = new BitmapBuffer(bitmap, new()); - return LoadTexture(bmp); - } + var texId = GL.GenTexture(); + GL.BindTexture(TextureTarget.Texture2D, texId); + unsafe + { + GL.TexImage2D(TextureTarget.Texture2D, 0, InternalFormat.Rgba8, (uint)width, (uint)height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, null); + } - public Texture2d LoadTexture(Stream stream) - { - using var bmp = new BitmapBuffer(stream, new()); - return LoadTexture(bmp); - } - - private uint GenTexture() - { - var id = GL.GenTexture(); // sensible defaults - GL.BindTexture(TextureTarget.Texture2D, id); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); - return id; - } - public Texture2d CreateTexture(int width, int height) - { - var id = GenTexture(); - return new(this, id, width, height); + return new(this, texId, width, height); } public Texture2d WrapGLTexture2d(IntPtr glTexId, int width, int height) @@ -545,13 +522,11 @@ namespace BizHawk.Bizware.Graphics } /// framebuffer creation unsuccessful - public unsafe RenderTarget CreateRenderTarget(int w, int h) + public RenderTarget CreateRenderTarget(int width, int height) { // create a texture for it - var texId = GenTexture(); - var tex = new Texture2d(this, texId, w, h); - - GL.TexImage2D(TextureTarget.Texture2D, 0, InternalFormat.Rgba8, (uint)w, (uint)h, 0, PixelFormat.Bgra, PixelType.UnsignedByte, null); + var tex = CreateTexture(width, height); + var texId = (uint)tex.Opaque; // create the FBO var fbId = GL.GenFramebuffer(); @@ -587,27 +562,6 @@ namespace BizHawk.Bizware.Graphics } } - public unsafe Texture2d LoadTexture(BitmapBuffer bmp) - { - Texture2d ret; - var id = GenTexture(); - try - { - ret = new(this, id, bmp.Width, bmp.Height); - GL.BindTexture(TextureTarget.Texture2D, id); - // picking a color order that matches doesnt seem to help, any. maybe my driver is accelerating it, or maybe it isnt a big deal. but its something to study on another day - GL.TexImage2D(TextureTarget.Texture2D, 0, InternalFormat.Rgba, (uint)bmp.Width, (uint)bmp.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero.ToPointer()); - LoadTextureData(ret, bmp); - } - catch - { - GL.DeleteTexture(id); - throw; - } - - return ret; - } - public unsafe BitmapBuffer ResolveTexture2d(Texture2d tex) { // note - this is dangerous since it changes the bound texture. could we save it? @@ -619,36 +573,20 @@ namespace BizHawk.Bizware.Graphics return bb; } - public Texture2d LoadTexture(string path) - { - using var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); - return LoadTexture(fs); - } - - public Matrix4x4 CreateGuiProjectionMatrix(int w, int h) - { - return CreateGuiProjectionMatrix(new(w, h)); - } - - public Matrix4x4 CreateGuiViewMatrix(int w, int h, bool autoflip) - { - return CreateGuiViewMatrix(new(w, h), autoflip); - } - - public Matrix4x4 CreateGuiProjectionMatrix(Size dims) + public Matrix4x4 CreateGuiProjectionMatrix(int width, int height) { var ret = Matrix4x4.Identity; - ret.M11 = 2.0f / dims.Width; - ret.M22 = 2.0f / dims.Height; + ret.M11 = 2.0f / width; + ret.M22 = 2.0f / height; return ret; } - public Matrix4x4 CreateGuiViewMatrix(Size dims, bool autoflip) + public Matrix4x4 CreateGuiViewMatrix(int width, int height, bool autoflip) { var ret = Matrix4x4.Identity; ret.M22 = -1.0f; - ret.M41 = dims.Width * -0.5f; - ret.M42 = dims.Height * 0.5f; + ret.M41 = width * -0.5f; + ret.M42 = height * 0.5f; if (autoflip && _currRenderTarget is not null) // flip as long as we're not a final render target { ret.M22 = 1.0f; @@ -665,16 +603,6 @@ namespace BizHawk.Bizware.Graphics // BUT ALSO: new specifications.. viewport+scissor make sense together } - public void SetViewport(int width, int height) - { - SetViewport(0, 0, width, height); - } - - public void SetViewport(Size size) - { - SetViewport(size.Width, size.Height); - } - private BizShader CreateShader(ShaderType type, string source, bool required) { var sw = new ShaderWrapper(); diff --git a/src/BizHawk.Bizware.Graphics/Renderers/GuiRenderer.cs b/src/BizHawk.Bizware.Graphics/Renderers/GuiRenderer.cs index 5061db80c0..e6dcc04045 100644 --- a/src/BizHawk.Bizware.Graphics/Renderers/GuiRenderer.cs +++ b/src/BizHawk.Bizware.Graphics/Renderers/GuiRenderer.cs @@ -31,13 +31,14 @@ namespace BizHawk.Bizware.Graphics string psProgram, vsProgram; - switch (owner.API) + // ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault + switch (owner.DispMethodEnum) { - case "D3D11": + case EDispMethod.D3D11: vsProgram = DefaultShader_d3d9; psProgram = DefaultShader_d3d9; break; - case "OPENGL": + case EDispMethod.OpenGL: vsProgram = DefaultVertexShader_gl; psProgram = DefaultPixelShader_gl; break; diff --git a/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs b/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs index c19aeb1839..8e8adf0780 100644 --- a/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs +++ b/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs @@ -865,10 +865,8 @@ namespace BizHawk.Client.Common public void Blank() { ActivateGraphicsControlContext(); - _gl.BeginScene(); _gl.BindRenderTarget(null); _gl.ClearColor(Color.Black); - _gl.EndScene(); SwapBuffersOfGraphicsControl(); } @@ -876,19 +874,12 @@ namespace BizHawk.Client.Common { if (!job.Offscreen) throw new InvalidOperationException(); - // begin rendering on this context - // should this have been done earlier? - // do i need to check this on an intel video card to see if running excessively is a problem? (it used to be in the FinalTarget command below, shouldn't be a problem) - //GraphicsControl.Begin(); // CRITICAL POINT for yabause+GL - //TODO - auto-create and age these (and dispose when old) var rtCounter = 0; // ReSharper disable once AccessToModifiedClosure _currentFilterProgram.RenderTargetProvider = new DisplayManagerRenderTargetProvider(size => _shaderChainFrugalizers[rtCounter++].Get(size)); - _gl.BeginScene(); RunFilterChainSteps(ref rtCounter, out var rtCurr, out _); - _gl.EndScene(); job.OffscreenBb = rtCurr.Texture2d.Resolve(); job.OffscreenBb.DiscardAlpha(); diff --git a/src/BizHawk.Client.Common/DisplayManager/Filters/Retro.cs b/src/BizHawk.Client.Common/DisplayManager/Filters/Retro.cs index b36a8e2d2f..68bf770942 100644 --- a/src/BizHawk.Client.Common/DisplayManager/Filters/Retro.cs +++ b/src/BizHawk.Client.Common/DisplayManager/Filters/Retro.cs @@ -45,9 +45,9 @@ namespace BizHawk.Client.Common.Filters Passes = preset.Passes.ToArray(); Errors = string.Empty; - if (owner.API is not ("OPENGL" or "D3D11")) + if (owner.DispMethodEnum is not (EDispMethod.OpenGL or EDispMethod.D3D11)) { - Errors = $"Unsupported API {owner.API}"; + Errors = $"Unsupported Display Method {owner.DispMethodEnum}"; return; } @@ -67,11 +67,12 @@ namespace BizHawk.Client.Common.Filters if (!File.Exists(path)) { - path = owner.API switch + // ReSharper disable once SwitchExpressionHandlesSomeKnownEnumValuesWithExceptionInDefault + path = owner.DispMethodEnum switch { - "OPENGL" => Path.ChangeExtension(path, ".glsl"), - "D3D11" => Path.ChangeExtension(path, ".hlsl"), - _ => throw new InvalidOperationException(), + EDispMethod.OpenGL => Path.ChangeExtension(path, ".glsl"), + EDispMethod.D3D11 => Path.ChangeExtension(path, ".hlsl"), + _ => throw new InvalidOperationException() }; } } diff --git a/src/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs b/src/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs index 92d084336b..8af02403a8 100644 --- a/src/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs +++ b/src/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs @@ -91,18 +91,11 @@ namespace BizHawk.Client.EmuHawk } } - // begin rendering on this context - // should this have been done earlier? - // do i need to check this on an intel video card to see if running excessively is a problem? (it used to be in the FinalTarget command below, shouldn't be a problem) - //TODO - auto-create and age these (and dispose when old) int rtCounter = 0; - _currentFilterProgram.RenderTargetProvider = new DisplayManagerRenderTargetProvider(size => _shaderChainFrugalizers[rtCounter++].Get(size)); - _gl.BeginScene(); RunFilterChainSteps(ref rtCounter, out var rtCurr, out var inFinalTarget); - _gl.EndScene(); if (job.Offscreen) {