Added static GetExtensionDelegate implementation

This commit is contained in:
Stefanos A 2013-11-22 20:06:04 +01:00
parent 2ace001203
commit ffe934fa5d

View file

@ -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);
}
}
}
}