diff --git a/Source/OpenTK/Platform/MacOS/AglContext.cs b/Source/OpenTK/Platform/MacOS/AglContext.cs index 36872054..c2bf34e9 100644 --- a/Source/OpenTK/Platform/MacOS/AglContext.cs +++ b/Source/OpenTK/Platform/MacOS/AglContext.cs @@ -125,10 +125,14 @@ namespace OpenTK.Platform.MacOS // Choose a pixel format with the attributes we specified. if (fullscreen) { - IntPtr gdevice; - + IntPtr gdevice; + IntPtr cgdevice = GetQuartzDevice(carbonWindow); + + if (cgdevice == IntPtr.Zero) + cgdevice = QuartzDisplayDeviceDriver.MainDisplay; + OSStatus status = Carbon.API.DMGetGDeviceByDisplayID( - QuartzDisplayDeviceDriver.MainDisplay, out gdevice, false); + cgdevice, out gdevice, false); if (status != OSStatus.NoError) throw new MacOSException(status, "DMGetGDeviceByDisplayID failed."); @@ -177,6 +181,26 @@ namespace OpenTK.Platform.MacOS Debug.Print("context: {0}", Handle.Handle); } + private IntPtr GetQuartzDevice(CarbonWindowInfo carbonWindow) + { + IntPtr windowRef = carbonWindow.WindowRef; + + if (CarbonGLNative.WindowRefMap.ContainsKey(windowRef) == false) + return IntPtr.Zero; + + WeakReference nativeRef = CarbonGLNative.WindowRefMap[windowRef]; + if (nativeRef.IsAlive == false) + return IntPtr.Zero; + + CarbonGLNative window = nativeRef.Target as CarbonGLNative; + + if (window == null) + return IntPtr.Zero; + + return QuartzDisplayDeviceDriver.HandleTo(window.TargetDisplayDevice); + + } + void SetBufferRect(CarbonWindowInfo carbonWindow) { if (carbonWindow.IsControl == false) diff --git a/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs b/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs index d4c65a92..47044bfc 100644 --- a/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs +++ b/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs @@ -53,6 +53,7 @@ namespace OpenTK.Platform.MacOS Rectangle bounds, windowedBounds, clientRectangle; bool mIsDisposed = false; bool mExists = true; + DisplayDevice mDisplayDevice; WindowAttributes mWindowAttrib; WindowClass mWindowClass; @@ -65,9 +66,16 @@ namespace OpenTK.Platform.MacOS #endregion - #region Constructors + #region AGL Device Hack - static CarbonGLNative() + static internal Dictionary WindowRefMap { get { return mWindows; } } + internal DisplayDevice TargetDisplayDevice { get { return mDisplayDevice; } } + + #endregion + + #region Constructors + + static CarbonGLNative() { Application.Initialize(); } @@ -93,6 +101,8 @@ namespace OpenTK.Platform.MacOS WindowAttributes.StandardDocument | WindowAttributes.StandardHandler | WindowAttributes.InWindowMenu | WindowAttributes.LiveResize, new Rect((short)x, (short)y, (short)width, (short)height)); + + mDisplayDevice = device; } #endregion diff --git a/Source/OpenTK/Platform/MacOS/QuartzDisplayDeviceDriver.cs b/Source/OpenTK/Platform/MacOS/QuartzDisplayDeviceDriver.cs index 26f873cd..3f3e65af 100644 --- a/Source/OpenTK/Platform/MacOS/QuartzDisplayDeviceDriver.cs +++ b/Source/OpenTK/Platform/MacOS/QuartzDisplayDeviceDriver.cs @@ -106,6 +106,15 @@ namespace OpenTK.Platform.MacOS } } + + internal static IntPtr HandleTo(DisplayDevice displayDevice) + { + if (displayMap.ContainsKey(displayDevice)) + return displayMap[displayDevice]; + else + return IntPtr.Zero; + } + #region IDisplayDeviceDriver Members Dictionary storedModes = new Dictionary(); @@ -173,5 +182,6 @@ namespace OpenTK.Platform.MacOS } #endregion - } + + } }