From 516a021add659514250056d8b7b995f1114fba0f Mon Sep 17 00:00:00 2001 From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> Date: Sun, 25 Aug 2024 17:37:41 -0700 Subject: [PATCH] Try making this actually work --- .../Controls/OpenGLControl.cs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/BizHawk.Bizware.Graphics.Controls/Controls/OpenGLControl.cs b/src/BizHawk.Bizware.Graphics.Controls/Controls/OpenGLControl.cs index f0d0b03320..1d5e4f6e02 100644 --- a/src/BizHawk.Bizware.Graphics.Controls/Controls/OpenGLControl.cs +++ b/src/BizHawk.Bizware.Graphics.Controls/Controls/OpenGLControl.cs @@ -9,7 +9,28 @@ namespace BizHawk.Bizware.Graphics.Controls // workaround a bug with proprietary Nvidia drivers resulting in some BadMatch on setting context to current // seems they don't like whatever depth values mono's winforms ends up setting // mono's winforms seems to try to copy from the "parent" window, so we need to create a "friendly" window - private static readonly Lazy _x11GLParent = new(() => SDL2OpenGLContext.CreateDummyX11ParentWindow(3, 2, true)); + private static readonly Lazy _x11GLParent = new(() => + { + // ugh, i hate this, seems just returning an x11 window handle is not good enough (unlike on windows where handing some native HWND is good enough) + // instead it has to have been created with mono's internal "Hwnd" class + var hwnd = typeof(Control).Assembly.CreateInstance("System.Windows.Forms.Hwnd"); + if (hwnd == null) + { + Console.WriteLine("Couldn't find System.Windows.Forms.Hwnd"); + return IntPtr.Zero; + } + + var clientWindowProp = hwnd.GetType().GetProperty("ClientWindow"); + if (clientWindowProp == null) + { + Console.WriteLine("Couldn't find ClientWindow prop"); + return IntPtr.Zero; + } + + var x11Window = SDL2OpenGLContext.CreateDummyX11ParentWindow(3, 2, true); + clientWindowProp.SetValue(hwnd, x11Window); + return x11Window; + }); private readonly Action _initGLState; private SDL2OpenGLContext _context;