Added PFD_SUPPORT_COMPOSITION on Vista and higher, to avoid inadvertently disabling Aero.

Allow non-accelerated formats when all accelerated ones fail. Fixes issue [#2224]: "Getting GraphicsModeException from WinGraphicsMode constructor".
This commit is contained in:
the_fiddler 2011-02-09 00:23:43 +00:00
parent c4475ec05b
commit da5371e92b
2 changed files with 26 additions and 14 deletions

View file

@ -3055,6 +3055,7 @@ namespace OpenTK.Platform.Windows
SWAP_LAYER_BUFFERS = 0x800,
GENERIC_ACCELERATED = 0x1000,
SUPPORT_DIRECTDRAW = 0x2000,
SUPPORT_COMPOSITION = 0x8000,
// PixelFormatDescriptor flags for use in ChoosePixelFormat only
DEPTH_DONTCARE = unchecked((int)0x20000000),

View file

@ -141,11 +141,21 @@ namespace OpenTK.Platform.Windows
PixelFormatDescriptorFlags.SUPPORT_OPENGL |
PixelFormatDescriptorFlags.DRAW_TO_WINDOW;
// Make sure we don't turn off Aero on Vista and newer.
if (Environment.OSVersion.Version.Major >= 6)
{
pfd.Flags |= PixelFormatDescriptorFlags.SUPPORT_COMPOSITION;
}
foreach (bool generic_allowed in new bool[] { false, true })
{
// Iterate through all accelerated formats first. Afterwards, iterate through non-accelerated formats.
// This should fix issue #2224, which causes OpenTK to fail on VMs without hardware acceleration.
int pixel = 0;
while (DescribePixelFormat(deviceContext, ++pixel, API.PixelFormatDescriptorSize, ref pfd) != 0)
{
// Ignore non-accelerated formats.
if ((pfd.Flags & PixelFormatDescriptorFlags.GENERIC_FORMAT) != 0)
if (!generic_allowed && (pfd.Flags & PixelFormatDescriptorFlags.GENERIC_FORMAT) != 0)
continue;
GraphicsMode fmt = new GraphicsMode((IntPtr)pixel,
@ -160,6 +170,7 @@ namespace OpenTK.Platform.Windows
yield return fmt;
}
}
}
#endregion