From 60022ab1463d843811a93b29bac0fa9e53d43e77 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Fri, 27 Nov 2020 00:50:25 +1000 Subject: [PATCH] Move OpenTK configuration to dedicated static ctor --- .../OpenTKConfigurator.cs | 22 +++++++++++++++++++ src/BizHawk.Bizware.DirectX/IGL_SlimDX9.cs | 2 ++ .../GraphicsImplementations/IGL_TK.cs | 11 ++-------- 3 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 src/BizHawk.Bizware.BizwareGL/OpenTKConfigurator.cs diff --git a/src/BizHawk.Bizware.BizwareGL/OpenTKConfigurator.cs b/src/BizHawk.Bizware.BizwareGL/OpenTKConfigurator.cs new file mode 100644 index 0000000000..1ddc53bc1e --- /dev/null +++ b/src/BizHawk.Bizware.BizwareGL/OpenTKConfigurator.cs @@ -0,0 +1,22 @@ +using System; + +using OpenTK; + +namespace BizHawk.Bizware.BizwareGL +{ + public static class OpenTKConfigurator + { + static OpenTKConfigurator() + { + // make sure OpenTK initializes without getting wrecked on the SDL check and throwing an exception to annoy our MDA's + var toolkitOptions = ToolkitOptions.Default; + toolkitOptions.Backend = PlatformBackend.PreferNative; + Toolkit.Init(toolkitOptions); + // NOTE: this throws EGL exceptions anyway. I'm going to ignore it and whine about it later + // still seeing the exception in VS as of 2.5.3 dev... --yoshi + } + + /// no-op; this class' static ctor is guaranteed to be called exactly once if this is called at least once + public static void EnsureConfigurated() {} + } +} diff --git a/src/BizHawk.Bizware.DirectX/IGL_SlimDX9.cs b/src/BizHawk.Bizware.DirectX/IGL_SlimDX9.cs index 961d8b8220..80f7be5747 100644 --- a/src/BizHawk.Bizware.DirectX/IGL_SlimDX9.cs +++ b/src/BizHawk.Bizware.DirectX/IGL_SlimDX9.cs @@ -38,6 +38,8 @@ namespace BizHawk.Bizware.DirectX _d3d = new Direct3D(); } + OpenTKConfigurator.EnsureConfigurated(); + // make an 'offscreen context' so we can at least do things without having to create a window _offscreenNativeWindow = new NativeWindow { ClientSize = new Size(8, 8) }; diff --git a/src/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_TK.cs b/src/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_TK.cs index fbaee47271..d625bd956c 100644 --- a/src/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_TK.cs +++ b/src/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_TK.cs @@ -34,15 +34,6 @@ namespace BizHawk.Client.EmuHawk private Pipeline _currPipeline; private RenderTarget _currRenderTarget; - static IGL_TK() - { - //make sure OpenTK initializes without getting wrecked on the SDL check and throwing an exception to annoy our MDA's - var toolkitOptions = global::OpenTK.ToolkitOptions.Default; - toolkitOptions.Backend = PlatformBackend.PreferNative; - global::OpenTK.Toolkit.Init(toolkitOptions); - //NOTE: this throws EGL exceptions anyway. I'm going to ignore it and whine about it later - } - public string API => "OPENGL"; public int Version @@ -66,6 +57,8 @@ namespace BizHawk.Client.EmuHawk public IGL_TK(int majorVersion, int minorVersion, bool forwardCompatible) { + OpenTKConfigurator.EnsureConfigurated(); + //make an 'offscreen context' so we can at least do things without having to create a window OffscreenNativeWindow = new NativeWindow { ClientSize = new sd.Size(8, 8) }; GraphicsContext = new GraphicsContext(GraphicsMode.Default, OffscreenNativeWindow.WindowInfo, majorVersion, minorVersion, forwardCompatible ? GraphicsContextFlags.ForwardCompatible : GraphicsContextFlags.Default);