bizwaregl-some simplification and cleanup and reduction of pointless api calls
This commit is contained in:
parent
c922dde1ee
commit
0e88359f1e
|
@ -46,8 +46,7 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
|
||||||
|
|
||||||
public void End()
|
public void End()
|
||||||
{
|
{
|
||||||
//this slows things down too much
|
Owner.MakeDefaultCurrent();
|
||||||
//Owner.MakeDefaultCurrent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public new void SwapBuffers()
|
public new void SwapBuffers()
|
||||||
|
|
|
@ -56,6 +56,7 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
|
||||||
//misc initialization
|
//misc initialization
|
||||||
CreateRenderStates();
|
CreateRenderStates();
|
||||||
GL.Enable(EnableCap.Texture2D);
|
GL.Enable(EnableCap.Texture2D);
|
||||||
|
PurgeStateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IDisposable.Dispose()
|
void IDisposable.Dispose()
|
||||||
|
@ -241,12 +242,12 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
|
||||||
|
|
||||||
unsafe void IGL.BindVertexLayout(VertexLayout layout)
|
unsafe void IGL.BindVertexLayout(VertexLayout layout)
|
||||||
{
|
{
|
||||||
StatePendingVertexLayouts[CurrentContext] = layout;
|
sStatePendingVertexLayout = layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe void IGL.BindArrayData(void* pData)
|
unsafe void IGL.BindArrayData(void* pData)
|
||||||
{
|
{
|
||||||
MyBindArrayData(StatePendingVertexLayouts[CurrentContext], pData);
|
MyBindArrayData(sStatePendingVertexLayout, pData);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IGL.DrawArrays(PrimitiveType mode, int first, int count)
|
void IGL.DrawArrays(PrimitiveType mode, int first, int count)
|
||||||
|
@ -278,9 +279,13 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
|
||||||
void IGL.SetPipelineUniformSampler(PipelineUniform uniform, IntPtr texHandle)
|
void IGL.SetPipelineUniformSampler(PipelineUniform uniform, IntPtr texHandle)
|
||||||
{
|
{
|
||||||
//set the sampler index into the uniform first
|
//set the sampler index into the uniform first
|
||||||
//GL.Uniform1(uniform.Id.ToInt32(), uniform.SamplerIndex);
|
|
||||||
//now bind the texture
|
//now bind the texture
|
||||||
GL.ActiveTexture((TextureUnit)((int)TextureUnit.Texture0 + uniform.SamplerIndex));
|
if(sActiveTexture != uniform.SamplerIndex)
|
||||||
|
{
|
||||||
|
sActiveTexture = uniform.SamplerIndex;
|
||||||
|
var selectedUnit = (TextureUnit)((int)TextureUnit.Texture0 + uniform.SamplerIndex);
|
||||||
|
GL.ActiveTexture(selectedUnit);
|
||||||
|
}
|
||||||
GL.BindTexture(TextureTarget.Texture2D, texHandle.ToInt32());
|
GL.BindTexture(TextureTarget.Texture2D, texHandle.ToInt32());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -437,8 +442,6 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
|
||||||
//---------------
|
//---------------
|
||||||
//my utility methods
|
//my utility methods
|
||||||
|
|
||||||
global::OpenTK.Graphics.IGraphicsContext CurrentContext { get { return global::OpenTK.Graphics.GraphicsContext.CurrentContext; } }
|
|
||||||
|
|
||||||
GLControl CastControl(swf.Control swfControl)
|
GLControl CastControl(swf.Control swfControl)
|
||||||
{
|
{
|
||||||
GLControl glc = swfControl as GLControl;
|
GLControl glc = swfControl as GLControl;
|
||||||
|
@ -471,16 +474,13 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
|
||||||
if(n==0)
|
if(n==0)
|
||||||
throw new InvalidOperationException("Error compiling shader (CompileShader)" + "\r\n\r\n" + resultLog);
|
throw new InvalidOperationException("Error compiling shader (CompileShader)" + "\r\n\r\n" + resultLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary<IGraphicsContext, VertexLayout> StateCurrentVertexLayouts = new Dictionary<IGraphicsContext, VertexLayout>();
|
|
||||||
Dictionary<IGraphicsContext, VertexLayout> StatePendingVertexLayouts = new Dictionary<IGraphicsContext, VertexLayout>();
|
|
||||||
WorkingDictionary<IGraphicsContext, HashSet<int>> VertexAttribEnables = new WorkingDictionary<IGraphicsContext, HashSet<int>>();
|
|
||||||
void UnbindVertexAttributes()
|
void UnbindVertexAttributes()
|
||||||
{
|
{
|
||||||
//HAMNUTS:
|
//HAMNUTS:
|
||||||
//its not clear how many bindings we'll have to disable before we can enable the ones we need..
|
//its not clear how many bindings we'll have to disable before we can enable the ones we need..
|
||||||
//so lets just disable the ones we remember we have bound
|
//so lets just disable the ones we remember we have bound
|
||||||
var currBindings = VertexAttribEnables[CurrentContext];
|
var currBindings = sVertexAttribEnables;
|
||||||
foreach (var index in currBindings)
|
foreach (var index in currBindings)
|
||||||
GL.DisableVertexAttribArray(index);
|
GL.DisableVertexAttribArray(index);
|
||||||
currBindings.Clear();
|
currBindings.Clear();
|
||||||
|
@ -491,8 +491,8 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
|
||||||
UnbindVertexAttributes();
|
UnbindVertexAttributes();
|
||||||
|
|
||||||
//HAMNUTS (continued)
|
//HAMNUTS (continued)
|
||||||
var currBindings = VertexAttribEnables[CurrentContext];
|
var currBindings = sVertexAttribEnables;
|
||||||
StateCurrentVertexLayouts[CurrentContext] = StatePendingVertexLayouts[CurrentContext];
|
sStateCurrentVertexLayout = sStatePendingVertexLayout;
|
||||||
|
|
||||||
foreach (var kvp in layout.Items)
|
foreach (var kvp in layout.Items)
|
||||||
{
|
{
|
||||||
|
@ -504,28 +504,15 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
|
||||||
|
|
||||||
internal void MakeDefaultCurrent()
|
internal void MakeDefaultCurrent()
|
||||||
{
|
{
|
||||||
MakeContextCurrent(this.GraphicsContext, OffscreenNativeWindow.WindowInfo);
|
MakeContextCurrent(this.GraphicsContext,OffscreenNativeWindow.WindowInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void MakeContextCurrent(IGraphicsContext context, global::OpenTK.Platform.IWindowInfo windowInfo)
|
internal void MakeContextCurrent(IGraphicsContext context, global::OpenTK.Platform.IWindowInfo windowInfo)
|
||||||
{
|
{
|
||||||
//TODO - if we're churning through contexts quickly, this will sort of be a memory leak, since they'll be memoized forever in here
|
|
||||||
//maybe make it a weakptr or something
|
|
||||||
|
|
||||||
//dont do anything if we're already current
|
|
||||||
IGraphicsContext currentForThread = null;
|
|
||||||
if (ThreadsForContexts.TryGetValue(Thread.CurrentThread, out currentForThread))
|
|
||||||
if (currentForThread == context)
|
|
||||||
return;
|
|
||||||
|
|
||||||
NativeWindowsForContexts[context] = windowInfo;
|
|
||||||
context.MakeCurrent(windowInfo);
|
context.MakeCurrent(windowInfo);
|
||||||
ThreadsForContexts[Thread.CurrentThread] = context;
|
PurgeStateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary<Thread, IGraphicsContext> ThreadsForContexts = new Dictionary<Thread, IGraphicsContext>();
|
|
||||||
Dictionary<IGraphicsContext, global::OpenTK.Platform.IWindowInfo> NativeWindowsForContexts = new Dictionary<IGraphicsContext, global::OpenTK.Platform.IWindowInfo>();
|
|
||||||
|
|
||||||
void CreateRenderStates()
|
void CreateRenderStates()
|
||||||
{
|
{
|
||||||
_rsBlendNone = new MyBlendState(false, BlendingFactorSrc.One, BlendEquationMode.FuncAdd, BlendingFactorDest.Zero, BlendingFactorSrc.One, BlendEquationMode.FuncAdd, BlendingFactorDest.Zero);
|
_rsBlendNone = new MyBlendState(false, BlendingFactorSrc.One, BlendEquationMode.FuncAdd, BlendingFactorDest.Zero, BlendingFactorSrc.One, BlendEquationMode.FuncAdd, BlendingFactorDest.Zero);
|
||||||
|
@ -535,6 +522,19 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
|
||||||
}
|
}
|
||||||
|
|
||||||
MyBlendState _rsBlendNone, _rsBlendNormal;
|
MyBlendState _rsBlendNone, _rsBlendNormal;
|
||||||
|
|
||||||
|
//state caches
|
||||||
|
int sActiveTexture;
|
||||||
|
VertexLayout sStateCurrentVertexLayout;
|
||||||
|
VertexLayout sStatePendingVertexLayout;
|
||||||
|
HashSet<int> sVertexAttribEnables = new HashSet<int>();
|
||||||
|
void PurgeStateCache()
|
||||||
|
{
|
||||||
|
sStateCurrentVertexLayout = null;
|
||||||
|
sStatePendingVertexLayout = null;
|
||||||
|
sVertexAttribEnables.Clear();
|
||||||
|
sActiveTexture = -1;
|
||||||
|
}
|
||||||
|
|
||||||
} //class IGL_TK
|
} //class IGL_TK
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,8 @@ namespace BizHawk.Bizware.BizwareGL
|
||||||
/// And possibly, quite possibly, Direct3d.. even though none of your shaders would work. (could use nvidia CG, native dlls in necessary since this would only be for windows)
|
/// And possibly, quite possibly, Direct3d.. even though none of your shaders would work. (could use nvidia CG, native dlls in necessary since this would only be for windows)
|
||||||
/// TODO - This really needs to be split up into an internal and a user interface. so many of the functions are made to support the smart wrappers
|
/// TODO - This really needs to be split up into an internal and a user interface. so many of the functions are made to support the smart wrappers
|
||||||
/// Maybe make a method that returns an interface used for advanced methods (and IGL_TK could implement that as well and just "return this:")
|
/// Maybe make a method that returns an interface used for advanced methods (and IGL_TK could implement that as well and just "return this:")
|
||||||
|
///
|
||||||
|
/// NOTE: THIS SHOULD NOT BE ASSUMED TO BE THREAD SAFE! Make a new IGL if you want to use it in a new thread. I hope that will work...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IGL : IDisposable
|
public interface IGL : IDisposable
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue