diff --git a/Source/OpenTK/Platform/MacOS/AglContext.cs b/Source/OpenTK/Platform/MacOS/AglContext.cs index e1b7f594..927d671c 100644 --- a/Source/OpenTK/Platform/MacOS/AglContext.cs +++ b/Source/OpenTK/Platform/MacOS/AglContext.cs @@ -89,7 +89,7 @@ namespace OpenTK.Platform.MacOS AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_BLUE_SIZE, mode.AccumulatorFormat.Blue); AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_ALPHA_SIZE, mode.AccumulatorFormat.Alpha); } - //AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_FULLSCREEN); + AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_FULLSCREEN); AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_NONE); Debug.Unindent(); @@ -100,14 +100,23 @@ namespace OpenTK.Platform.MacOS Debug.WriteLine(""); AGLPixelFormat myAGLPixelFormat; - IntPtr shareContextRef = IntPtr.Zero; + IntPtr gdevice; + + OSStatus status = Carbon.API.DMGetGDeviceByDisplayID( + QuartzDisplayDeviceDriver.MainDisplay, out gdevice, false); + if (status != OSStatus.NoError) + throw new MacOSException(status, "DMGetGDeviceByDisplayID failed."); // Choose a pixel format with the attributes we specified. - myAGLPixelFormat = Agl.aglChoosePixelFormat(QuartzDisplayDeviceDriver.MainDisplay, - 1, aglAttributes.ToArray()); + myAGLPixelFormat = Agl.aglChoosePixelFormat( + ref gdevice, 1, + //IntPtr.Zero, 0, + aglAttributes.ToArray()); MyAGLReportError("aglChoosePixelFormat"); + + IntPtr shareContextRef = IntPtr.Zero; if (shareContext != null) { Debug.Print("shareContext type is {0}", shareContext.GetType()); @@ -216,7 +225,7 @@ namespace OpenTK.Platform.MacOS internal void SetFullScreen() { - Agl.aglSetFullScreen(contextRef, 0, 0, 0, 0); + Agl.aglSetFullScreen(contextRef, 640, 480, 60, 0); } internal void UnsetFullScreen() { diff --git a/Source/OpenTK/Platform/MacOS/CarbonBindings/Agl.cs b/Source/OpenTK/Platform/MacOS/CarbonBindings/Agl.cs index a0eef103..7484f762 100644 --- a/Source/OpenTK/Platform/MacOS/CarbonBindings/Agl.cs +++ b/Source/OpenTK/Platform/MacOS/CarbonBindings/Agl.cs @@ -8,6 +8,7 @@ // using System; +using System.Diagnostics; using System.Runtime.InteropServices; namespace OpenTK.Platform.MacOS @@ -279,7 +280,7 @@ namespace OpenTK.Platform.MacOS /* ** Pixel format functions */ - [DllImport(agl)] internal static extern AGLPixelFormat aglChoosePixelFormat(AGLDevice gdevs, int ndev, int []attribs); + [DllImport(agl)] internal static extern AGLPixelFormat aglChoosePixelFormat(ref AGLDevice gdevs, int ndev, int []attribs); [DllImport(agl)] internal static extern void aglDestroyPixelFormat(AGLPixelFormat pix); [DllImport(agl)] internal static extern AGLPixelFormat aglNextPixelFormat(AGLPixelFormat pix); [DllImport(agl)] static extern byte aglDescribePixelFormat(AGLPixelFormat pix, int attrib, out int value); @@ -331,11 +332,40 @@ namespace OpenTK.Platform.MacOS /* ** Drawable Functions */ - [DllImport(agl)] internal static extern byte aglSetDrawable(AGLContext ctx, AGLDrawable draw); + [DllImport(agl,EntryPoint="aglSetDrawable")] + static extern byte _aglSetDrawable(AGLContext ctx, AGLDrawable draw); + + internal static void aglSetDrawable(AGLContext ctx, AGLDrawable draw) + { + byte retval = _aglSetDrawable(ctx, draw); + + if (retval == 0) + { + AglError err = GetError(); + + throw new MacOSException(err, ErrorString(err)); + } + } [DllImport(agl)] static extern byte aglSetOffScreen(AGLContext ctx, int width, int height, int rowbytes, IntPtr baseaddr); - [DllImport(agl)] internal static extern byte aglSetFullScreen(AGLContext ctx, int width, int height, int freq, int device); [DllImport(agl)] static extern AGLDrawable aglGetDrawable(AGLContext ctx); - + + [DllImport(agl, EntryPoint = "aglSetFullScreen")] + static extern byte _aglSetFullScreen(AGLContext ctx, int width, int height, int freq, int device); + internal static void aglSetFullScreen(AGLContext ctx, int width, int height, int freq, int device) + { + byte retval = _aglSetFullScreen(ctx, width, height, freq, device); + + if (retval == 0) + { + AglError err = GetError(); + Debug.Print("AGL Error: {0}", err); + Debug.Indent(); + Debug.Print(ErrorString(err)); + Debug.Unindent(); + + throw new MacOSException(err, ErrorString(err)); + } + } /* ** Virtual screen functions */ diff --git a/Source/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs b/Source/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs index 067fcc2c..2187d760 100644 --- a/Source/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs +++ b/Source/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs @@ -848,6 +848,11 @@ namespace OpenTK.Platform.MacOS.Carbon } } + [DllImport(carbon)] + internal unsafe static extern OSStatus DMGetGDeviceByDisplayID( + IntPtr displayID, out IntPtr displayDevice, Boolean failToMain); + + } #endregion diff --git a/Source/OpenTK/Platform/MacOS/MacOSException.cs b/Source/OpenTK/Platform/MacOS/MacOSException.cs index 9ea1ad46..a120d2f6 100644 --- a/Source/OpenTK/Platform/MacOS/MacOSException.cs +++ b/Source/OpenTK/Platform/MacOS/MacOSException.cs @@ -19,7 +19,11 @@ namespace OpenTK.Platform.MacOS { this.errorCode = errorCode; } - + internal MacOSException(Agl.AglError errorCode, string message) + : base(message) + { + this.errorCode = (OSStatus)errorCode; + } public OSStatus ErrorCode {