/// <summary> /// Creates a new graphics context. /// </summary> private void _createGraphicsContext(DevicePixelFormat pixelFormat) { _graphicsContext = GraphicsManager.CreateGraphicsContext(_getWindowHandle()); #region Set Pixel Format DevicePixelFormatCollection pixelFormats = _graphicsContext.PixelsFormats; System.Collections.Generic.List <DevicePixelFormat> matchingPixelFormats = pixelFormats.Choose(pixelFormat); if ((matchingPixelFormats.Count == 0) && pixelFormat.MultisampleBits > 0) { // Try to select the maximum multisample configuration int multisampleBits = 0; pixelFormats.ForEach(delegate(DevicePixelFormat item) { multisampleBits = Math.Max(multisampleBits, item.MultisampleBits); }); pixelFormat.MultisampleBits = multisampleBits; matchingPixelFormats = pixelFormats.Choose(pixelFormat); } if ((matchingPixelFormats.Count == 0) && pixelFormat.DoubleBuffer) { // Try single buffered pixel formats pixelFormat.DoubleBuffer = false; matchingPixelFormats = pixelFormats.Choose(pixelFormat); if (matchingPixelFormats.Count == 0) { throw new InvalidOperationException(String.Format("unable to find a suitable pixel format: {0}", pixelFormats.GuessChooseError(pixelFormat))); } } else if (matchingPixelFormats.Count == 0) { throw new InvalidOperationException(String.Format("unable to find a suitable pixel format: {0}", pixelFormats.GuessChooseError(pixelFormat))); } _graphicsContext.SetPixelFormat(matchingPixelFormats[0]); #endregion // TODO: Platform specific extension checker if (WGL.IsExtensionSupported(_graphicsContext.DeviceHandle.Handle, WGL.EXT.SwapControl)) { // TODO: Handle tear WGL.SwapIntervalEXT(SwapInterval); } }