[Win] Use RelaxGraphicsMode to find optimal mode

This commit is contained in:
thefiddler 2014-01-22 10:49:55 +01:00
parent 615df9201b
commit 6ba475e23f

View file

@ -96,16 +96,23 @@ namespace OpenTK.Platform.Windows
// 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
// ChoosePixelFormatPFD.
GraphicsMode ChoosePixelFormatARB(IntPtr device, GraphicsMode mode)
GraphicsMode ChoosePixelFormatARB(IntPtr device, GraphicsMode desired_mode)
{
GraphicsMode created_mode = null;
GraphicsMode mode = new GraphicsMode(desired_mode);
if (Wgl.SupportsExtension("WGL_ARB_pixel_format") &&
Wgl.SupportsFunction("wglChoosePixelFormatARB"))
{
int[] format = new int[1];
int count;
List<int> attributes = new List<int>();
bool retry = false;
do
{
attributes.Clear();
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);
@ -193,18 +200,20 @@ namespace OpenTK.Platform.Windows
attributes.Add(0);
attributes.Add(0);
int[] format = new int[1];
int count;
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
{
Debug.WriteLine("[WGL] ChoosePixelFormatARB not supported on this context");