private unsafe void loadEntryPoints(GraphicsBindingsBase bindings) { var type = bindings.GetType(); var pointsInfo = type.GetRuntimeFields().First(x => x.Name == "_EntryPointsInstance"); var namesInfo = type.GetRuntimeFields().First(x => x.Name == "_EntryPointNamesInstance"); var offsetsInfo = type.GetRuntimeFields().First(x => x.Name == "_EntryPointNameOffsetsInstance"); var entryPointsInstance = (IntPtr[])pointsInfo.GetValue(bindings); var entryPointNamesInstance = (byte[])namesInfo.GetValue(bindings); var entryPointNameOffsetsInstance = (int[])offsetsInfo.GetValue(bindings); Debug.Assert(entryPointsInstance != null); Debug.Assert(entryPointNameOffsetsInstance != null); fixed(byte *name = entryPointNamesInstance) { for (int i = 0; i < entryPointsInstance.Length; i++) { var ptr = name + entryPointNameOffsetsInstance[i]; var str = Marshal.PtrToStringAnsi(new IntPtr(ptr)); entryPointsInstance[i] = GetProcAddress(str); } } pointsInfo.SetValue(bindings, entryPointsInstance); }
public override void LoadAll() { //version 1 //new OpenTK.Graphics.ES10.GL().LoadEntryPoints(); //new OpenTK.Graphics.ES11.GL().LoadEntryPoints(); //new OpenTK.Graphics.ES20.GL().LoadEntryPoints(); //version 2 if (s_bindingBase == null) { s_bindingBase = new OpenTK.Graphics.ES20.GL(); s_bindingBase.LoadEntryPoints(); } }