fix minor oopsies / dumbs with previous commit

This commit is contained in:
CasualPokePlayer 2023-07-23 02:16:24 -07:00
parent 8ae947fed7
commit bed66e2cd4
5 changed files with 14 additions and 29 deletions

View File

@ -53,13 +53,9 @@ namespace BizHawk.Bizware.Graphics
_minorVersion = minorVersion; _minorVersion = minorVersion;
_forwardCompatible = forwardCompatible; _forwardCompatible = forwardCompatible;
// we need an active context in order to acquire these functions // the loading of symbols is delayed until actual use, so no need to create a context now
// technically, they could be different between contexts // if you want to do offscreen work with this GL make a dummy control or an SDL2OpenGLContext
// but with the exact same requested version and config that is highly unlikely in practice GL = GL.GetApi(SDL2OpenGLContext.GetGLProcAddress);
using (new SDL2OpenGLContext(majorVersion, minorVersion, forwardCompatible))
{
GL = GL.GetApi(SDL2OpenGLContext.GetGLProcAddress);
}
// misc initialization // misc initialization
CreateRenderStates(); CreateRenderStates();
@ -75,6 +71,7 @@ namespace BizHawk.Bizware.Graphics
public void Dispose() public void Dispose()
{ {
GL.Dispose();
} }
public void Clear(BizClearBufferMask mask) public void Clear(BizClearBufferMask mask)

View File

@ -1,6 +1,8 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Silk.NET.OpenGL.Legacy;
using static SDL2.SDL; using static SDL2.SDL;
namespace BizHawk.Bizware.Graphics namespace BizHawk.Bizware.Graphics
@ -40,9 +42,6 @@ namespace BizHawk.Bizware.Graphics
SDL_SetHint(SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL, "1"); SDL_SetHint(SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL, "1");
} }
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
private delegate IntPtr glGetStringDelegate(int name);
private static readonly Lazy<int> _version = new(() => private static readonly Lazy<int> _version = new(() =>
{ {
var prevWindow = SDL_GL_GetCurrentWindow(); var prevWindow = SDL_GL_GetCurrentWindow();
@ -52,21 +51,8 @@ namespace BizHawk.Bizware.Graphics
{ {
using (new SDL2OpenGLContext(2, 0, false)) using (new SDL2OpenGLContext(2, 0, false))
{ {
var getStringFp = GetGLProcAddress("glGetString"); using var gl = GL.GetApi(GetGLProcAddress);
if (getStringFp == IntPtr.Zero) // uhhh? var versionString = gl.GetStringS(StringName.Version);
{
return 0;
}
var getStringFunc = Marshal.GetDelegateForFunctionPointer<glGetStringDelegate>(getStringFp);
const int GL_VERSION = 0x1F02;
var version = getStringFunc(GL_VERSION);
if (version == IntPtr.Zero)
{
return 0;
}
var versionString = Marshal.PtrToStringAnsi(version);
var versionParts = versionString!.Split('.'); var versionParts = versionString!.Split('.');
var major = int.Parse(versionParts[0]); var major = int.Parse(versionParts[0]);
var minor = int.Parse(versionParts[1][0].ToString()); var minor = int.Parse(versionParts[1][0].ToString());

View File

@ -196,8 +196,6 @@ namespace BizHawk.Client.Common
private RetroShaderChain _shaderChainUser; private RetroShaderChain _shaderChainUser;
public virtual void ActivateOpenGLContext() => throw new NotImplementedException();
protected virtual void ActivateGraphicsControlContext() => throw new NotImplementedException(); protected virtual void ActivateGraphicsControlContext() => throw new NotImplementedException();
protected virtual void SwapBuffersOfGraphicsControl() => throw new NotImplementedException(); protected virtual void SwapBuffersOfGraphicsControl() => throw new NotImplementedException();

View File

@ -36,7 +36,7 @@ namespace BizHawk.Client.EmuHawk
_getIsSecondaryThrottlingDisabled = getIsSecondaryThrottlingDisabled; _getIsSecondaryThrottlingDisabled = getIsSecondaryThrottlingDisabled;
} }
public override void ActivateOpenGLContext() public void ActivateOpenGLContext()
{ {
if (_gl.DispMethodEnum == EDispMethod.OpenGL) if (_gl.DispMethodEnum == EDispMethod.OpenGL)
{ {

View File

@ -233,7 +233,11 @@ namespace BizHawk.Client.EmuHawk
new ExceptionBox(new Exception($"Initialization of OpenGL Display Method failed; falling back to {fallback.Name}")).ShowDialog(); new ExceptionBox(new Exception($"Initialization of OpenGL Display Method failed; falling back to {fallback.Name}")).ShowDialog();
return TryInitIGL(initialConfig.DispMethod = fallback.Method); return TryInitIGL(initialConfig.DispMethod = fallback.Method);
} }
return CheckRenderer(new IGL_OpenGL(2, 0, false)); // need to have a context active for checking renderer, will be disposed afterwards
using (new SDL2OpenGLContext(2, 0, false))
{
return CheckRenderer(new IGL_OpenGL(2, 0, false));
}
default: default:
case EDispMethod.GdiPlus: case EDispMethod.GdiPlus:
static GLControlWrapper_GdiPlus CreateGLControlWrapper(IGL_GdiPlus self) => new(self); // inlining as lambda causes crash, don't wanna know why --yoshi static GLControlWrapper_GdiPlus CreateGLControlWrapper(IGL_GdiPlus self) => new(self); // inlining as lambda causes crash, don't wanna know why --yoshi