Removed the various GetProcAddress methods (now handled by IGraphicsContextInternal).
Removed Imports nested class.
This commit is contained in:
parent
e4f1c956c9
commit
521c1211d3
1 changed files with 17 additions and 111 deletions
|
@ -52,9 +52,6 @@ namespace OpenTK.Graphics.OpenGL
|
||||||
/// <seealso cref="GL.Load"/>
|
/// <seealso cref="GL.Load"/>
|
||||||
public static partial class GL
|
public static partial class GL
|
||||||
{
|
{
|
||||||
delegate void VoidGLDelegate(object @class, object[] parameters);
|
|
||||||
delegate object ObjectGLDelegate(object @class, object[] parameters);
|
|
||||||
|
|
||||||
#region --- Fields ---
|
#region --- Fields ---
|
||||||
|
|
||||||
internal const string Library = "opengl32.dll";
|
internal const string Library = "opengl32.dll";
|
||||||
|
@ -67,7 +64,9 @@ namespace OpenTK.Graphics.OpenGL
|
||||||
|
|
||||||
private static Type glClass;
|
private static Type glClass;
|
||||||
private static Type delegatesClass;
|
private static Type delegatesClass;
|
||||||
private static Type importsClass;
|
private static Type importsClass;
|
||||||
|
|
||||||
|
readonly static SortedList<string, MethodInfo> FunctionMap = new SortedList<string, MethodInfo>();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -77,24 +76,13 @@ namespace OpenTK.Graphics.OpenGL
|
||||||
{
|
{
|
||||||
glClass = typeof(GL);
|
glClass = typeof(GL);
|
||||||
delegatesClass = glClass.GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic);
|
delegatesClass = glClass.GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic);
|
||||||
importsClass = glClass.GetNestedType("Imports", BindingFlags.Static | BindingFlags.NonPublic);
|
importsClass = glClass.GetNestedType("Imports", BindingFlags.Static | BindingFlags.NonPublic);
|
||||||
}
|
|
||||||
|
MethodInfo[] methods = importsClass.GetMethods(BindingFlags.Static | BindingFlags.NonPublic);
|
||||||
#endregion
|
FunctionMap = new SortedList<string, MethodInfo>(methods.Length);
|
||||||
|
foreach (MethodInfo m in methods)
|
||||||
#region --- Imports ---
|
{
|
||||||
|
FunctionMap.Add(m.Name, m);
|
||||||
internal static partial class Imports
|
|
||||||
{
|
|
||||||
internal static SortedList<string, MethodInfo> FunctionMap; // This is faster than either Dictionary or SortedDictionary
|
|
||||||
static Imports()
|
|
||||||
{
|
|
||||||
MethodInfo[] methods = importsClass.GetMethods(BindingFlags.Static | BindingFlags.NonPublic);
|
|
||||||
FunctionMap = new SortedList<string, MethodInfo>(methods.Length);
|
|
||||||
foreach (MethodInfo m in methods)
|
|
||||||
{
|
|
||||||
FunctionMap.Add(m.Name, m);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,13 +176,10 @@ namespace OpenTK.Graphics.OpenGL
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public static void LoadAll()
|
public static void LoadAll()
|
||||||
{
|
{
|
||||||
//TODO: Route GameWindow context creation through GraphicsContext.
|
if (GraphicsContext.CurrentContext == null)
|
||||||
//if (GraphicsContext.CurrentContext == null)
|
throw new GraphicsContextMissingException();
|
||||||
// throw new InvalidOperationException("You must create an OpenGL context before using the GL class.");
|
|
||||||
if (GraphicsContext.CurrentContext != null)
|
OpenTK.Platform.Utilities.LoadExtensions(glClass);
|
||||||
OpenTK.Platform.Utilities.LoadExtensions(glClass);
|
|
||||||
else
|
|
||||||
throw new InvalidOperationException("No GraphicsContext available in the calling thread.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -258,7 +243,7 @@ namespace OpenTK.Graphics.OpenGL
|
||||||
MethodInfo m;
|
MethodInfo m;
|
||||||
return
|
return
|
||||||
GetExtensionDelegate(name, signature) ??
|
GetExtensionDelegate(name, signature) ??
|
||||||
(Imports.FunctionMap.TryGetValue((name.Substring(2)), out m) ?
|
(FunctionMap.TryGetValue((name.Substring(2)), out m) ?
|
||||||
Delegate.CreateDelegate(signature, m) : null);
|
Delegate.CreateDelegate(signature, m) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -468,65 +453,7 @@ namespace OpenTK.Graphics.OpenGL
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#endregion
|
#region GetAddress
|
||||||
|
|
||||||
#region --- GetProcAddress ---
|
|
||||||
|
|
||||||
private static IGetProcAddress getProcAddress;
|
|
||||||
|
|
||||||
internal interface IGetProcAddress
|
|
||||||
{
|
|
||||||
IntPtr GetProcAddress(string function);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class GetProcAddressWindows : IGetProcAddress
|
|
||||||
{
|
|
||||||
[System.Runtime.InteropServices.DllImport(Library, EntryPoint = "wglGetProcAddress", ExactSpelling = true)]
|
|
||||||
private static extern IntPtr wglGetProcAddress(String lpszProc);
|
|
||||||
|
|
||||||
public IntPtr GetProcAddress(string function)
|
|
||||||
{
|
|
||||||
return wglGetProcAddress(function);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class GetProcAddressX11 : IGetProcAddress
|
|
||||||
{
|
|
||||||
[DllImport(Library, EntryPoint = "glXGetProcAddress")]
|
|
||||||
private static extern IntPtr glxGetProcAddress([MarshalAs(UnmanagedType.LPTStr)] string procName);
|
|
||||||
|
|
||||||
public IntPtr GetProcAddress(string function)
|
|
||||||
{
|
|
||||||
return glxGetProcAddress(function);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class GetProcAddressOSX : IGetProcAddress
|
|
||||||
{
|
|
||||||
private const string Library = "libdl.dylib";
|
|
||||||
|
|
||||||
[DllImport(Library, EntryPoint = "NSIsSymbolNameDefined")]
|
|
||||||
private static extern bool NSIsSymbolNameDefined(string s);
|
|
||||||
[DllImport(Library, EntryPoint = "NSLookupAndBindSymbol")]
|
|
||||||
private static extern IntPtr NSLookupAndBindSymbol(string s);
|
|
||||||
[DllImport(Library, EntryPoint = "NSAddressOfSymbol")]
|
|
||||||
private static extern IntPtr NSAddressOfSymbol(IntPtr symbol);
|
|
||||||
|
|
||||||
public IntPtr GetProcAddress(string function)
|
|
||||||
{
|
|
||||||
string fname = "_" + function;
|
|
||||||
if (!NSIsSymbolNameDefined(fname))
|
|
||||||
return IntPtr.Zero;
|
|
||||||
|
|
||||||
IntPtr symbol = NSLookupAndBindSymbol(fname);
|
|
||||||
if (symbol != IntPtr.Zero)
|
|
||||||
symbol = NSAddressOfSymbol(symbol);
|
|
||||||
|
|
||||||
return symbol;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#region private static IntPtr GetAddress(string function)
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves the entry point for a dynamically exported OpenGL function.
|
/// Retrieves the entry point for a dynamically exported OpenGL function.
|
||||||
|
@ -548,28 +475,7 @@ namespace OpenTK.Graphics.OpenGL
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
private static IntPtr GetAddress(string function)
|
private static IntPtr GetAddress(string function)
|
||||||
{
|
{
|
||||||
if (getProcAddress == null)
|
return (GraphicsContext.CurrentContext as IGraphicsContextInternal).GetAddress(function);
|
||||||
{
|
|
||||||
if (Configuration.RunningOnWindows)
|
|
||||||
{
|
|
||||||
getProcAddress = new GetProcAddressWindows();
|
|
||||||
}
|
|
||||||
else if (Configuration.RunningOnMacOS)
|
|
||||||
{
|
|
||||||
getProcAddress = new GetProcAddressOSX();
|
|
||||||
}
|
|
||||||
else if (Configuration.RunningOnX11)
|
|
||||||
{
|
|
||||||
getProcAddress = new GetProcAddressX11();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new PlatformNotSupportedException(
|
|
||||||
"Extension loading is only supported under Mac OS X, X11 and Windows. We are sorry for the inconvience.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return getProcAddress.GetProcAddress(function);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
Loading…
Reference in a new issue