MacOS: Hack for AGL to have access to the display device specified when a NativeWindow is created.

This commit is contained in:
kanato 2009-11-09 07:50:21 +00:00
parent 56412367c4
commit 62b65af462
3 changed files with 50 additions and 6 deletions

View file

@ -126,9 +126,13 @@ namespace OpenTK.Platform.MacOS
if (fullscreen)
{
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)

View file

@ -53,6 +53,7 @@ namespace OpenTK.Platform.MacOS
Rectangle bounds, windowedBounds, clientRectangle;
bool mIsDisposed = false;
bool mExists = true;
DisplayDevice mDisplayDevice;
WindowAttributes mWindowAttrib;
WindowClass mWindowClass;
@ -63,6 +64,13 @@ namespace OpenTK.Platform.MacOS
static Dictionary<IntPtr, WeakReference> mWindows = new Dictionary<IntPtr, WeakReference>();
#endregion
#region AGL Device Hack
static internal Dictionary<IntPtr, WeakReference> WindowRefMap { get { return mWindows; } }
internal DisplayDevice TargetDisplayDevice { get { return mDisplayDevice; } }
#endregion
#region Constructors
@ -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

View file

@ -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<IntPtr, IntPtr> storedModes = new Dictionary<IntPtr, IntPtr>();
@ -173,5 +182,6 @@ namespace OpenTK.Platform.MacOS
}
#endregion
}
}