internal WGLInterop() { WglDXCloseDeviceNV = Assign <wglDXCloseDeviceNV>(); WglDXLockObjectsNV = Assign <wglDXLockObjectsNV>(); WglDXObjectAccessNV = Assign <wglDXObjectAccessNV>(); WglDXOpenDeviceNV = Assign <wglDXOpenDeviceNV>(); WglDXRegisterObjectNV = Assign <wglDXRegisterObjectNV>(); WglDXSetResourceShareHandleNV = Assign <wglDXSetResourceShareHandleNV>(); WglDXUnlockObjectsNV = Assign <wglDXUnlockObjectsNV>(); WglDXUnregisterObjectNV = Assign <wglDXUnregisterObjectNV>(); }
public WGL_NV_DX_interop() { var wgl = typeof(OpenTK.Platform.Windows.All).Assembly.GetType("OpenTK.Platform.Windows.Wgl", true); var wglInstance = wgl.GetConstructor(new Type[] { }).Invoke(new object[] { }); // STATIC (but not visible) METHODS // Public (even though the class isn't?!) var wglSupportsExtension = (Func <string, bool>)wgl.GetMethods().Where(m => m.Name == "SupportsExtension" && m.GetParameters().Length == 1).Single().CreateDelegate(typeof(Func <string, bool>)); var wglSupportsFunction = (Func <string, bool>)wgl.GetMethods().Where(m => m.Name == "SupportsFunction" && m.GetParameters().Length == 1).Single().CreateDelegate(typeof(Func <string, bool>)); // Private wglIsValid = (Func <IntPtr, bool>)wgl.GetMethod("IsValid", BindingFlags.NonPublic | BindingFlags.Static).CreateDelegate(typeof(Func <IntPtr, bool>)); // INSTANCE (still invisible!) METHODS // Protected wglGetAddress = (Func <string, IntPtr>)wgl.GetMethod("GetAddress", BindingFlags.NonPublic | BindingFlags.Instance).CreateDelegate(typeof(Func <string, IntPtr>), wglInstance); if (!wglSupportsExtension("WGL_NV_DX_interop")) { throw new NotSupportedException("OpenGL (WGL) doesn't support WGL_NV_DX_interop. Can't use WPF with OpenGL."); } this.WglDXCloseDeviceNV = fetch <wglDXCloseDeviceNV>(); this.WglDXLockObjectsNV = fetch <wglDXLockObjectsNV>(); this.WglDXObjectAccessNV = fetch <wglDXObjectAccessNV>(); this.WglDXOpenDeviceNV = fetch <wglDXOpenDeviceNV>(); this.WglDXRegisterObjectNV = fetch <wglDXRegisterObjectNV>(); this.WglDXSetResourceShareHandleNV = fetch <wglDXSetResourceShareHandleNV>(); this.WglDXUnlockObjectsNV = fetch <wglDXUnlockObjectsNV>(); this.WglDXUnregisterObjectNV = fetch <wglDXUnregisterObjectNV>(); // calling getaddress'd thing: // [UnmanagedFunctionPointer(CallingConvention.Cdecl)] // private delegate int MultiplyByTen(int num); // // IntPtr pAddr=..getprocadddr.. // MultiplyByTen multiplyByTen = (MultiplyByTen) Marshal.GetDelegateForFunctionPointer(pAddr, typeof(MultiplyByTen)); }