Removed redundant WindowInfo initializer.
This commit is contained in:
parent
5df8f47d18
commit
29863f13da
5 changed files with 2 additions and 218 deletions
|
@ -1,15 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using Gdk;
|
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using OpenTK.Platform;
|
|
||||||
|
|
||||||
using Gtk;
|
using Gtk;
|
||||||
using OpenTK.OSX;
|
|
||||||
using OpenTK.Platform.X11;
|
|
||||||
using OpenTK.Win;
|
|
||||||
using OpenTK.X11;
|
|
||||||
|
|
||||||
namespace OpenTK
|
namespace OpenTK
|
||||||
{
|
{
|
||||||
|
@ -25,7 +18,6 @@ namespace OpenTK
|
||||||
private static bool _SharedContextInitialized = false;
|
private static bool _SharedContextInitialized = false;
|
||||||
|
|
||||||
private IGraphicsContext _GraphicsContext;
|
private IGraphicsContext _GraphicsContext;
|
||||||
private IWindowInfo _WindowInfo;
|
|
||||||
private bool _Initialized = false;
|
private bool _Initialized = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -240,23 +232,6 @@ namespace OpenTK
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called whenever the widget is resized.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="evnt"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
protected override bool OnConfigureEvent(Gdk.EventConfigure evnt)
|
|
||||||
{
|
|
||||||
bool result = base.OnConfigureEvent(evnt);
|
|
||||||
|
|
||||||
if (_GraphicsContext != null)
|
|
||||||
{
|
|
||||||
_GraphicsContext.Update(_WindowInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the <see cref="GLWidget"/> with its given values and creates a <see cref="GraphicsContext"/>.
|
/// Initializes the <see cref="GLWidget"/> with its given values and creates a <see cref="GraphicsContext"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -264,48 +239,11 @@ namespace OpenTK
|
||||||
{
|
{
|
||||||
_Initialized = true;
|
_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
|
// Make the GDK GL context current
|
||||||
MakeCurrent();
|
MakeCurrent();
|
||||||
|
|
||||||
// Create an OpenTK graphics context using the GdkGLContext as a foreign context
|
// Create a dummy context that will grab the GdkGLContext that is current on the thread
|
||||||
// Since the GDK context is already created and has been made current, we can retrieve its handle.
|
_GraphicsContext = new GraphicsContext(ContextHandle.Zero, null);
|
||||||
var gdkContextHandle = Factory.Default.CreateGetCurrentGraphicsContext()();
|
|
||||||
|
|
||||||
GetRequiredVersion(out int glVersionMajor, out int glVersionMinor);
|
|
||||||
_GraphicsContext = new GraphicsContext(gdkContextHandle, _WindowInfo, null, glVersionMajor, glVersionMinor, GraphicsContextFlags);
|
|
||||||
|
|
||||||
if (GraphicsContext.ShareContexts)
|
if (GraphicsContext.ShareContexts)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Security;
|
|
||||||
using OpenTK.Platform;
|
|
||||||
|
|
||||||
namespace OpenTK.OSX
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Handler class for initializing <see cref="IWindowInfo"/> objects under the OSX platform for both GTK2 and
|
|
||||||
/// GTK3.
|
|
||||||
/// </summary>
|
|
||||||
public static class OSXWindowInfoInitializer
|
|
||||||
{
|
|
||||||
#if GTK3
|
|
||||||
private const string OSXLibGdkName = "libgdk-3.dylib";
|
|
||||||
#else
|
|
||||||
const string OSXLibGdkName = "libgdk-quartz-2.0.0.dylib";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes an <see cref="IWindowInfo"/> under the OSX platform.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="gdkWindowHandle"></param>
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -98,13 +98,10 @@
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="OSX\OSXWindowInfoInitializer.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs">
|
<Compile Include="Properties\AssemblyInfo.cs">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="GLWidget.cs" />
|
<Compile Include="GLWidget.cs" />
|
||||||
<Compile Include="Win\WinWindowsInfoInitializer.cs" />
|
|
||||||
<Compile Include="X11\XWindowInfoInitializer.cs" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="paket.references" />
|
<None Include="paket.references" />
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Security;
|
|
||||||
using OpenTK.Platform;
|
|
||||||
|
|
||||||
namespace OpenTK.Win
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Handler class for initializing <see cref="IWindowInfo"/> objects under the Windows platform for both GTK2 and
|
|
||||||
/// GTK3.
|
|
||||||
/// </summary>
|
|
||||||
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
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes an <see cref="IWindowInfo"/> under the Windows platform.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="gdkWindowHandle"></param>
|
|
||||||
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
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Handler class for initializing <see cref="IWindowInfo"/> objects under the X11 platform for both GTK2 and GTK3.
|
|
||||||
/// </summary>
|
|
||||||
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
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes an <see cref="IWindowInfo"/> under the X11 platform.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="displayHandle"></param>
|
|
||||||
/// <param name="screenNumber"></param>
|
|
||||||
/// <param name="gdkWindowHandle"></param>
|
|
||||||
/// <param name="gdkRootWindowHandle"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
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
|
|
||||||
/// <summary> Returns the X resource (window or pixmap) belonging to a GdkWindow. </summary>
|
|
||||||
/// <remarks> XID gdk_x11_window_get_xid(GdkWindow *drawable); </remarks>
|
|
||||||
/// <param name="gdkDisplay"> The GdkDrawable. </param>
|
|
||||||
/// <returns> The ID of window's X resource. </returns>
|
|
||||||
[SuppressUnmanagedCodeSecurity, DllImport(UnixLibGdkName)]
|
|
||||||
private static extern IntPtr gdk_x11_window_get_xid(IntPtr gdkDisplay);
|
|
||||||
#else
|
|
||||||
/// <summary> Returns the X resource (window or pixmap) belonging to a GdkDrawable. </summary>
|
|
||||||
/// <remarks> XID gdk_x11_drawable_get_xid(GdkDrawable *drawable); </remarks>
|
|
||||||
/// <param name="gdkDisplay"> The GdkDrawable. </param>
|
|
||||||
/// <returns> The ID of drawable's X resource. </returns>
|
|
||||||
[SuppressUnmanagedCodeSecurity, DllImport(UnixLibGdkName)]
|
|
||||||
static extern IntPtr gdk_x11_drawable_get_xid(IntPtr gdkDisplay);
|
|
||||||
#endif
|
|
||||||
/// <summary> Returns the X display of a GdkDisplay. </summary>
|
|
||||||
/// <remarks> Display* gdk_x11_display_get_xdisplay(GdkDisplay *display); </remarks>
|
|
||||||
/// <param name="gdkDisplay"> The GdkDrawable. </param>
|
|
||||||
/// <returns> The X Display of the GdkDisplay. </returns>
|
|
||||||
[SuppressUnmanagedCodeSecurity, DllImport(UnixLibGdkName)]
|
|
||||||
private static extern IntPtr gdk_x11_display_get_xdisplay(IntPtr gdkDisplay);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue