mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-24 13:35:27 +00:00
Fixed creating contexts without native windows.
To create a context for the GTK GLWidget, you need to be able to specify the exact NSView you want the OpenGL context to apply to. Also, you don’t want to initialise the NSApplication in this situation, which the CocoaContext did before (unintentionally).
This commit is contained in:
parent
a79086bb20
commit
a24ce9ba11
|
@ -223,8 +223,6 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
AppKitLibrary = NS.LoadLibrary("/System/Library/Frameworks/AppKit.framework/AppKit");
|
AppKitLibrary = NS.LoadLibrary("/System/Library/Frameworks/AppKit.framework/AppKit");
|
||||||
FoundationLibrary = NS.LoadLibrary("/System/Library/Frameworks/Foundation.framework/Foundation");
|
FoundationLibrary = NS.LoadLibrary("/System/Library/Frameworks/Foundation.framework/Foundation");
|
||||||
|
|
||||||
NSApplication.Initialize();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,6 @@ namespace OpenTK.Platform.MacOS
|
||||||
static readonly IntPtr selNextEventMatchingMask = Selector.Get("nextEventMatchingMask:untilDate:inMode:dequeue:");
|
static readonly IntPtr selNextEventMatchingMask = Selector.Get("nextEventMatchingMask:untilDate:inMode:dequeue:");
|
||||||
static readonly IntPtr selSendEvent = Selector.Get("sendEvent:");
|
static readonly IntPtr selSendEvent = Selector.Get("sendEvent:");
|
||||||
//static readonly IntPtr selUpdateWindows = Selector.Get("updateWindows");
|
//static readonly IntPtr selUpdateWindows = Selector.Get("updateWindows");
|
||||||
static readonly IntPtr selContentView = Selector.Get("contentView");
|
|
||||||
static readonly IntPtr selConvertRectFromScreen = Selector.Get("convertRectFromScreen:");
|
static readonly IntPtr selConvertRectFromScreen = Selector.Get("convertRectFromScreen:");
|
||||||
static readonly IntPtr selConvertRectToScreen = Selector.Get("convertRectToScreen:");
|
static readonly IntPtr selConvertRectToScreen = Selector.Get("convertRectToScreen:");
|
||||||
static readonly IntPtr selPerformClose = Selector.Get("performClose:");
|
static readonly IntPtr selPerformClose = Selector.Get("performClose:");
|
||||||
|
@ -119,6 +118,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
static CocoaNativeWindow()
|
static CocoaNativeWindow()
|
||||||
{
|
{
|
||||||
Cocoa.Initialize();
|
Cocoa.Initialize();
|
||||||
|
NSApplication.Initialize(); // Problem: This does not allow creating a separate app and using CocoaNativeWindow.
|
||||||
NSDefaultRunLoopMode = Cocoa.GetStringConstant(Cocoa.FoundationLibrary, "NSDefaultRunLoopMode");
|
NSDefaultRunLoopMode = Cocoa.GetStringConstant(Cocoa.FoundationLibrary, "NSDefaultRunLoopMode");
|
||||||
NSCursor = Class.Get("NSCursor");
|
NSCursor = Class.Get("NSCursor");
|
||||||
}
|
}
|
||||||
|
@ -939,11 +939,6 @@ namespace OpenTK.Platform.MacOS
|
||||||
Dispose(false);
|
Dispose(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IntPtr GetView(IntPtr windowHandle)
|
|
||||||
{
|
|
||||||
return Cocoa.SendIntPtr(windowHandle, selContentView);
|
|
||||||
}
|
|
||||||
|
|
||||||
private RectangleF GetContentViewFrame()
|
private RectangleF GetContentViewFrame()
|
||||||
{
|
{
|
||||||
return Cocoa.SendRect(windowInfo.ViewHandle, selFrame);
|
return Cocoa.SendRect(windowInfo.ViewHandle, selFrame);
|
||||||
|
|
|
@ -40,7 +40,10 @@ namespace OpenTK.Platform.MacOS
|
||||||
/// </summary>
|
/// </summary>
|
||||||
sealed class CocoaWindowInfo : IWindowInfo
|
sealed class CocoaWindowInfo : IWindowInfo
|
||||||
{
|
{
|
||||||
|
static readonly IntPtr selContentView = Selector.Get("contentView");
|
||||||
|
|
||||||
IntPtr nsWindowRef;
|
IntPtr nsWindowRef;
|
||||||
|
IntPtr nsViewRef;
|
||||||
|
|
||||||
bool disposed = false;
|
bool disposed = false;
|
||||||
|
|
||||||
|
@ -49,10 +52,22 @@ namespace OpenTK.Platform.MacOS
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs a new instance with the specified parameters.
|
/// Constructs a new instance with the specified parameters.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="nsWindowRef">A valid NSView reference.</param>
|
/// <remarks>This constructor assumes that the NSWindow's contentView is the NSView we want to attach to our context.</remarks>
|
||||||
public CocoaWindowInfo(IntPtr nsWindowRef)
|
/// <param name="nsWindowRef">A valid NSWindow reference.</param>
|
||||||
|
public CocoaWindowInfo(IntPtr nsWindowRef) : this(nsWindowRef, Cocoa.SendIntPtr(nsWindowRef, selContentView))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructs a new instance with the specified parameters.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="nsWindowRef">A valid NSWindow reference.</param>
|
||||||
|
/// <param name="nsViewRef">A valid NSView reference.</param>
|
||||||
|
public CocoaWindowInfo(IntPtr nsWindowRef, IntPtr nsViewRef)
|
||||||
{
|
{
|
||||||
this.nsWindowRef = nsWindowRef;
|
this.nsWindowRef = nsWindowRef;
|
||||||
|
this.nsViewRef = nsViewRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -67,19 +82,13 @@ namespace OpenTK.Platform.MacOS
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the view reference for this instance.
|
/// Gets the view reference for this instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IntPtr ViewHandle
|
public IntPtr ViewHandle { get { return nsViewRef; } }
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return CocoaNativeWindow.GetView(nsWindowRef);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Returns a System.String that represents the current window.</summary>
|
/// <summary>Returns a System.String that represents the current window.</summary>
|
||||||
/// <returns>A System.String that represents the current window.</returns>
|
/// <returns>A System.String that represents the current window.</returns>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return String.Format("MacOS.CocoaWindowInfo: NSWindow {0}", nsWindowRef);
|
return String.Format("MacOS.CocoaWindowInfo: NSWindow {0}, NSView {1}", nsWindowRef, nsViewRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -309,12 +309,24 @@ namespace OpenTK.Platform
|
||||||
/// Creates an IWindowInfo instance for the Mac OS X platform.
|
/// Creates an IWindowInfo instance for the Mac OS X platform.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="windowHandle">The handle of the NSWindow.</param>
|
/// <param name="windowHandle">The handle of the NSWindow.</param>
|
||||||
|
/// <remarks>Assumes that the NSWindow's contentView is the NSView we want to attach to our context.</remarks>
|
||||||
/// <returns>A new IWindowInfo instance.</returns>
|
/// <returns>A new IWindowInfo instance.</returns>
|
||||||
public static IWindowInfo CreateMacOSWindowInfo(IntPtr windowHandle)
|
public static IWindowInfo CreateMacOSWindowInfo(IntPtr windowHandle)
|
||||||
{
|
{
|
||||||
return new OpenTK.Platform.MacOS.CocoaWindowInfo(windowHandle);
|
return new OpenTK.Platform.MacOS.CocoaWindowInfo(windowHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates an IWindowInfo instance for the Mac OS X platform.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="windowHandle">The handle of the NSWindow.</param>
|
||||||
|
/// <param name="viewHandle">The handle of the NSView.</param>
|
||||||
|
/// <returns>A new IWindowInfo instance.</returns>
|
||||||
|
public static IWindowInfo CreateMacOSWindowInfo(IntPtr windowHandle, IntPtr viewHandle)
|
||||||
|
{
|
||||||
|
return new OpenTK.Platform.MacOS.CocoaWindowInfo(windowHandle, viewHandle);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region CreateDummyWindowInfo
|
#region CreateDummyWindowInfo
|
||||||
|
|
Loading…
Reference in a new issue