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, SWAP_LAYER_BUFFERS = 0x800,
GENERIC_ACCELERATED = 0x1000, GENERIC_ACCELERATED = 0x1000,
SUPPORT_DIRECTDRAW = 0x2000, SUPPORT_DIRECTDRAW = 0x2000,
SUPPORT_COMPOSITION = 0x8000,
// PixelFormatDescriptor flags for use in ChoosePixelFormat only // PixelFormatDescriptor flags for use in ChoosePixelFormat only
DEPTH_DONTCARE = unchecked((int)0x20000000), DEPTH_DONTCARE = unchecked((int)0x20000000),

View file

@ -141,23 +141,34 @@ namespace OpenTK.Platform.Windows
PixelFormatDescriptorFlags.SUPPORT_OPENGL | PixelFormatDescriptorFlags.SUPPORT_OPENGL |
PixelFormatDescriptorFlags.DRAW_TO_WINDOW; PixelFormatDescriptorFlags.DRAW_TO_WINDOW;
int pixel = 0; // Make sure we don't turn off Aero on Vista and newer.
while (DescribePixelFormat(deviceContext, ++pixel, API.PixelFormatDescriptorSize, ref pfd) != 0) if (Environment.OSVersion.Version.Major >= 6)
{ {
// Ignore non-accelerated formats. pfd.Flags |= PixelFormatDescriptorFlags.SUPPORT_COMPOSITION;
if ((pfd.Flags & PixelFormatDescriptorFlags.GENERIC_FORMAT) != 0) }
continue;
GraphicsMode fmt = new GraphicsMode((IntPtr)pixel, foreach (bool generic_allowed in new bool[] { false, true })
new ColorFormat(pfd.RedBits, pfd.GreenBits, pfd.BlueBits, pfd.AlphaBits), {
pfd.DepthBits, // Iterate through all accelerated formats first. Afterwards, iterate through non-accelerated formats.
pfd.StencilBits, // This should fix issue #2224, which causes OpenTK to fail on VMs without hardware acceleration.
0, int pixel = 0;
new ColorFormat(pfd.AccumBits), while (DescribePixelFormat(deviceContext, ++pixel, API.PixelFormatDescriptorSize, ref pfd) != 0)
(pfd.Flags & PixelFormatDescriptorFlags.DOUBLEBUFFER) != 0 ? 2 : 1, {
(pfd.Flags & PixelFormatDescriptorFlags.STEREO) != 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;
}
} }
} }