mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-23 16:15:34 +00:00
Deduplicate MacOSGraphicsMode and AglContext
The IGraphicsMode interface is gradually being removed and the MacOSFactory will now throw an exception if an instance is requested. AglContext no longer duplicates MacOSGraphicsMode functionality.
This commit is contained in:
parent
f77a6b11c3
commit
6edaf8c3cf
|
@ -47,18 +47,18 @@ namespace OpenTK.Platform.MacOS
|
||||||
// Todo: keep track of which display adapter was specified when the context was created.
|
// Todo: keep track of which display adapter was specified when the context was created.
|
||||||
// IntPtr displayID;
|
// IntPtr displayID;
|
||||||
|
|
||||||
GraphicsMode graphics_mode;
|
|
||||||
CarbonWindowInfo carbonWindow;
|
CarbonWindowInfo carbonWindow;
|
||||||
IntPtr shareContextRef;
|
IntPtr shareContextRef;
|
||||||
DisplayDevice device;
|
DisplayDevice device;
|
||||||
bool mIsFullscreen = false;
|
bool mIsFullscreen = false;
|
||||||
|
|
||||||
|
readonly MacOSGraphicsMode ModeSelector = new MacOSGraphicsMode();
|
||||||
|
|
||||||
public AglContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext)
|
public AglContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext)
|
||||||
{
|
{
|
||||||
Debug.Print("Context Type: {0}", shareContext);
|
Debug.Print("Context Type: {0}", shareContext);
|
||||||
Debug.Print("Window info: {0}", window);
|
Debug.Print("Window info: {0}", window);
|
||||||
|
|
||||||
this.graphics_mode = mode;
|
|
||||||
this.carbonWindow = (CarbonWindowInfo)window;
|
this.carbonWindow = (CarbonWindowInfo)window;
|
||||||
|
|
||||||
if (shareContext is AglContext)
|
if (shareContext is AglContext)
|
||||||
|
@ -105,50 +105,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
}
|
}
|
||||||
void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow, IntPtr shareContextRef, bool fullscreen)
|
void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow, IntPtr shareContextRef, bool fullscreen)
|
||||||
{
|
{
|
||||||
List<int> aglAttributes = new List<int>();
|
|
||||||
|
|
||||||
Debug.Print("AGL pixel format attributes:");
|
Debug.Print("AGL pixel format attributes:");
|
||||||
Debug.Indent();
|
|
||||||
|
|
||||||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_RGBA);
|
|
||||||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_DOUBLEBUFFER);
|
|
||||||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_RED_SIZE, mode.ColorFormat.Red);
|
|
||||||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_GREEN_SIZE, mode.ColorFormat.Green);
|
|
||||||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_BLUE_SIZE, mode.ColorFormat.Blue);
|
|
||||||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ALPHA_SIZE, mode.ColorFormat.Alpha);
|
|
||||||
|
|
||||||
if (mode.Depth > 0)
|
|
||||||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_DEPTH_SIZE, mode.Depth);
|
|
||||||
|
|
||||||
if (mode.Stencil > 0)
|
|
||||||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_STENCIL_SIZE, mode.Stencil);
|
|
||||||
|
|
||||||
if (mode.AccumulatorFormat.BitsPerPixel > 0)
|
|
||||||
{
|
|
||||||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_RED_SIZE, mode.AccumulatorFormat.Red);
|
|
||||||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_GREEN_SIZE, mode.AccumulatorFormat.Green);
|
|
||||||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_BLUE_SIZE, mode.AccumulatorFormat.Blue);
|
|
||||||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_ALPHA_SIZE, mode.AccumulatorFormat.Alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode.Samples > 1)
|
|
||||||
{
|
|
||||||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_SAMPLE_BUFFERS_ARB, 1);
|
|
||||||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_SAMPLES_ARB, mode.Samples);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fullscreen)
|
|
||||||
{
|
|
||||||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_FULLSCREEN);
|
|
||||||
}
|
|
||||||
AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_NONE);
|
|
||||||
|
|
||||||
Debug.Unindent();
|
|
||||||
|
|
||||||
Debug.Write("Attribute array: ");
|
|
||||||
for (int i = 0; i < aglAttributes.Count; i++)
|
|
||||||
Debug.Write(aglAttributes[i].ToString() + " ");
|
|
||||||
Debug.WriteLine("");
|
|
||||||
|
|
||||||
AGLPixelFormat myAGLPixelFormat;
|
AGLPixelFormat myAGLPixelFormat;
|
||||||
|
|
||||||
|
@ -166,11 +123,13 @@ namespace OpenTK.Platform.MacOS
|
||||||
if (status != OSStatus.NoError)
|
if (status != OSStatus.NoError)
|
||||||
throw new MacOSException(status, "DMGetGDeviceByDisplayID failed.");
|
throw new MacOSException(status, "DMGetGDeviceByDisplayID failed.");
|
||||||
|
|
||||||
myAGLPixelFormat = Agl.aglChoosePixelFormat(ref gdevice, 1, aglAttributes.ToArray());
|
myAGLPixelFormat = ModeSelector.SelectPixelFormat(
|
||||||
|
mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples,
|
||||||
|
mode.AccumulatorFormat, mode.Buffers, mode.Stereo,
|
||||||
|
true, gdevice);
|
||||||
|
|
||||||
Agl.AglError err = Agl.GetError();
|
Agl.AglError err = Agl.GetError();
|
||||||
|
if (myAGLPixelFormat == IntPtr.Zero || err == Agl.AglError.BadPixelFormat)
|
||||||
if (err == Agl.AglError.BadPixelFormat)
|
|
||||||
{
|
{
|
||||||
Debug.Print("Failed to create full screen pixel format.");
|
Debug.Print("Failed to create full screen pixel format.");
|
||||||
Debug.Print("Trying again to create a non-fullscreen pixel format.");
|
Debug.Print("Trying again to create a non-fullscreen pixel format.");
|
||||||
|
@ -179,21 +138,23 @@ namespace OpenTK.Platform.MacOS
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
myAGLPixelFormat = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, aglAttributes.ToArray());
|
myAGLPixelFormat = ModeSelector.SelectPixelFormat(
|
||||||
|
mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples,
|
||||||
|
mode.AccumulatorFormat, mode.Buffers, mode.Stereo,
|
||||||
|
false, IntPtr.Zero);
|
||||||
MyAGLReportError("aglChoosePixelFormat");
|
MyAGLReportError("aglChoosePixelFormat");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Debug.Print("Creating AGL context. Sharing with {0}", shareContextRef);
|
Debug.Print("Creating AGL context. Sharing with {0}", shareContextRef);
|
||||||
|
|
||||||
// create the context and share it with the share reference.
|
// create the context and share it with the share reference.
|
||||||
Handle = new ContextHandle(Agl.aglCreateContext(myAGLPixelFormat, shareContextRef));
|
Handle = new ContextHandle(Agl.aglCreateContext(myAGLPixelFormat, shareContextRef));
|
||||||
MyAGLReportError("aglCreateContext");
|
MyAGLReportError("aglCreateContext");
|
||||||
|
|
||||||
|
Mode = ModeSelector.GetGraphicsModeFromPixelFormat(myAGLPixelFormat);
|
||||||
|
|
||||||
// Free the pixel format from memory.
|
// Free the pixel format from memory.
|
||||||
Agl.aglDestroyPixelFormat(myAGLPixelFormat);
|
Agl.aglDestroyPixelFormat(myAGLPixelFormat);
|
||||||
MyAGLReportError("aglDestroyPixelFormat");
|
MyAGLReportError("aglDestroyPixelFormat");
|
||||||
|
@ -205,7 +166,6 @@ namespace OpenTK.Platform.MacOS
|
||||||
Update(carbonWindow);
|
Update(carbonWindow);
|
||||||
|
|
||||||
MakeCurrent(carbonWindow);
|
MakeCurrent(carbonWindow);
|
||||||
|
|
||||||
Debug.Print("context: {0}", Handle.Handle);
|
Debug.Print("context: {0}", Handle.Handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,10 +250,11 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
windowPort = API.GetWindowPort(controlOwner);
|
windowPort = API.GetWindowPort(controlOwner);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
|
{
|
||||||
windowPort = API.GetWindowPort(carbonWindow.Handle);
|
windowPort = API.GetWindowPort(carbonWindow.Handle);
|
||||||
|
}
|
||||||
|
|
||||||
return windowPort;
|
return windowPort;
|
||||||
}
|
}
|
||||||
public override void Update(IWindowInfo window)
|
public override void Update(IWindowInfo window)
|
||||||
|
|
|
@ -76,7 +76,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
public virtual IGraphicsMode CreateGraphicsMode()
|
public virtual IGraphicsMode CreateGraphicsMode()
|
||||||
{
|
{
|
||||||
return new MacOSGraphicsMode();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual OpenTK.Input.IKeyboardDriver2 CreateKeyboardDriver()
|
public virtual OpenTK.Input.IKeyboardDriver2 CreateKeyboardDriver()
|
||||||
|
|
|
@ -42,15 +42,17 @@ namespace OpenTK.Platform.MacOS
|
||||||
public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil,
|
public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil,
|
||||||
int samples, ColorFormat accum, int buffers, bool stereo)
|
int samples, ColorFormat accum, int buffers, bool stereo)
|
||||||
{
|
{
|
||||||
IntPtr pixelformat = SelectPixelFormat(color, depth, stencil, samples, accum, buffers, stereo);
|
IntPtr pixelformat = SelectPixelFormat(
|
||||||
|
color, depth, stencil, samples, accum, buffers, stereo,
|
||||||
|
false, IntPtr.Zero);
|
||||||
return GetGraphicsModeFromPixelFormat(pixelformat);
|
return GetGraphicsModeFromPixelFormat(pixelformat);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Members
|
#region Internal Members
|
||||||
|
|
||||||
GraphicsMode GetGraphicsModeFromPixelFormat(IntPtr pixelformat)
|
internal GraphicsMode GetGraphicsModeFromPixelFormat(IntPtr pixelformat)
|
||||||
{
|
{
|
||||||
int r, g, b, a;
|
int r, g, b, a;
|
||||||
Agl.aglDescribePixelFormat(pixelformat, Agl.PixelFormatAttribute.AGL_RED_SIZE, out r);
|
Agl.aglDescribePixelFormat(pixelformat, Agl.PixelFormatAttribute.AGL_RED_SIZE, out r);
|
||||||
|
@ -73,8 +75,8 @@ namespace OpenTK.Platform.MacOS
|
||||||
depth, stencil, samples, new ColorFormat(ar, ag, ab, aa), buffers + 1, stereo != 0);
|
depth, stencil, samples, new ColorFormat(ar, ag, ab, aa), buffers + 1, stereo != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
IntPtr SelectPixelFormat(ColorFormat color, int depth, int stencil, int samples,
|
internal IntPtr SelectPixelFormat(ColorFormat color, int depth, int stencil, int samples,
|
||||||
ColorFormat accum, int buffers, bool stereo)
|
ColorFormat accum, int buffers, bool stereo, bool fullscreen, IntPtr device)
|
||||||
{
|
{
|
||||||
List<int> attribs = new List<int>();
|
List<int> attribs = new List<int>();
|
||||||
|
|
||||||
|
@ -140,14 +142,22 @@ namespace OpenTK.Platform.MacOS
|
||||||
attribs.Add((int)Agl.PixelFormatAttribute.AGL_STEREO);
|
attribs.Add((int)Agl.PixelFormatAttribute.AGL_STEREO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fullscreen)
|
||||||
|
{
|
||||||
|
attribs.Add((int)Agl.PixelFormatAttribute.AGL_FULLSCREEN);
|
||||||
|
}
|
||||||
|
|
||||||
attribs.Add(0);
|
attribs.Add(0);
|
||||||
attribs.Add(0);
|
attribs.Add(0);
|
||||||
|
|
||||||
IntPtr pixelformat = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, attribs.ToArray());
|
IntPtr pixelformat = IntPtr.Zero;
|
||||||
if (pixelformat == IntPtr.Zero)
|
if (device != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
throw new GraphicsModeException(String.Format(
|
pixelformat = Agl.aglChoosePixelFormat(ref device, 0, attribs.ToArray());
|
||||||
"[Error] Failed to select GraphicsMode, error {0}.", Agl.GetError()));
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pixelformat = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, attribs.ToArray());
|
||||||
}
|
}
|
||||||
return pixelformat;
|
return pixelformat;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue