simplify and cleanup GLManager

This commit is contained in:
adelikat 2019-12-21 12:03:16 -06:00
parent b5090b5a63
commit b93b4e449a
3 changed files with 40 additions and 44 deletions

View File

@ -1,6 +1,7 @@
using System;
using BizHawk.Bizware.BizwareGL;
using BizHawk.Bizware.BizwareGL.Drivers.OpenTK;
using BizHawk.Bizware.BizwareGL.Drivers.SlimDX;
namespace BizHawk.Client.EmuHawk
{
@ -11,7 +12,6 @@ namespace BizHawk.Client.EmuHawk
{
private GLManager()
{
}
public void Dispose()
@ -20,28 +20,26 @@ namespace BizHawk.Client.EmuHawk
public static GLManager Instance { get; private set; }
Bizware.BizwareGL.Drivers.OpenTK.IGL_TK MainContext;
public static void CreateInstance(Bizware.BizwareGL.Drivers.OpenTK.IGL_TK mainContext)
public static void CreateInstance()
{
if (Instance != null) throw new InvalidOperationException($"Attempted to create more than one {nameof(GLManager)}");
if (Instance != null)
{
throw new InvalidOperationException($"Attempted to create more than one {nameof(GLManager)}");
}
Instance = new GLManager();
Instance.MainContext = mainContext;
}
public void ReleaseGLContext(object o)
{
ContextRef cr = (ContextRef)o;
cr.gl.Dispose();
var cr = (ContextRef)o;
cr.GL.Dispose();
}
//[System.Runtime.InteropServices.DllImport("opengl32.dll")]
//bool wglShareLists(IntPtr hglrc1, IntPtr hglrc2);
public ContextRef CreateGLContext(int major_version, int minor_version, bool forward_compatible)
public ContextRef CreateGLContext(int majorVersion, int minorVersion, bool forwardCompatible)
{
var gl = new Bizware.BizwareGL.Drivers.OpenTK.IGL_TK(major_version, minor_version, forward_compatible);
var ret = new ContextRef { gl = gl };
var gl = new IGL_TK(majorVersion, minorVersion, forwardCompatible);
var ret = new ContextRef { GL = gl };
return ret;
}
@ -49,27 +47,16 @@ namespace BizHawk.Client.EmuHawk
{
return new ContextRef
{
gc = gc,
gl = gc.IGL
Gc = gc,
GL = gc.IGL
};
}
/// <summary>
/// This might not be a GL implementation. If it isnt GL, then setting it as active context is just NOP
/// </summary>
public ContextRef GetContextForIGL(IGL gl)
{
return new ContextRef
{
gl = gl
};
}
ContextRef ActiveContext;
private ContextRef _activeContext;
public void Invalidate()
{
ActiveContext = null;
_activeContext = null;
}
public void Activate(ContextRef cr)
@ -77,26 +64,32 @@ namespace BizHawk.Client.EmuHawk
bool begun = false;
//this needs a begin signal to set the swap chain to the next backbuffer
if (cr.gl is BizHawk.Bizware.BizwareGL.Drivers.SlimDX.IGL_SlimDX9)
if (cr.GL is IGL_SlimDX9)
{
cr.gc.Begin();
cr.Gc.Begin();
begun = true;
}
if (cr == ActiveContext)
if (cr == _activeContext)
{
return;
}
ActiveContext = cr;
if (cr.gc != null)
_activeContext = cr;
if (cr.Gc != null)
{
//TODO - this is checking the current context inside to avoid an extra NOP context change. make this optional or remove it, since we're tracking it here
if(!begun)
cr.gc.Begin();
}
else if (cr.gl != null)
if (!begun)
{
if(cr.gl is BizHawk.Bizware.BizwareGL.Drivers.OpenTK.IGL_TK)
((BizHawk.Bizware.BizwareGL.Drivers.OpenTK.IGL_TK)cr.gl).MakeDefaultCurrent();
cr.Gc.Begin();
}
}
else
{
if (cr.GL is IGL_TK tk)
{
tk.MakeDefaultCurrent();
}
}
}
@ -107,8 +100,8 @@ namespace BizHawk.Client.EmuHawk
public class ContextRef
{
public IGL gl;
public GraphicsControl gc;
public IGL GL { get; set; }
public GraphicsControl Gc { get; set; }
}
}
}

View File

@ -146,13 +146,15 @@ namespace BizHawk.Client.EmuHawk
GlobalWin.IGL_GL = new Bizware.BizwareGL.Drivers.OpenTK.IGL_TK(2, 0, false);
// setup the GL context manager, needed for coping with multiple opengl cores vs opengl display method
GLManager.CreateInstance(GlobalWin.IGL_GL);
GLManager.CreateInstance();
GlobalWin.GLManager = GLManager.Instance;
//now create the "GL" context for the display method. we can reuse the IGL_TK context if opengl display method is chosen
REDO_DISPMETHOD:
if (Global.Config.DispMethod == Config.EDispMethod.GdiPlus)
{
GlobalWin.GL = new Bizware.BizwareGL.Drivers.GdiPlus.IGL_GdiPlus();
}
else if (Global.Config.DispMethod == Config.EDispMethod.SlimDX9)
{
try
@ -172,7 +174,7 @@ namespace BizHawk.Client.EmuHawk
{
GlobalWin.GL = GlobalWin.IGL_GL;
// check the opengl version and dont even try to boot this crap up if its too old
// check the opengl version and don't even try to boot this crap up if its too old
if (GlobalWin.IGL_GL.Version < 200)
{
// fallback

View File

@ -190,6 +190,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=automagically/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=autorestore/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Autosave/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=backbuffer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=backcolor/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Bezier/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=bilinear/@EntryIndexedValue">True</s:Boolean>