From ae1838f3d3a980bcf796f2647321d6cde9d7dd15 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Sat, 19 Jan 2008 15:27:15 +0000 Subject: [PATCH] GetDelegate does not load OpenGL functions anymore (use the Load and LoadAll methods for that). Added GetDelegate method that takes a simple string (no type information). Deprecated existing GetDelegate method. --- Source/OpenTK/OpenGL/GLHelper.cs | 73 +++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 15 deletions(-) diff --git a/Source/OpenTK/OpenGL/GLHelper.cs b/Source/OpenTK/OpenGL/GLHelper.cs index f82617ec..53bf53a6 100644 --- a/Source/OpenTK/OpenGL/GLHelper.cs +++ b/Source/OpenTK/OpenGL/GLHelper.cs @@ -33,13 +33,12 @@ namespace OpenTK.OpenGL /// This class contains all OpenGL enums and functions defined in the 2.1 specification. /// The official .spec files can be found at: http://opengl.org/registry/. /// - /// - /// A valid OpenGL context must be created before calling any OpenGL function. - /// + /// A valid OpenGL context must be created before calling any OpenGL function. /// /// Use the GL.Load and GL.LoadAll methods to prepare function entry points prior to use. To maintain /// cross-platform compatibility, this must be done for both core and extension functions. The GameWindow /// and the GLControl class will take care of this automatically. + /// /// /// You can use the GL.SupportsExtension method to check whether any given category of extension functions /// exists in the current OpenGL context. Keep in mind that different OpenGL contexts may support different @@ -49,16 +48,17 @@ namespace OpenTK.OpenGL /// /// You may retrieve the entry point for an OpenGL function using the GL.GetDelegate method. /// - /// + /// /// /// /// /// /// - /// - /// public static partial class GL { + delegate void VoidGLDelegate(object @class, object[] parameters); + delegate object ObjectGLDelegate(object @class, object[] parameters); + #region --- Fields --- internal const string Library = "opengl32.dll"; @@ -134,10 +134,33 @@ namespace OpenTK.OpenGL #endregion + #region public static Delegate GetDelegate(string name) + + /// + /// Returns a System.Delegate wrapping the specified OpenGL function. You must use the + /// base OpenGL name of the function (e.g. "glVertex3fv" instead of "Vertex3"). + /// + /// The name of the OpenGL function (eg. "glNewList") + /// The signature of the OpenGL function. + /// + /// A System.Delegate that can be used to call this OpenGL function or null, if the specified + /// function name does not correspond to an OpenGL function or if the function is not + /// supported by the video drivers. + /// + public static Delegate GetDelegate(string name) + { + FieldInfo info = typeof(Delegates).GetField(name, BindingFlags.Static | BindingFlags.NonPublic); + if (info == null) + return null; + return (Delegate)info.GetValue(null); + } + + #endregion + #region public static Delegate GetDelegate(string name, Type signature) /// - /// Creates a System.Delegate that can be used to call an OpenGL function, core or extension. + /// Returns a System.Delegate wrapping an OpenGL function. /// /// The name of the OpenGL function (eg. "glNewList") /// The signature of the OpenGL function. @@ -145,14 +168,10 @@ namespace OpenTK.OpenGL /// A System.Delegate that can be used to call this OpenGL function, or null if the specified /// function name did not correspond to an OpenGL function. /// + [Obsolete("Use GetDelegate(string name) instead.")] public static Delegate GetDelegate(string name, Type signature) { - MethodInfo m; - return - GetExtensionDelegate(name, signature) ?? - /*((m = importsClass.GetMethod(name.Substring(2), BindingFlags.Static | BindingFlags.NonPublic)) != null ?*/ - (Imports.FunctionMap.TryGetValue((name.Substring(2)), out m) ? - Delegate.CreateDelegate(signature, m) : null); + return LoadDelegate(name, signature); } #endregion @@ -192,7 +211,7 @@ namespace OpenTK.OpenGL foreach (FieldInfo f in delegates) { - Delegate d = GetDelegate(f.Name, f.FieldType); + Delegate d = LoadDelegate(f.Name, f.FieldType); if (d != null) { ++supported; @@ -246,7 +265,7 @@ namespace OpenTK.OpenGL return false; Delegate old = f.GetValue(null) as Delegate; - Delegate @new = GetDelegate(f.Name, f.FieldType); + Delegate @new = LoadDelegate(f.Name, f.FieldType); if (old.Target != @new.Target) { f.SetValue(null, @new); @@ -257,6 +276,30 @@ namespace OpenTK.OpenGL #endregion + #region static Delegate LoadDelegate(string name, Type signature) + + /// + /// + /// Loads an OpenGL function into a type-safe System.Delegate. + /// + /// The name of the OpenGL function (eg. "glNewList") + /// The signature of the OpenGL function. + /// + /// A System.Delegate that can be used to call this OpenGL function, or null if the specified + /// function name did not correspond to an OpenGL function. + /// + static Delegate LoadDelegate(string name, Type signature) + { + MethodInfo m; + return + GetExtensionDelegate(name, signature) ?? + /*((m = importsClass.GetMethod(name.Substring(2), BindingFlags.Static | BindingFlags.NonPublic)) != null ?*/ + (Imports.FunctionMap.TryGetValue((name.Substring(2)), out m) ? + Delegate.CreateDelegate(signature, m) : null); + } + + #endregion + #region public static bool SupportsFunction(string function) ///