From 825ed3621f0fc7fed13185e4f843d7cb0ad99645 Mon Sep 17 00:00:00 2001 From: "Stefanos A." Date: Sun, 24 Nov 2013 13:57:43 +0100 Subject: [PATCH] Implemented new loading mechanism --- .../OpenTK/Graphics/GraphicsBindingsBase.cs | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/Source/OpenTK/Graphics/GraphicsBindingsBase.cs b/Source/OpenTK/Graphics/GraphicsBindingsBase.cs index 21923cb1..02c1a43a 100644 --- a/Source/OpenTK/Graphics/GraphicsBindingsBase.cs +++ b/Source/OpenTK/Graphics/GraphicsBindingsBase.cs @@ -35,6 +35,18 @@ namespace OpenTK.Graphics /// public abstract class GraphicsBindingsBase : BindingsBase { + /// + /// Contains the list of API entry points (function pointers). + /// This field must be set by an inheriting class. + /// + protected IntPtr[] EntryPointsInstance; + + /// + /// Contains the list of API entry point names. + /// This field must be set by an inheriting class. + /// + protected string[] EntryPointNamesInstance; + /// /// Retrieves an unmanaged function pointer to the specified function. /// @@ -58,22 +70,20 @@ namespace OpenTK.Graphics return context != null ? context.GetAddress(funcname) : IntPtr.Zero; } - internal static Delegate GetExtensionDelegateStatic(string funcname, Type signature) + // Loads all available entry points for the current API. + // Note: we prefer IGraphicsContextInternal.GetAddress over + // this.GetAddress to improve loading performance (less + // validation necessary.) + internal override void LoadEntryPoints() { - var context = GraphicsContext.CurrentContext as IGraphicsContextInternal; + IGraphicsContext context = GraphicsContext.CurrentContext; if (context == null) throw new GraphicsContextMissingException(); - IntPtr address = context.GetAddress(funcname); - if (address == IntPtr.Zero || - address == new IntPtr(1) || // Workaround for buggy nvidia drivers which return - address == new IntPtr(2)) // 1 or 2 instead of IntPtr.Zero for some extensions. + IGraphicsContextInternal context_internal = context as IGraphicsContextInternal; + for (int i = 0; i < EntryPointsInstance.Length; i++) { - return null; - } - else - { - return Marshal.GetDelegateForFunctionPointer(address, signature); + EntryPointsInstance[i] = context_internal.GetAddress(EntryPointNamesInstance[i]); } } }