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
src
BizHawk.Bizware.Graphics/OpenGL
BizHawk.Client.Common/DisplayManager
BizHawk.Client.EmuHawk

View File

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

View File

@ -1,6 +1,8 @@
using System;
using System.Runtime.InteropServices;
using Silk.NET.OpenGL.Legacy;
using static SDL2.SDL;
namespace BizHawk.Bizware.Graphics
@ -40,9 +42,6 @@ namespace BizHawk.Bizware.Graphics
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(() =>
{
var prevWindow = SDL_GL_GetCurrentWindow();
@ -52,21 +51,8 @@ namespace BizHawk.Bizware.Graphics
{
using (new SDL2OpenGLContext(2, 0, false))
{
var getStringFp = GetGLProcAddress("glGetString");
if (getStringFp == IntPtr.Zero) // uhhh?
{
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);
using var gl = GL.GetApi(GetGLProcAddress);
var versionString = gl.GetStringS(StringName.Version);
var versionParts = versionString!.Split('.');
var major = int.Parse(versionParts[0]);
var minor = int.Parse(versionParts[1][0].ToString());

View File

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

View File

@ -36,7 +36,7 @@ namespace BizHawk.Client.EmuHawk
_getIsSecondaryThrottlingDisabled = getIsSecondaryThrottlingDisabled;
}
public override void ActivateOpenGLContext()
public void ActivateOpenGLContext()
{
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();
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:
case EDispMethod.GdiPlus:
static GLControlWrapper_GdiPlus CreateGLControlWrapper(IGL_GdiPlus self) => new(self); // inlining as lambda causes crash, don't wanna know why --yoshi