mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-24 18:35:32 +00:00
* Graphics/ES10/Helper.cs:
* Graphics/ES11/Helper.cs: * Graphics/ES20/Helper.cs: * Graphics/BindingsBase.cs: * Platform/X11/GlxHelper.cs: * Graphics/OpenGL/GLHelper.cs: * Platform/X11/X11GLContext.cs: Modified BindingsBase to define abstract GetAddress method (reason: removes OpenTK.Graphics-specific code from BindingsBase and allows it to be used in different bindings). Implemented GraphicsBindingsBase and modified the OpenGL and OpenGL|ES bindings to use this. Modified the GLX bindings to inherit from BindingsBase (reason: reduces code duplication for extension loading).
This commit is contained in:
parent
8992f90571
commit
d3a56a15ef
|
@ -32,10 +32,10 @@ using System.Reflection;
|
|||
using System.Runtime.InteropServices;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
namespace OpenTK
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a common foundation for all flat API classes.
|
||||
/// Provides a common foundation for all flat API bindings and implements the extension loading interface.
|
||||
/// </summary>
|
||||
public abstract class BindingsBase
|
||||
{
|
||||
|
@ -70,13 +70,16 @@ namespace OpenTK.Graphics
|
|||
DelegatesClass = this.GetType().GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
CoreClass = this.GetType().GetNestedType("Core", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
|
||||
if (CoreClass != null)
|
||||
{
|
||||
MethodInfo[] methods = CoreClass.GetMethods(BindingFlags.Static | BindingFlags.NonPublic);
|
||||
CoreFunctionMap = new SortedList<string, MethodInfo>(methods.Length);
|
||||
CoreFunctionMap = new SortedList<string, MethodInfo>(methods.Length); // Avoid resizing
|
||||
foreach (MethodInfo m in methods)
|
||||
{
|
||||
CoreFunctionMap.Add(m.Name, m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -91,6 +94,8 @@ namespace OpenTK.Graphics
|
|||
set { rebuildExtensionList = value; }
|
||||
}
|
||||
|
||||
protected abstract IntPtr GetAddress(string funcname);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Members
|
||||
|
@ -176,9 +181,9 @@ namespace OpenTK.Graphics
|
|||
#region GetExtensionDelegate
|
||||
|
||||
// Creates a System.Delegate that can be used to call a dynamically exported OpenGL function.
|
||||
internal static Delegate GetExtensionDelegate(string name, Type signature)
|
||||
internal Delegate GetExtensionDelegate(string name, Type signature)
|
||||
{
|
||||
IntPtr address = (GraphicsContext.CurrentContext as IGraphicsContextInternal).GetAddress(name);
|
||||
IntPtr address = GetAddress(name);
|
||||
|
||||
if (address == IntPtr.Zero ||
|
||||
address == new IntPtr(1) || // Workaround for buggy nvidia drivers which return
|
||||
|
@ -197,3 +202,14 @@ namespace OpenTK.Graphics
|
|||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
public class GraphicsBindingsBase : BindingsBase
|
||||
{
|
||||
protected override IntPtr GetAddress(string funcname)
|
||||
{
|
||||
return (GraphicsContext.CurrentContext as IGraphicsContextInternal).GetAddress(funcname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace OpenTK.Graphics.ES10
|
|||
/// <summary>
|
||||
/// Provides access to OpenGL ES 1.0 methods.
|
||||
/// </summary>
|
||||
public sealed partial class GL : BindingsBase
|
||||
public sealed partial class GL : GraphicsBindingsBase
|
||||
{
|
||||
const string Library = "libGLES.dll";
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace OpenTK.Graphics.ES11
|
|||
/// <summary>
|
||||
/// Provides access to OpenGL ES 1.1 methods.
|
||||
/// </summary>
|
||||
public sealed partial class GL : BindingsBase
|
||||
public sealed partial class GL : GraphicsBindingsBase
|
||||
{
|
||||
const string Library = "libGLES.dll";
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace OpenTK.Graphics.ES20
|
|||
/// <summary>
|
||||
/// Provides access to OpenGL ES 2.0 methods.
|
||||
/// </summary>
|
||||
public sealed partial class GL : BindingsBase
|
||||
public sealed partial class GL : GraphicsBindingsBase
|
||||
{
|
||||
const string Library = "libGLESv2.dll";
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace OpenTK.Graphics.OpenGL
|
|||
/// </para>
|
||||
/// </remarks>
|
||||
/// <see href="http://opengl.org/registry/"/>
|
||||
public sealed partial class GL : BindingsBase
|
||||
public sealed partial class GL : GraphicsBindingsBase
|
||||
{
|
||||
#region --- Fields ---
|
||||
|
||||
|
|
|
@ -15,13 +15,19 @@ using OpenTK.Graphics;
|
|||
|
||||
namespace OpenTK.Platform.X11
|
||||
{
|
||||
static partial class Glx
|
||||
partial class Glx : BindingsBase
|
||||
{
|
||||
const string Library = "libGL.so.1";
|
||||
|
||||
// Disable BeforeFieldInit optimization.
|
||||
static Glx() { }
|
||||
|
||||
protected override IntPtr GetAddress (string funcname)
|
||||
{
|
||||
return Glx.GetProcAddress(funcname);
|
||||
}
|
||||
|
||||
#if false
|
||||
#region static Delegate LoadDelegate(string name, Type signature)
|
||||
|
||||
/// <summary>
|
||||
|
@ -83,5 +89,6 @@ namespace OpenTK.Platform.X11
|
|||
}
|
||||
|
||||
#endregion
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
if (ctx != IntPtr.Zero)
|
||||
{
|
||||
Glx.LoadAll();
|
||||
new Glx().LoadAll();
|
||||
Glx.MakeCurrent(currentWindow.Display, IntPtr.Zero, IntPtr.Zero);
|
||||
//Glx.DestroyContext(currentWindow.Display, ctx);
|
||||
glx_loaded = true;
|
||||
|
@ -271,7 +271,7 @@ namespace OpenTK.Platform.X11
|
|||
public override void LoadAll()
|
||||
{
|
||||
new OpenTK.Graphics.OpenGL.GL().LoadAll();
|
||||
Glx.LoadAll();
|
||||
new Glx().LoadAll();
|
||||
vsync_supported = this.GetAddress("glXSwapIntervalSGI") != IntPtr.Zero;
|
||||
Debug.Print("Context supports vsync: {0}.", vsync_supported);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue