From ffe934fa5deda3e0a719ace644ec76f4588d5cdf Mon Sep 17 00:00:00 2001 From: Stefanos A Date: Fri, 22 Nov 2013 20:06:04 +0100 Subject: [PATCH] Added static GetExtensionDelegate implementation --- .../OpenTK/Graphics/GraphicsBindingsBase.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Source/OpenTK/Graphics/GraphicsBindingsBase.cs b/Source/OpenTK/Graphics/GraphicsBindingsBase.cs index 29cbdbac..21923cb1 100644 --- a/Source/OpenTK/Graphics/GraphicsBindingsBase.cs +++ b/Source/OpenTK/Graphics/GraphicsBindingsBase.cs @@ -26,6 +26,7 @@ #endregion using System; +using System.Runtime.InteropServices; namespace OpenTK.Graphics { @@ -56,5 +57,24 @@ namespace OpenTK.Graphics throw new GraphicsContextMissingException(); return context != null ? context.GetAddress(funcname) : IntPtr.Zero; } + + internal static Delegate GetExtensionDelegateStatic(string funcname, Type signature) + { + var context = GraphicsContext.CurrentContext as IGraphicsContextInternal; + 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. + { + return null; + } + else + { + return Marshal.GetDelegateForFunctionPointer(address, signature); + } + } } }