From 231f83186afd222f0053b753c7b25d05489d273a Mon Sep 17 00:00:00 2001 From: kanato Date: Wed, 11 Feb 2009 08:03:46 +0000 Subject: [PATCH] AGL Fullscreen: Try to create a full screen context first, failing that create a non-fullscreen context. --- Source/OpenTK/Platform/MacOS/AglContext.cs | 23 +++++++++++++++----- Source/OpenTK/Platform/MacOS/MacOSFactory.cs | 2 +- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Source/OpenTK/Platform/MacOS/AglContext.cs b/Source/OpenTK/Platform/MacOS/AglContext.cs index 2cc923a3..08edd8e7 100644 --- a/Source/OpenTK/Platform/MacOS/AglContext.cs +++ b/Source/OpenTK/Platform/MacOS/AglContext.cs @@ -40,7 +40,7 @@ namespace OpenTK.Platform.MacOS if (GraphicsContext.GetCurrentContext == null) GraphicsContext.GetCurrentContext = AglContext.GetCurrentContext; } - public AglContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool fullscreen) + public AglContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext) { Debug.Print("Context Type: {0}", shareContext); Debug.Print("Window info: {0}", window); @@ -48,11 +48,10 @@ namespace OpenTK.Platform.MacOS this.mode = mode; this.carbonWindow = (CarbonWindowInfo)window; - if (shareContext is AglContext) shareContextRef = ((AglContext)shareContext).contextRef; - CreateContext(mode, carbonWindow, shareContextRef, fullscreen); + CreateContext(mode, carbonWindow, shareContextRef, true); } @@ -98,7 +97,7 @@ namespace OpenTK.Platform.MacOS AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_ALPHA_SIZE, mode.AccumulatorFormat.Alpha); } - //if (fullscreen) + if (fullscreen) { AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_FULLSCREEN); } @@ -127,16 +126,28 @@ namespace OpenTK.Platform.MacOS myAGLPixelFormat = Agl.aglChoosePixelFormat( ref gdevice, 1, aglAttributes.ToArray()); + + Agl.AglError err = Agl.GetError(); + + if (err == Agl.AglError.BadPixelFormat) + { + Debug.Print("Failed to create full screen pixel format."); + Debug.Print("Trying again to create a non-fullscreen pixel format."); + + CreateContext(mode, carbonWindow, shareContextRef, false); + return; + } } else { myAGLPixelFormat = Agl.aglChoosePixelFormat( IntPtr.Zero, 0, aglAttributes.ToArray()); + + MyAGLReportError("aglChoosePixelFormat"); } - MyAGLReportError("aglChoosePixelFormat"); - + // create the context and share it with the share reference. this.contextRef = Agl.aglCreateContext(myAGLPixelFormat, shareContextRef); MyAGLReportError("aglCreateContext"); diff --git a/Source/OpenTK/Platform/MacOS/MacOSFactory.cs b/Source/OpenTK/Platform/MacOS/MacOSFactory.cs index 7dab7c33..39a85c4e 100644 --- a/Source/OpenTK/Platform/MacOS/MacOSFactory.cs +++ b/Source/OpenTK/Platform/MacOS/MacOSFactory.cs @@ -27,7 +27,7 @@ namespace OpenTK.Platform.MacOS public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool DirectRendering) { - return new AglContext(mode, window, shareContext, false); + return new AglContext(mode, window, shareContext); } public IGraphicsMode CreateGraphicsMode()