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> /// <summary>
/// Gets the address of an OpenGL extension function. /// Retrieves the implementation-defined address of an OpenGL function.
/// </summary> /// </summary>
/// <param name="function">The name of the OpenGL function (e.g. "glGetString")</param> /// <param name="function">The name of the OpenGL function (e.g. "glGetString")</param>
/// <returns> /// <returns>
/// A pointer to the specified function or IntPtr.Zero if the function isn't /// A pointer to the specified function or an invalid pointer if the function is not
/// available in the current opengl context. /// available in the current OpenGL context. The return value and calling convention
/// depends on the underlying platform.
/// </returns> /// </returns>
IntPtr IGraphicsContextInternal.GetAddress(string function) IntPtr IGraphicsContextInternal.GetAddress(string function)
{ {
return (implementation as IGraphicsContextInternal).GetAddress(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 #endregion
#region --- IDisposable Members --- #region --- IDisposable Members ---

View file

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

View file

@ -121,5 +121,20 @@ namespace OpenTK.Graphics
/// depends on the underlying platform. /// depends on the underlying platform.
/// </returns> /// </returns>
IntPtr GetAddress(string function); 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(string function) { return IntPtr.Zero; }
public override IntPtr GetAddress(IntPtr function) { return IntPtr.Zero; }
public override int SwapInterval public override int SwapInterval
{ {
get get

View file

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

View file

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

View file

@ -468,8 +468,12 @@ namespace OpenTK.Platform.MacOS
[DllImport(Library, EntryPoint = "NSIsSymbolNameDefined")] [DllImport(Library, EntryPoint = "NSIsSymbolNameDefined")]
private static extern bool NSIsSymbolNameDefined(string s); private static extern bool NSIsSymbolNameDefined(string s);
[DllImport(Library, EntryPoint = "NSIsSymbolNameDefined")]
private static extern bool NSIsSymbolNameDefined(IntPtr s);
[DllImport(Library, EntryPoint = "NSLookupAndBindSymbol")] [DllImport(Library, EntryPoint = "NSLookupAndBindSymbol")]
private static extern IntPtr NSLookupAndBindSymbol(string s); private static extern IntPtr NSLookupAndBindSymbol(string s);
[DllImport(Library, EntryPoint = "NSLookupAndBindSymbol")]
private static extern IntPtr NSLookupAndBindSymbol(IntPtr s);
[DllImport(Library, EntryPoint = "NSAddressOfSymbol")] [DllImport(Library, EntryPoint = "NSAddressOfSymbol")]
private static extern IntPtr NSAddressOfSymbol(IntPtr symbol); private static extern IntPtr NSAddressOfSymbol(IntPtr symbol);
@ -485,6 +489,18 @@ namespace OpenTK.Platform.MacOS
return symbol; 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 #endregion
} }

View file

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

View file

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

View file

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

View file

@ -308,6 +308,9 @@ namespace OpenTK.Platform.X11
[DllImport(Library, EntryPoint = "glXGetProcAddress")] [DllImport(Library, EntryPoint = "glXGetProcAddress")]
public static extern IntPtr GetProcAddress([MarshalAs(UnmanagedType.LPTStr)] string procName); 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")] [DllImport(Library, EntryPoint = "glXGetConfig")]
public static extern int GetConfig(IntPtr dpy, ref XVisualInfo vis, GLXAttribute attrib, out int value); 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 #endregion
#region GetAddress
public override IntPtr GetAddress(string function)
{
using (new XLock(Display))
{
return Glx.GetProcAddress(function);
}
}
#endregion
#region LoadAll #region LoadAll
public override void LoadAll() public override void LoadAll()
@ -403,11 +391,25 @@ namespace OpenTK.Platform.X11
#endregion #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 #endregion