static private SetGraphicsModePFD ( OpenTK.Graphics.GraphicsMode mode, |
||
mode | OpenTK.Graphics.GraphicsMode | |
window | ||
Résultat | void |
internal static void SetGraphicsModePFD(GraphicsMode mode, WinWindowInfo window)
{
Debug.Write("Setting pixel format... ");
if (!mode.Index.HasValue)
throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");
if (window == null) throw new ArgumentNullException("window", "Must point to a valid window.");
PixelFormatDescriptor pfd = new PixelFormatDescriptor();
Functions.DescribePixelFormat(window.DeviceContext, (int)mode.Index.Value,
API.PixelFormatDescriptorSize, ref pfd);
Debug.WriteLine(mode.Index.ToString());
if (!Functions.SetPixelFormat(window.DeviceContext, (int)mode.Index.Value, ref pfd))
throw new GraphicsContextException(String.Format(
"Requested GraphicsMode not available. SetPixelFormat error: {0}", Marshal.GetLastWin32Error()));
}
public TemporaryContext(IntPtr native) { Debug.WriteLine("[WGL] Creating temporary context to load extensions"); if (native == null) { throw new ArgumentNullException(); } // Create temporary context and load WGL entry points // First, set a compatible pixel format to the device context // of the temp window WinWindowInfo window = new WinWindowInfo { Handle = native }; WinGraphicsMode selector = new WinGraphicsMode(window.DeviceContext); WinGLContext.SetGraphicsModePFD(selector, GraphicsMode.Default, window); bool success = false; // Then, construct a temporary context and load all wgl extensions Context = new ContextHandle(Wgl.CreateContext(window.DeviceContext)); if (Context != ContextHandle.Zero) { // Make the context current. // Note: on some video cards and on some virtual machines, wglMakeCurrent // may fail with an errorcode of 6 (INVALID_HANDLE). The suggested workaround // is to call wglMakeCurrent in a loop until it succeeds. // See https://www.opengl.org/discussion_boards/showthread.php/171058-nVidia-wglMakeCurrent()-multiple-threads // Sigh... for (int retry = 0; retry < 5 && !success; retry++) { success = Wgl.MakeCurrent(window.DeviceContext, Context.Handle); if (!success) { Debug.Print("wglMakeCurrent failed with error: {0}. Retrying", Marshal.GetLastWin32Error()); System.Threading.Thread.Sleep(10); } } } else { Debug.Print("[WGL] CreateContext failed with error: {0}", Marshal.GetLastWin32Error()); } if (!success) { Debug.WriteLine("[WGL] Failed to create temporary context"); } }