Added GetProcAddress(IntPtr) overloads

This might allow us to improve startup performance, by avoiding string
marshaling during extension loading.
This commit is contained in:
Stefanos A. 2013-11-28 23:21:19 +01:00
parent 8b8ea714ee
commit c53c0bc66f
12 changed files with 94 additions and 25 deletions

View file

@ -544,18 +544,36 @@ namespace OpenTK.Graphics
}
/// <summary>
/// Gets the address of an OpenGL extension function.
/// Retrieves the implementation-defined address of an OpenGL function.
/// </summary>
/// <param name="function">The name of the OpenGL function (e.g. "glGetString")</param>
/// <returns>
/// A pointer to the specified function or IntPtr.Zero if the function isn't
/// available in the current opengl context.
/// A pointer to the specified function or an invalid pointer if the function is not
/// available in the current OpenGL context. The return value and calling convention
/// depends on the underlying platform.
/// </returns>
IntPtr IGraphicsContextInternal.GetAddress(string function)
{
return (implementation as IGraphicsContextInternal).GetAddress(function);
}
/// <summary>
/// Retrieves the implementation-defined address of an OpenGL function.
/// </summary>
/// <param name="function">
/// A pointer to a null-terminated buffer
/// containing the name of the OpenGL function.
/// </param>
/// <returns>
/// A pointer to the specified function or an invalid pointer if the function is not
/// available in the current OpenGL context. The return value and calling convention
/// depends on the underlying platform.
/// </returns>
IntPtr IGraphicsContextInternal.GetAddress(IntPtr function)
{
return (implementation as IGraphicsContextInternal).GetAddress(function);
}
#endregion
#region --- IDisposable Members ---

View file

@ -94,6 +94,8 @@ namespace OpenTK.Graphics
public abstract IntPtr GetAddress(string function);
public abstract IntPtr GetAddress(IntPtr function);
#endregion
#region IDisposable Members

View file

@ -121,5 +121,20 @@ namespace OpenTK.Graphics
/// depends on the underlying platform.
/// </returns>
IntPtr GetAddress(string function);
/// <summary>
/// Retrieves the implementation-defined address of an OpenGL function.
/// </summary>
/// <param name="function">
/// A pointer to a null-terminated buffer
/// containing the name of the OpenGL function.
/// </param>
/// <returns>
/// A pointer to the specified function or an invalid pointer if the function is not
/// available in the current OpenGL context. The return value and calling convention
/// depends on the underlying platform.
/// </returns>
/// <remarks><seealso cref="GetAddress(string)"/></remarks>
IntPtr GetAddress(IntPtr function);
}
}

View file

@ -83,6 +83,8 @@ namespace OpenTK.Platform.Dummy
public override IntPtr GetAddress(string function) { return IntPtr.Zero; }
public override IntPtr GetAddress(IntPtr function) { return IntPtr.Zero; }
public override int SwapInterval
{
get

View file

@ -308,6 +308,9 @@ namespace OpenTK.Platform.Egl
[DllImportAttribute("libEGL.dll", EntryPoint = "eglGetProcAddress")]
public static extern IntPtr GetProcAddress(string funcname);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglGetProcAddress")]
public static extern IntPtr GetProcAddress(IntPtr funcname);
// Returns true if Egl drivers exist on the system.
public static bool IsSupported
{

View file

@ -143,6 +143,11 @@ namespace OpenTK.Platform.Egl
return Egl.GetProcAddress(function);
}
public override IntPtr GetAddress(IntPtr function)
{
return Egl.GetProcAddress(function);
}
#endregion
#region IDisposable Members

View file

@ -468,8 +468,12 @@ namespace OpenTK.Platform.MacOS
[DllImport(Library, EntryPoint = "NSIsSymbolNameDefined")]
private static extern bool NSIsSymbolNameDefined(string s);
[DllImport(Library, EntryPoint = "NSIsSymbolNameDefined")]
private static extern bool NSIsSymbolNameDefined(IntPtr s);
[DllImport(Library, EntryPoint = "NSLookupAndBindSymbol")]
private static extern IntPtr NSLookupAndBindSymbol(string s);
[DllImport(Library, EntryPoint = "NSLookupAndBindSymbol")]
private static extern IntPtr NSLookupAndBindSymbol(IntPtr s);
[DllImport(Library, EntryPoint = "NSAddressOfSymbol")]
private static extern IntPtr NSAddressOfSymbol(IntPtr symbol);
@ -485,6 +489,18 @@ namespace OpenTK.Platform.MacOS
return symbol;
}
public override IntPtr GetAddress(IntPtr function)
{
if (!NSIsSymbolNameDefined(function))
return IntPtr.Zero;
IntPtr symbol = NSLookupAndBindSymbol(function);
if (symbol != IntPtr.Zero)
symbol = NSAddressOfSymbol(symbol);
return symbol;
}
#endregion
}

View file

@ -336,7 +336,7 @@ namespace OpenTK.Platform.SDL2
[SuppressUnmanagedCodeSecurity]
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GL_GetProcAddress", ExactSpelling = true)]
static extern IntPtr GetProcAddress(IntPtr proc);
public static extern IntPtr GetProcAddress(IntPtr proc);
public static IntPtr GetProcAddress(string proc)
{
IntPtr p = Marshal.StringToHGlobalAnsi(proc);

View file

@ -294,6 +294,11 @@ namespace OpenTK.Platform.SDL2
return SDL.GL.GetProcAddress(function);
}
public override IntPtr GetAddress(IntPtr function)
{
return SDL.GL.GetProcAddress(function);
}
public override bool IsCurrent
{
get

View file

@ -581,15 +581,13 @@ namespace OpenTK.Platform.Windows
#region GetProcAddress
/// <summary>
///
/// </summary>
/// <param name="handle"></param>
/// <param name="funcname"></param>
/// <returns></returns>
[DllImport("kernel32.dll")]
internal static extern IntPtr GetProcAddress(IntPtr handle, string funcname);
[DllImport("kernel32.dll")]
internal static extern IntPtr GetProcAddress(IntPtr handle, IntPtr funcname);
#endregion
#endregion

View file

@ -308,6 +308,9 @@ namespace OpenTK.Platform.X11
[DllImport(Library, EntryPoint = "glXGetProcAddress")]
public static extern IntPtr GetProcAddress([MarshalAs(UnmanagedType.LPTStr)] string procName);
[DllImport(Library, EntryPoint = "glXGetProcAddress")]
public static extern IntPtr GetProcAddress(IntPtr procName);
[DllImport(Library, EntryPoint = "glXGetConfig")]
public static extern int GetConfig(IntPtr dpy, ref XVisualInfo vis, GLXAttribute attrib, out int value);

View file

@ -376,18 +376,6 @@ namespace OpenTK.Platform.X11
#endregion
#region GetAddress
public override IntPtr GetAddress(string function)
{
using (new XLock(Display))
{
return Glx.GetProcAddress(function);
}
}
#endregion
#region LoadAll
public override void LoadAll()
@ -403,11 +391,25 @@ namespace OpenTK.Platform.X11
#endregion
#region --- IGLContextInternal Members ---
#region --- IGraphicsContextInternal Members ---
#region IWindowInfo IGLContextInternal.Info
#region GetAddress
//IWindowInfo IGraphicsContextInternal.Info { get { return window; } }
public override IntPtr GetAddress(string function)
{
using (new XLock(Display))
{
return Glx.GetProcAddress(function);
}
}
public override IntPtr GetAddress(IntPtr function)
{
using (new XLock(Display))
{
return Glx.GetProcAddress(function);
}
}
#endregion