00001 #region --- License ---
00002
00003
00004
00005
00006
00007
00008 #endregion
00009
00010 using System;
00011 using System.Runtime.InteropServices;
00012 using System.Reflection;
00013
00014 namespace OpenTK.Platform.Windows
00015 {
00016 internal partial class Wgl
00017 {
00018 #region --- Constructors ---
00019
00020 static Wgl()
00021 {
00022 assembly = Assembly.GetExecutingAssembly();
00023 wglClass = assembly.GetType("OpenTK.Platform.Windows.Wgl");
00024 delegatesClass = wglClass.GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic);
00025 importsClass = wglClass.GetNestedType("Imports", BindingFlags.Static | BindingFlags.NonPublic);
00026
00027
00028
00029 LoadAll();
00030 }
00031
00032 #endregion
00033
00034 #region --- Fields ---
00035
00036 internal const string Library = "OPENGL32.DLL";
00037
00038 private static Assembly assembly;
00039 private static Type wglClass;
00040 private static Type delegatesClass;
00041 private static Type importsClass;
00042
00043 private static bool rebuildExtensionList = true;
00044
00045 #endregion
00046
00047 #region static Delegate LoadDelegate(string name, Type signature)
00048
00058 static Delegate LoadDelegate(string name, Type signature)
00059 {
00060 Delegate d;
00061 string realName = name.StartsWith("wgl") ? name.Substring(3) : name;
00062
00063 if (importsClass.GetMethod(realName,
00064 BindingFlags.NonPublic | BindingFlags.Static) != null)
00065 d = GetExtensionDelegate(name, signature) ??
00066 Delegate.CreateDelegate(signature, typeof(Imports), realName);
00067 else
00068 d = GetExtensionDelegate(name, signature);
00069
00070 return d;
00071 }
00072
00073 #endregion
00074
00075 #region private static Delegate GetExtensionDelegate(string name, Type signature)
00076
00086 private static Delegate GetExtensionDelegate(string name, Type signature)
00087 {
00088 IntPtr address = Imports.GetProcAddress(name);
00089
00090 if (address == IntPtr.Zero ||
00091 address == new IntPtr(1) ||
00092 address == new IntPtr(2))
00093 {
00094 return null;
00095 }
00096 else
00097 {
00098 return Marshal.GetDelegateForFunctionPointer(address, signature);
00099 }
00100 }
00101
00102 #endregion
00103
00104 #region public static void LoadAll()
00105
00109 public static void LoadAll()
00110 {
00111 OpenTK.Platform.Utilities.LoadExtensions(typeof(Wgl));
00112 }
00113
00114 #endregion
00115
00116 #region public static bool Load(string function)
00117
00123 public static bool Load(string function)
00124 {
00125 return OpenTK.Platform.Utilities.TryLoadExtension(typeof(Wgl), function);
00126 }
00127
00128 #endregion
00129
00130 #region public static partial class Arb
00131
00133 public static partial class Arb
00134 {
00141 public static bool SupportsExtension(WinGLContext context, string ext)
00142 {
00143
00144
00145
00146
00147
00148 Wgl.Delegates.GetExtensionsStringARB get = Wgl.Delegates.wglGetExtensionsStringARB;
00149
00150 if (get != null)
00151 {
00152 string[] extensions = null;
00153 unsafe
00154 {
00155 extensions = new string((sbyte*)get(context.DeviceContext))
00156 .Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
00157 }
00158 if (extensions == null || extensions.Length == 0)
00159 return false;
00160
00161 foreach (string s in extensions)
00162 if (s == ext)
00163 return true;
00164 }
00165 return false;
00166 }
00167 }
00168
00169 #endregion
00170
00171 #region public static partial class Ext
00172
00174 public static partial class Ext
00175 {
00176 private static string[] extensions;
00182 public static bool SupportsExtension(string ext)
00183 {
00184 if (Wgl.Delegates.wglGetExtensionsStringEXT != null)
00185 {
00186 if (extensions == null || rebuildExtensionList)
00187 {
00188 extensions = Wgl.Ext.GetExtensionsString().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
00189 Array.Sort(extensions);
00190 rebuildExtensionList = false;
00191 }
00192
00193 return Array.BinarySearch(extensions, ext) != -1;
00194 }
00195 return false;
00196 }
00197 }
00198
00199 #endregion
00200 }
00201 }