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 4595d424f0
commit cf4619fe6d
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,23 +141,34 @@ namespace OpenTK.Platform.Windows
PixelFormatDescriptorFlags.SUPPORT_OPENGL |
PixelFormatDescriptorFlags.DRAW_TO_WINDOW;
int pixel = 0;
while (DescribePixelFormat(deviceContext, ++pixel, API.PixelFormatDescriptorSize, ref pfd) != 0)
// Make sure we don't turn off Aero on Vista and newer.
if (Environment.OSVersion.Version.Major >= 6)
{
// Ignore non-accelerated formats.
if ((pfd.Flags & PixelFormatDescriptorFlags.GENERIC_FORMAT) != 0)
continue;
pfd.Flags |= PixelFormatDescriptorFlags.SUPPORT_COMPOSITION;
}
GraphicsMode fmt = new GraphicsMode((IntPtr)pixel,
new ColorFormat(pfd.RedBits, pfd.GreenBits, pfd.BlueBits, pfd.AlphaBits),
pfd.DepthBits,
pfd.StencilBits,
0,
new ColorFormat(pfd.AccumBits),
(pfd.Flags & PixelFormatDescriptorFlags.DOUBLEBUFFER) != 0 ? 2 : 1,
(pfd.Flags & PixelFormatDescriptorFlags.STEREO) != 0);
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 (!generic_allowed && (pfd.Flags & PixelFormatDescriptorFlags.GENERIC_FORMAT) != 0)
continue;
yield return fmt;
GraphicsMode fmt = new GraphicsMode((IntPtr)pixel,
new ColorFormat(pfd.RedBits, pfd.GreenBits, pfd.BlueBits, pfd.AlphaBits),
pfd.DepthBits,
pfd.StencilBits,
0,
new ColorFormat(pfd.AccumBits),
(pfd.Flags & PixelFormatDescriptorFlags.DOUBLEBUFFER) != 0 ? 2 : 1,
(pfd.Flags & PixelFormatDescriptorFlags.STEREO) != 0);
yield return fmt;
}
}
}