diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index 87903b79..6b11da02 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -1,15 +1,8 @@ using System; using System.Threading; using System.ComponentModel; -using Gdk; using OpenTK.Graphics; -using OpenTK.Platform; - using Gtk; -using OpenTK.OSX; -using OpenTK.Platform.X11; -using OpenTK.Win; -using OpenTK.X11; namespace OpenTK { @@ -25,7 +18,6 @@ namespace OpenTK private static bool _SharedContextInitialized = false; private IGraphicsContext _GraphicsContext; - private IWindowInfo _WindowInfo; private bool _Initialized = false; /// @@ -240,23 +232,6 @@ namespace OpenTK return result; } - /// - /// Called whenever the widget is resized. - /// - /// - /// - protected override bool OnConfigureEvent(Gdk.EventConfigure evnt) - { - bool result = base.OnConfigureEvent(evnt); - - if (_GraphicsContext != null) - { - _GraphicsContext.Update(_WindowInfo); - } - - return result; - } - /// /// Initializes the with its given values and creates a . /// @@ -264,48 +239,11 @@ namespace OpenTK { _Initialized = true; - if (Configuration.RunningOnWindows) - { - Console.WriteLine("OpenTK running on windows"); - } - else if (Configuration.RunningOnMacOS) - { - Console.WriteLine("OpenTK running on OSX"); - } - else - { - Console.WriteLine("OpenTK running on X11"); - } - -#if GTK3 - IntPtr widgetWindowHandle = this.Window.Handle; -#else - IntPtr widgetWindowHandle = this.GdkWindow.Handle; -#endif - - // IWindowInfo - if (Configuration.RunningOnWindows) - { - _WindowInfo = WinWindowsInfoInitializer.Initialize(widgetWindowHandle); - } - else if (Configuration.RunningOnMacOS) - { - _WindowInfo = OSXWindowInfoInitializer.Initialize(widgetWindowHandle); - } - else - { - _WindowInfo = XWindowInfoInitializer.Initialize(this.Display.Handle, this.Screen.Number, widgetWindowHandle, this.Screen.RootWindow.Handle); - } - // Make the GDK GL context current MakeCurrent(); - // Create an OpenTK graphics context using the GdkGLContext as a foreign context - // Since the GDK context is already created and has been made current, we can retrieve its handle. - var gdkContextHandle = Factory.Default.CreateGetCurrentGraphicsContext()(); - - GetRequiredVersion(out int glVersionMajor, out int glVersionMinor); - _GraphicsContext = new GraphicsContext(gdkContextHandle, _WindowInfo, null, glVersionMajor, glVersionMinor, GraphicsContextFlags); + // Create a dummy context that will grab the GdkGLContext that is current on the thread + _GraphicsContext = new GraphicsContext(ContextHandle.Zero, null); if (GraphicsContext.ShareContexts) { diff --git a/src/OpenTK.GLWidget/OSX/OSXWindowInfoInitializer.cs b/src/OpenTK.GLWidget/OSX/OSXWindowInfoInitializer.cs deleted file mode 100644 index cfdba748..00000000 --- a/src/OpenTK.GLWidget/OSX/OSXWindowInfoInitializer.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Security; -using OpenTK.Platform; - -namespace OpenTK.OSX -{ - /// - /// Handler class for initializing objects under the OSX platform for both GTK2 and - /// GTK3. - /// - public static class OSXWindowInfoInitializer - { -#if GTK3 - private const string OSXLibGdkName = "libgdk-3.dylib"; -#else - const string OSXLibGdkName = "libgdk-quartz-2.0.0.dylib"; -#endif - - /// - /// Initializes an under the OSX platform. - /// - /// - public static IWindowInfo Initialize(IntPtr gdkWindowHandle) - { - IntPtr windowHandle = gdk_quartz_window_get_nswindow(gdkWindowHandle); - IntPtr viewHandle = gdk_quartz_window_get_nsview(gdkWindowHandle); - - return Utilities.CreateMacOSWindowInfo(windowHandle, viewHandle); - } - - [SuppressUnmanagedCodeSecurity, DllImport(OSXLibGdkName)] - private static extern IntPtr gdk_quartz_window_get_nswindow(IntPtr handle); - - [SuppressUnmanagedCodeSecurity, DllImport(OSXLibGdkName)] - private static extern IntPtr gdk_quartz_window_get_nsview(IntPtr handle); - } -} \ No newline at end of file diff --git a/src/OpenTK.GLWidget/OpenTK.GLWidget.csproj b/src/OpenTK.GLWidget/OpenTK.GLWidget.csproj index aeda128c..c82f52bd 100644 --- a/src/OpenTK.GLWidget/OpenTK.GLWidget.csproj +++ b/src/OpenTK.GLWidget/OpenTK.GLWidget.csproj @@ -98,13 +98,10 @@ - Code - - diff --git a/src/OpenTK.GLWidget/Win/WinWindowsInfoInitializer.cs b/src/OpenTK.GLWidget/Win/WinWindowsInfoInitializer.cs deleted file mode 100644 index 95303104..00000000 --- a/src/OpenTK.GLWidget/Win/WinWindowsInfoInitializer.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Security; -using OpenTK.Platform; - -namespace OpenTK.Win -{ - /// - /// Handler class for initializing objects under the Windows platform for both GTK2 and - /// GTK3. - /// - public static class WinWindowsInfoInitializer - { -#if GTK3 - private const string WinLibGDKName = "libgdk-3-0.dll"; -#else - private const string WinLibGDKName = "libgdk-win32-2.0-0.dll"; -#endif - - /// - /// Initializes an under the Windows platform. - /// - /// - public static IWindowInfo Initialize(IntPtr gdkWindowHandle) - { -#if GTK3 - IntPtr windowHandle = gdk_win32_window_get_handle(gdkWindowHandle); -#else - IntPtr windowHandle = gdk_win32_drawable_get_handle(gdkWindowHandle); -#endif - return Utilities.CreateWindowsWindowInfo(windowHandle); - } - -#if GTK3 - [SuppressUnmanagedCodeSecurity, DllImport(WinLibGDKName, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr gdk_win32_window_get_handle(IntPtr w); -#else - [SuppressUnmanagedCodeSecurity, DllImport(WinLibGDKName, CallingConvention = CallingConvention.Cdecl)] - static extern IntPtr gdk_win32_drawable_get_handle(IntPtr d); -#endif - - } -} \ No newline at end of file diff --git a/src/OpenTK.GLWidget/X11/XWindowInfoInitializer.cs b/src/OpenTK.GLWidget/X11/XWindowInfoInitializer.cs deleted file mode 100644 index cc9ec9fe..00000000 --- a/src/OpenTK.GLWidget/X11/XWindowInfoInitializer.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Security; -using OpenTK.Graphics; -using OpenTK.Platform; -using OpenTK.Platform.X11; - -namespace OpenTK.X11 -{ - /// - /// Handler class for initializing objects under the X11 platform for both GTK2 and GTK3. - /// - public static class XWindowInfoInitializer - { - -#if GTK3 - private const string UnixLibGdkName = "libgdk-3.so.0"; -#else - const string UnixLibGdkName = "libgdk-x11-2.0.so.0"; -#endif - /// - /// Initializes an under the X11 platform. - /// - /// - /// - /// - /// - /// - public static IWindowInfo Initialize(IntPtr displayHandle, int screenNumber, IntPtr gdkWindowHandle, IntPtr gdkRootWindowHandle) - { - IntPtr display = gdk_x11_display_get_xdisplay(displayHandle); - -#if GTK3 - IntPtr windowXid = gdk_x11_window_get_xid(gdkWindowHandle); - IntPtr rootWindowXid = gdk_x11_window_get_xid(gdkRootWindowHandle); -#else - IntPtr windowXid = gdk_x11_drawable_get_xid(gdkWindowHandle); - IntPtr rootWindowXid = gdk_x11_drawable_get_xid(gdkRootWindowHandle); -#endif - - // No visual needs to be passed here, since we're piggybacking on the GdkGLContext from the base GLArea - IWindowInfo retval = Utilities.CreateX11WindowInfo(display, screenNumber, windowXid, rootWindowXid, IntPtr.Zero); - - return retval; - } - -#if GTK3 - /// Returns the X resource (window or pixmap) belonging to a GdkWindow. - /// XID gdk_x11_window_get_xid(GdkWindow *drawable); - /// The GdkDrawable. - /// The ID of window's X resource. - [SuppressUnmanagedCodeSecurity, DllImport(UnixLibGdkName)] - private static extern IntPtr gdk_x11_window_get_xid(IntPtr gdkDisplay); -#else - /// Returns the X resource (window or pixmap) belonging to a GdkDrawable. - /// XID gdk_x11_drawable_get_xid(GdkDrawable *drawable); - /// The GdkDrawable. - /// The ID of drawable's X resource. - [SuppressUnmanagedCodeSecurity, DllImport(UnixLibGdkName)] - static extern IntPtr gdk_x11_drawable_get_xid(IntPtr gdkDisplay); -#endif - /// Returns the X display of a GdkDisplay. - /// Display* gdk_x11_display_get_xdisplay(GdkDisplay *display); - /// The GdkDrawable. - /// The X Display of the GdkDisplay. - [SuppressUnmanagedCodeSecurity, DllImport(UnixLibGdkName)] - private static extern IntPtr gdk_x11_display_get_xdisplay(IntPtr gdkDisplay); - } -} \ No newline at end of file