mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-06-02 07:10:25 +00:00
[Win] Use RelaxGraphicsMode to find optimal mode
This commit is contained in:
parent
615df9201b
commit
6ba475e23f
|
@ -96,114 +96,123 @@ namespace OpenTK.Platform.Windows
|
||||||
// hardware acceleration (e.g. we are running in a VM or in a remote desktop
|
// hardware acceleration (e.g. we are running in a VM or in a remote desktop
|
||||||
// connection), this method will return 0 formats and we will fall back to
|
// connection), this method will return 0 formats and we will fall back to
|
||||||
// ChoosePixelFormatPFD.
|
// ChoosePixelFormatPFD.
|
||||||
GraphicsMode ChoosePixelFormatARB(IntPtr device, GraphicsMode mode)
|
GraphicsMode ChoosePixelFormatARB(IntPtr device, GraphicsMode desired_mode)
|
||||||
{
|
{
|
||||||
GraphicsMode created_mode = null;
|
GraphicsMode created_mode = null;
|
||||||
|
GraphicsMode mode = new GraphicsMode(desired_mode);
|
||||||
if (Wgl.SupportsExtension("WGL_ARB_pixel_format") &&
|
if (Wgl.SupportsExtension("WGL_ARB_pixel_format") &&
|
||||||
Wgl.SupportsFunction("wglChoosePixelFormatARB"))
|
Wgl.SupportsFunction("wglChoosePixelFormatARB"))
|
||||||
{
|
{
|
||||||
List<int> attributes = new List<int>();
|
|
||||||
attributes.Add((int)WGL_ARB_pixel_format.AccelerationArb);
|
|
||||||
attributes.Add((int)WGL_ARB_pixel_format.FullAccelerationArb);
|
|
||||||
|
|
||||||
attributes.Add((int)WGL_ARB_pixel_format.DrawToWindowArb);
|
|
||||||
attributes.Add(1);
|
|
||||||
|
|
||||||
if (mode.ColorFormat.Red > 0)
|
|
||||||
{
|
|
||||||
attributes.Add((int)WGL_ARB_pixel_format.RedBitsArb);
|
|
||||||
attributes.Add(mode.ColorFormat.Red);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode.ColorFormat.Green > 0)
|
|
||||||
{
|
|
||||||
attributes.Add((int)WGL_ARB_pixel_format.GreenBitsArb);
|
|
||||||
attributes.Add(mode.ColorFormat.Green);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode.ColorFormat.Blue > 0)
|
|
||||||
{
|
|
||||||
attributes.Add((int)WGL_ARB_pixel_format.BlueBitsArb);
|
|
||||||
attributes.Add(mode.ColorFormat.Blue);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode.ColorFormat.Alpha > 0)
|
|
||||||
{
|
|
||||||
attributes.Add((int)WGL_ARB_pixel_format.AlphaBitsArb);
|
|
||||||
attributes.Add(mode.ColorFormat.Alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode.Depth > 0)
|
|
||||||
{
|
|
||||||
attributes.Add((int)WGL_ARB_pixel_format.DepthBitsArb);
|
|
||||||
attributes.Add(mode.Depth);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode.Stencil > 0)
|
|
||||||
{
|
|
||||||
attributes.Add((int)WGL_ARB_pixel_format.StencilBitsArb);
|
|
||||||
attributes.Add(mode.Stencil);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode.AccumulatorFormat.Red > 0)
|
|
||||||
{
|
|
||||||
attributes.Add((int)WGL_ARB_pixel_format.AccumRedBitsArb);
|
|
||||||
attributes.Add(mode.AccumulatorFormat.Red);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode.AccumulatorFormat.Green > 0)
|
|
||||||
{
|
|
||||||
attributes.Add((int)WGL_ARB_pixel_format.AccumGreenBitsArb);
|
|
||||||
attributes.Add(mode.AccumulatorFormat.Green);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode.AccumulatorFormat.Blue > 0)
|
|
||||||
{
|
|
||||||
attributes.Add((int)WGL_ARB_pixel_format.AccumBlueBitsArb);
|
|
||||||
attributes.Add(mode.AccumulatorFormat.Blue);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode.AccumulatorFormat.Alpha > 0)
|
|
||||||
{
|
|
||||||
attributes.Add((int)WGL_ARB_pixel_format.AccumAlphaBitsArb);
|
|
||||||
attributes.Add(mode.AccumulatorFormat.Alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode.Samples > 0 &&
|
|
||||||
Wgl.SupportsExtension("WGL_ARB_multisample"))
|
|
||||||
{
|
|
||||||
attributes.Add((int)WGL_ARB_multisample.SampleBuffersArb);
|
|
||||||
attributes.Add(1);
|
|
||||||
attributes.Add((int)WGL_ARB_multisample.SamplesArb);
|
|
||||||
attributes.Add(mode.Samples);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode.Buffers > 0)
|
|
||||||
{
|
|
||||||
attributes.Add((int)WGL_ARB_pixel_format.DoubleBufferArb);
|
|
||||||
attributes.Add(mode.Buffers > 1 ? 1 : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode.Stereo)
|
|
||||||
{
|
|
||||||
attributes.Add((int)WGL_ARB_pixel_format.StereoArb);
|
|
||||||
attributes.Add(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
attributes.Add(0);
|
|
||||||
attributes.Add(0);
|
|
||||||
|
|
||||||
int[] format = new int[1];
|
int[] format = new int[1];
|
||||||
int count;
|
int count;
|
||||||
if (Wgl.Arb.ChoosePixelFormat(device, attributes.ToArray(), null, format.Length, format, out count)
|
List<int> attributes = new List<int>();
|
||||||
&& count > 0)
|
bool retry = false;
|
||||||
|
|
||||||
|
do
|
||||||
{
|
{
|
||||||
created_mode = DescribePixelFormatARB(device, format[0]);
|
attributes.Clear();
|
||||||
}
|
attributes.Add((int)WGL_ARB_pixel_format.AccelerationArb);
|
||||||
else
|
attributes.Add((int)WGL_ARB_pixel_format.FullAccelerationArb);
|
||||||
{
|
attributes.Add((int)WGL_ARB_pixel_format.DrawToWindowArb);
|
||||||
Debug.Print("[WGL] ChoosePixelFormatARB failed with {0}", Marshal.GetLastWin32Error());
|
attributes.Add(1);
|
||||||
|
|
||||||
|
if (mode.ColorFormat.Red > 0)
|
||||||
|
{
|
||||||
|
attributes.Add((int)WGL_ARB_pixel_format.RedBitsArb);
|
||||||
|
attributes.Add(mode.ColorFormat.Red);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode.ColorFormat.Green > 0)
|
||||||
|
{
|
||||||
|
attributes.Add((int)WGL_ARB_pixel_format.GreenBitsArb);
|
||||||
|
attributes.Add(mode.ColorFormat.Green);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode.ColorFormat.Blue > 0)
|
||||||
|
{
|
||||||
|
attributes.Add((int)WGL_ARB_pixel_format.BlueBitsArb);
|
||||||
|
attributes.Add(mode.ColorFormat.Blue);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode.ColorFormat.Alpha > 0)
|
||||||
|
{
|
||||||
|
attributes.Add((int)WGL_ARB_pixel_format.AlphaBitsArb);
|
||||||
|
attributes.Add(mode.ColorFormat.Alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode.Depth > 0)
|
||||||
|
{
|
||||||
|
attributes.Add((int)WGL_ARB_pixel_format.DepthBitsArb);
|
||||||
|
attributes.Add(mode.Depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode.Stencil > 0)
|
||||||
|
{
|
||||||
|
attributes.Add((int)WGL_ARB_pixel_format.StencilBitsArb);
|
||||||
|
attributes.Add(mode.Stencil);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode.AccumulatorFormat.Red > 0)
|
||||||
|
{
|
||||||
|
attributes.Add((int)WGL_ARB_pixel_format.AccumRedBitsArb);
|
||||||
|
attributes.Add(mode.AccumulatorFormat.Red);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode.AccumulatorFormat.Green > 0)
|
||||||
|
{
|
||||||
|
attributes.Add((int)WGL_ARB_pixel_format.AccumGreenBitsArb);
|
||||||
|
attributes.Add(mode.AccumulatorFormat.Green);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode.AccumulatorFormat.Blue > 0)
|
||||||
|
{
|
||||||
|
attributes.Add((int)WGL_ARB_pixel_format.AccumBlueBitsArb);
|
||||||
|
attributes.Add(mode.AccumulatorFormat.Blue);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode.AccumulatorFormat.Alpha > 0)
|
||||||
|
{
|
||||||
|
attributes.Add((int)WGL_ARB_pixel_format.AccumAlphaBitsArb);
|
||||||
|
attributes.Add(mode.AccumulatorFormat.Alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode.Samples > 0 &&
|
||||||
|
Wgl.SupportsExtension("WGL_ARB_multisample"))
|
||||||
|
{
|
||||||
|
attributes.Add((int)WGL_ARB_multisample.SampleBuffersArb);
|
||||||
|
attributes.Add(1);
|
||||||
|
attributes.Add((int)WGL_ARB_multisample.SamplesArb);
|
||||||
|
attributes.Add(mode.Samples);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode.Buffers > 0)
|
||||||
|
{
|
||||||
|
attributes.Add((int)WGL_ARB_pixel_format.DoubleBufferArb);
|
||||||
|
attributes.Add(mode.Buffers > 1 ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode.Stereo)
|
||||||
|
{
|
||||||
|
attributes.Add((int)WGL_ARB_pixel_format.StereoArb);
|
||||||
|
attributes.Add(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
attributes.Add(0);
|
||||||
|
attributes.Add(0);
|
||||||
|
|
||||||
|
if (Wgl.Arb.ChoosePixelFormat(device, attributes.ToArray(), null, format.Length, format, out count)
|
||||||
|
&& count > 0)
|
||||||
|
{
|
||||||
|
created_mode = DescribePixelFormatARB(device, format[0]);
|
||||||
|
retry = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Print("[WGL] ChoosePixelFormatARB failed with {0}", Marshal.GetLastWin32Error());
|
||||||
|
retry = Utilities.RelaxGraphicsMode(ref mode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
while (retry);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue