mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-23 17:20:57 +00:00
Updates to macos fullscreen.
Resolution switching is now accompanied by a call to CGDisplayCapture. A secondary fullscreen context is created for going full screen.
This commit is contained in:
parent
34e283367d
commit
74707ccdfd
|
@ -26,26 +26,34 @@ namespace OpenTK.Platform.MacOS
|
|||
|
||||
class AglContext : IGraphicsContext, IGraphicsContextInternal
|
||||
{
|
||||
IntPtr storedContextRef;
|
||||
IntPtr contextRef;
|
||||
|
||||
bool mVSync = false;
|
||||
IntPtr displayID;
|
||||
|
||||
GraphicsMode mode;
|
||||
CarbonWindowInfo carbonWindow;
|
||||
IGraphicsContext shareContext;
|
||||
IntPtr shareContextRef;
|
||||
|
||||
static AglContext()
|
||||
{
|
||||
if (GraphicsContext.GetCurrentContext == null)
|
||||
GraphicsContext.GetCurrentContext = AglContext.GetCurrentContext;
|
||||
}
|
||||
public AglContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext)
|
||||
public AglContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool fullscreen)
|
||||
{
|
||||
Debug.Print("Context Type: {0}", shareContext);
|
||||
Debug.Print("Window info: {0}", window);
|
||||
|
||||
this.mode = mode;
|
||||
this.carbonWindow = (CarbonWindowInfo)window;
|
||||
this.shareContext = shareContext;
|
||||
|
||||
CreateContext(mode, carbonWindow, shareContext);
|
||||
|
||||
if (shareContext is AglContext)
|
||||
shareContextRef = ((AglContext)shareContext).contextRef;
|
||||
|
||||
CreateContext(mode, carbonWindow, shareContextRef, fullscreen);
|
||||
}
|
||||
|
||||
|
||||
|
@ -62,11 +70,12 @@ namespace OpenTK.Platform.MacOS
|
|||
aglAttributes.Add((int)pixelFormatAttribute);
|
||||
aglAttributes.Add(value);
|
||||
}
|
||||
void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow, IGraphicsContext shareContext)
|
||||
void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow,
|
||||
IntPtr shareContextRef, bool fullscreen)
|
||||
{
|
||||
List<int> aglAttributes = new List<int>();
|
||||
|
||||
Debug.Print("AGL attributes:");
|
||||
Debug.Print("AGL pixel format attributes:");
|
||||
Debug.Indent();
|
||||
|
||||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_RGBA);
|
||||
|
@ -89,7 +98,11 @@ 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);
|
||||
}
|
||||
|
||||
if (fullscreen)
|
||||
{
|
||||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_FULLSCREEN);
|
||||
}
|
||||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_NONE);
|
||||
|
||||
Debug.Unindent();
|
||||
|
@ -100,30 +113,30 @@ namespace OpenTK.Platform.MacOS
|
|||
Debug.WriteLine("");
|
||||
|
||||
AGLPixelFormat myAGLPixelFormat;
|
||||
|
||||
// Choose a pixel format with the attributes we specified.
|
||||
if (fullscreen)
|
||||
{
|
||||
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(
|
||||
ref gdevice, 1,
|
||||
//IntPtr.Zero, 0,
|
||||
aglAttributes.ToArray());
|
||||
|
||||
MyAGLReportError("aglChoosePixelFormat");
|
||||
|
||||
|
||||
IntPtr shareContextRef = IntPtr.Zero;
|
||||
if (shareContext != null)
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Print("shareContext type is {0}", shareContext.GetType());
|
||||
myAGLPixelFormat = Agl.aglChoosePixelFormat(
|
||||
IntPtr.Zero, 0,
|
||||
aglAttributes.ToArray());
|
||||
}
|
||||
|
||||
if (shareContext != null && shareContext is AglContext)
|
||||
shareContextRef = ((AglContext)shareContext).contextRef;
|
||||
MyAGLReportError("aglChoosePixelFormat");
|
||||
|
||||
// create the context and share it with the share reference.
|
||||
this.contextRef = Agl.aglCreateContext(myAGLPixelFormat, shareContextRef);
|
||||
|
@ -205,7 +218,6 @@ namespace OpenTK.Platform.MacOS
|
|||
|
||||
SetBufferRect(carbonWindow);
|
||||
|
||||
//Agl.aglSetCurrentContext(contextRef);
|
||||
Agl.aglUpdateContext(contextRef);
|
||||
|
||||
}
|
||||
|
@ -215,7 +227,8 @@ namespace OpenTK.Platform.MacOS
|
|||
|
||||
if (err != Agl.AglError.NoError)
|
||||
throw new MacOSException((OSStatus)err, string.Format(
|
||||
"AGL Error from function {0}: {1} {2}", err, Agl.ErrorString(err)));
|
||||
"AGL Error from function {0}: {1} {2}",
|
||||
function, err, Agl.ErrorString(err)));
|
||||
}
|
||||
|
||||
static ContextHandle GetCurrentContext()
|
||||
|
@ -225,11 +238,37 @@ namespace OpenTK.Platform.MacOS
|
|||
|
||||
internal void SetFullScreen()
|
||||
{
|
||||
Agl.aglSetFullScreen(contextRef, 640, 480, 60, 0);
|
||||
if (storedContextRef == IntPtr.Zero)
|
||||
{
|
||||
storedContextRef = contextRef;
|
||||
}
|
||||
else
|
||||
{
|
||||
Agl.aglDestroyContext(contextRef);
|
||||
}
|
||||
|
||||
// TODO: this may be a problem if we are switching from one
|
||||
// full screen mode to another.
|
||||
try
|
||||
{
|
||||
CreateContext(mode, carbonWindow, storedContextRef, true);
|
||||
Agl.aglSetFullScreen(contextRef, 0, 0, 0, 0);
|
||||
}
|
||||
catch (MacOSException e)
|
||||
{
|
||||
contextRef = storedContextRef;
|
||||
storedContextRef = IntPtr.Zero;
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
internal void UnsetFullScreen()
|
||||
{
|
||||
SetDrawable(carbonWindow);
|
||||
if (storedContextRef == IntPtr.Zero)
|
||||
return;
|
||||
|
||||
Agl.aglDestroyContext(contextRef);
|
||||
contextRef = storedContextRef;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -281,6 +281,18 @@ namespace OpenTK.Platform.MacOS
|
|||
** Pixel format functions
|
||||
*/
|
||||
[DllImport(agl)] internal static extern AGLPixelFormat aglChoosePixelFormat(ref AGLDevice gdevs, int ndev, int []attribs);
|
||||
/// <summary>
|
||||
/// Use this overload only with IntPtr.Zero for the first argument.
|
||||
/// </summary>
|
||||
/// <param name="gdevs">
|
||||
/// </param>
|
||||
/// <param name="ndev">
|
||||
/// </param>
|
||||
/// <param name="attribs">
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// </returns>
|
||||
[DllImport(agl)] internal static extern AGLPixelFormat aglChoosePixelFormat(IntPtr 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);
|
||||
|
|
|
@ -632,9 +632,13 @@ namespace OpenTK.Platform.MacOS
|
|||
case WindowState.Fullscreen:
|
||||
((AglContext)context.Implementation).SetFullScreen();
|
||||
context.Update(WindowInfo);
|
||||
|
||||
break;
|
||||
|
||||
case WindowState.Maximized:
|
||||
// hack because mac os has no concept of maximized. Instead windows are "zoomed"
|
||||
// meaning they are maximized up to their reported ideal size. So we report a
|
||||
// large ideal size.
|
||||
idealSize = new Point(9000, 9000);
|
||||
API.ZoomWindowIdeal(window.WindowRef, WindowPartCode.inZoomOut, ref idealSize);
|
||||
break;
|
||||
|
|
|
@ -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);
|
||||
return new AglContext(mode, window, shareContext, false);
|
||||
}
|
||||
|
||||
public IGraphicsMode CreateGraphicsMode()
|
||||
|
|
|
@ -20,16 +20,6 @@ namespace OpenTK.Platform.MacOS
|
|||
|
||||
static QuartzDisplayDeviceDriver()
|
||||
{
|
||||
//lock (display_lock)
|
||||
//{
|
||||
// List<DisplayResolution> resolutions = new List<DisplayResolution>();
|
||||
|
||||
// DisplayResolution primaryRes = new DisplayResolution(1024, 768, 32, 60);
|
||||
// resolutions.Add(primaryRes);
|
||||
|
||||
// object o = new Graphics.DisplayDevice(primaryRes, true, resolutions);
|
||||
//}
|
||||
|
||||
lock (display_lock)
|
||||
{
|
||||
// To minimize the need to add static methods to OpenTK.Graphics.DisplayDevice
|
||||
|
@ -143,6 +133,8 @@ namespace OpenTK.Platform.MacOS
|
|||
bpp == resolution.BitsPerPixel &&
|
||||
freq == resolution.RefreshRate)
|
||||
{
|
||||
CG.DisplayCapture(display);
|
||||
|
||||
CG.DisplaySwitchToMode(display, displayModes[j]);
|
||||
|
||||
return true;
|
||||
|
@ -158,7 +150,8 @@ namespace OpenTK.Platform.MacOS
|
|||
|
||||
if (storedModes.ContainsKey(display))
|
||||
{
|
||||
CG.DisplaySwitchToMode(display, storedModes[display]);
|
||||
//CG.DisplaySwitchToMode(display, storedModes[display]);
|
||||
CG.DisplayRelease(display);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue