* 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:
the_fiddler 2009-10-07 10:44:45 +00:00
parent 8992f90571
commit d3a56a15ef
7 changed files with 39 additions and 16 deletions

View file

@ -32,10 +32,10 @@ using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Diagnostics; using System.Diagnostics;
namespace OpenTK.Graphics namespace OpenTK
{ {
/// <summary> /// <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> /// </summary>
public abstract class BindingsBase public abstract class BindingsBase
{ {
@ -70,11 +70,14 @@ namespace OpenTK.Graphics
DelegatesClass = this.GetType().GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic); DelegatesClass = this.GetType().GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic);
CoreClass = this.GetType().GetNestedType("Core", BindingFlags.Static | BindingFlags.NonPublic); CoreClass = this.GetType().GetNestedType("Core", BindingFlags.Static | BindingFlags.NonPublic);
MethodInfo[] methods = CoreClass.GetMethods(BindingFlags.Static | BindingFlags.NonPublic); if (CoreClass != null)
CoreFunctionMap = new SortedList<string, MethodInfo>(methods.Length);
foreach (MethodInfo m in methods)
{ {
CoreFunctionMap.Add(m.Name, m); MethodInfo[] methods = CoreClass.GetMethods(BindingFlags.Static | BindingFlags.NonPublic);
CoreFunctionMap = new SortedList<string, MethodInfo>(methods.Length); // Avoid resizing
foreach (MethodInfo m in methods)
{
CoreFunctionMap.Add(m.Name, m);
}
} }
} }
@ -91,6 +94,8 @@ namespace OpenTK.Graphics
set { rebuildExtensionList = value; } set { rebuildExtensionList = value; }
} }
protected abstract IntPtr GetAddress(string funcname);
#endregion #endregion
#region Internal Members #region Internal Members
@ -176,9 +181,9 @@ namespace OpenTK.Graphics
#region GetExtensionDelegate #region GetExtensionDelegate
// Creates a System.Delegate that can be used to call a dynamically exported OpenGL function. // 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 || if (address == IntPtr.Zero ||
address == new IntPtr(1) || // Workaround for buggy nvidia drivers which return address == new IntPtr(1) || // Workaround for buggy nvidia drivers which return
@ -197,3 +202,14 @@ namespace OpenTK.Graphics
#endregion #endregion
} }
} }
namespace OpenTK.Graphics
{
public class GraphicsBindingsBase : BindingsBase
{
protected override IntPtr GetAddress(string funcname)
{
return (GraphicsContext.CurrentContext as IGraphicsContextInternal).GetAddress(funcname);
}
}
}

View file

@ -7,7 +7,7 @@ namespace OpenTK.Graphics.ES10
/// <summary> /// <summary>
/// Provides access to OpenGL ES 1.0 methods. /// Provides access to OpenGL ES 1.0 methods.
/// </summary> /// </summary>
public sealed partial class GL : BindingsBase public sealed partial class GL : GraphicsBindingsBase
{ {
const string Library = "libGLES.dll"; const string Library = "libGLES.dll";
} }

View file

@ -9,7 +9,7 @@ namespace OpenTK.Graphics.ES11
/// <summary> /// <summary>
/// Provides access to OpenGL ES 1.1 methods. /// Provides access to OpenGL ES 1.1 methods.
/// </summary> /// </summary>
public sealed partial class GL : BindingsBase public sealed partial class GL : GraphicsBindingsBase
{ {
const string Library = "libGLES.dll"; const string Library = "libGLES.dll";
} }

View file

@ -7,7 +7,7 @@ namespace OpenTK.Graphics.ES20
/// <summary> /// <summary>
/// Provides access to OpenGL ES 2.0 methods. /// Provides access to OpenGL ES 2.0 methods.
/// </summary> /// </summary>
public sealed partial class GL : BindingsBase public sealed partial class GL : GraphicsBindingsBase
{ {
const string Library = "libGLESv2.dll"; const string Library = "libGLESv2.dll";
} }

View file

@ -46,7 +46,7 @@ namespace OpenTK.Graphics.OpenGL
/// </para> /// </para>
/// </remarks> /// </remarks>
/// <see href="http://opengl.org/registry/"/> /// <see href="http://opengl.org/registry/"/>
public sealed partial class GL : BindingsBase public sealed partial class GL : GraphicsBindingsBase
{ {
#region --- Fields --- #region --- Fields ---

View file

@ -15,13 +15,19 @@ using OpenTK.Graphics;
namespace OpenTK.Platform.X11 namespace OpenTK.Platform.X11
{ {
static partial class Glx partial class Glx : BindingsBase
{ {
const string Library = "libGL.so.1"; const string Library = "libGL.so.1";
// Disable BeforeFieldInit optimization. // Disable BeforeFieldInit optimization.
static Glx() { } static Glx() { }
protected override IntPtr GetAddress (string funcname)
{
return Glx.GetProcAddress(funcname);
}
#if false
#region static Delegate LoadDelegate(string name, Type signature) #region static Delegate LoadDelegate(string name, Type signature)
/// <summary> /// <summary>
@ -83,5 +89,6 @@ namespace OpenTK.Platform.X11
} }
#endregion #endregion
#endif
} }
} }

View file

@ -59,7 +59,7 @@ namespace OpenTK.Platform.X11
if (ctx != IntPtr.Zero) if (ctx != IntPtr.Zero)
{ {
Glx.LoadAll(); new Glx().LoadAll();
Glx.MakeCurrent(currentWindow.Display, IntPtr.Zero, IntPtr.Zero); Glx.MakeCurrent(currentWindow.Display, IntPtr.Zero, IntPtr.Zero);
//Glx.DestroyContext(currentWindow.Display, ctx); //Glx.DestroyContext(currentWindow.Display, ctx);
glx_loaded = true; glx_loaded = true;
@ -271,7 +271,7 @@ namespace OpenTK.Platform.X11
public override void LoadAll() public override void LoadAll()
{ {
new OpenTK.Graphics.OpenGL.GL().LoadAll(); new OpenTK.Graphics.OpenGL.GL().LoadAll();
Glx.LoadAll(); new Glx().LoadAll();
vsync_supported = this.GetAddress("glXSwapIntervalSGI") != IntPtr.Zero; vsync_supported = this.GetAddress("glXSwapIntervalSGI") != IntPtr.Zero;
Debug.Print("Context supports vsync: {0}.", vsync_supported); Debug.Print("Context supports vsync: {0}.", vsync_supported);
} }