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 System;
using BizHawk.Bizware.BizwareGL; using BizHawk.Bizware.BizwareGL;
using BizHawk.Bizware.BizwareGL.Drivers.OpenTK;
using BizHawk.Bizware.BizwareGL.Drivers.SlimDX;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
@ -11,7 +12,6 @@ namespace BizHawk.Client.EmuHawk
{ {
private GLManager() private GLManager()
{ {
} }
public void Dispose() public void Dispose()
@ -20,28 +20,26 @@ namespace BizHawk.Client.EmuHawk
public static GLManager Instance { get; private set; } public static GLManager Instance { get; private set; }
Bizware.BizwareGL.Drivers.OpenTK.IGL_TK MainContext; public static void CreateInstance()
public static void CreateInstance(Bizware.BizwareGL.Drivers.OpenTK.IGL_TK mainContext)
{ {
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 = new GLManager();
Instance.MainContext = mainContext;
} }
public void ReleaseGLContext(object o) public void ReleaseGLContext(object o)
{ {
ContextRef cr = (ContextRef)o; var cr = (ContextRef)o;
cr.gl.Dispose(); cr.GL.Dispose();
} }
//[System.Runtime.InteropServices.DllImport("opengl32.dll")] public ContextRef CreateGLContext(int majorVersion, int minorVersion, bool forwardCompatible)
//bool wglShareLists(IntPtr hglrc1, IntPtr hglrc2);
public ContextRef CreateGLContext(int major_version, int minor_version, bool forward_compatible)
{ {
var gl = new Bizware.BizwareGL.Drivers.OpenTK.IGL_TK(major_version, minor_version, forward_compatible); var gl = new IGL_TK(majorVersion, minorVersion, forwardCompatible);
var ret = new ContextRef { gl = gl }; var ret = new ContextRef { GL = gl };
return ret; return ret;
} }
@ -49,27 +47,16 @@ namespace BizHawk.Client.EmuHawk
{ {
return new ContextRef return new ContextRef
{ {
gc = gc, Gc = gc,
gl = gc.IGL GL = gc.IGL
}; };
} }
/// <summary> private ContextRef _activeContext;
/// 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;
public void Invalidate() public void Invalidate()
{ {
ActiveContext = null; _activeContext = null;
} }
public void Activate(ContextRef cr) public void Activate(ContextRef cr)
@ -77,26 +64,32 @@ namespace BizHawk.Client.EmuHawk
bool begun = false; bool begun = false;
//this needs a begin signal to set the swap chain to the next backbuffer //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; begun = true;
} }
if (cr == ActiveContext) if (cr == _activeContext)
{
return; return;
}
ActiveContext = cr; _activeContext = cr;
if (cr.gc != null) 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 //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) if (!begun)
cr.gc.Begin(); {
cr.Gc.Begin();
}
} }
else if (cr.gl != null) else
{ {
if(cr.gl is BizHawk.Bizware.BizwareGL.Drivers.OpenTK.IGL_TK) if (cr.GL is IGL_TK tk)
((BizHawk.Bizware.BizwareGL.Drivers.OpenTK.IGL_TK)cr.gl).MakeDefaultCurrent(); {
tk.MakeDefaultCurrent();
}
} }
} }
@ -107,8 +100,8 @@ namespace BizHawk.Client.EmuHawk
public class ContextRef public class ContextRef
{ {
public IGL gl; public IGL GL { get; set; }
public GraphicsControl gc; 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); 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 // 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; 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 //now create the "GL" context for the display method. we can reuse the IGL_TK context if opengl display method is chosen
REDO_DISPMETHOD: REDO_DISPMETHOD:
if (Global.Config.DispMethod == Config.EDispMethod.GdiPlus) if (Global.Config.DispMethod == Config.EDispMethod.GdiPlus)
{
GlobalWin.GL = new Bizware.BizwareGL.Drivers.GdiPlus.IGL_GdiPlus(); GlobalWin.GL = new Bizware.BizwareGL.Drivers.GdiPlus.IGL_GdiPlus();
}
else if (Global.Config.DispMethod == Config.EDispMethod.SlimDX9) else if (Global.Config.DispMethod == Config.EDispMethod.SlimDX9)
{ {
try try
@ -172,7 +174,7 @@ namespace BizHawk.Client.EmuHawk
{ {
GlobalWin.GL = GlobalWin.IGL_GL; 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) if (GlobalWin.IGL_GL.Version < 200)
{ {
// fallback // 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/=automagically/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=autorestore/@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/=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/=backcolor/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Bezier/@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> <s:Boolean x:Key="/Default/UserDictionary/Words/=bilinear/@EntryIndexedValue">True</s:Boolean>