/// <summary> /// Checks if a Wgl extension is supported by the given context. /// </summary> /// <param name="context">The device context.</param> /// <param name="ext">The extension to check.</param> /// <returns>True if the extension is supported by the given context, false otherwise</returns> public static bool SupportsExtension(WinGLContext context, string ext) { // We cache this locally, as another thread might create a context which doesn't support this method. // The design is far from ideal, but there's no good solution to this issue as long as we are using // static WGL/GL classes. Fortunately, this issue is extremely unlikely to arise in practice, as you'd // have to create one accelerated and one non-accelerated context in the same application, with the // non-accelerated context coming second. Wgl.Delegates.GetExtensionsStringARB get = Wgl.Delegates.wglGetExtensionsStringARB; if (get != null) { string[] extensions = null; unsafe { extensions = new string((sbyte *)get(context.DeviceContext)) .Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); } if (extensions == null || extensions.Length == 0) { return(false); } foreach (string s in extensions) { if (s == ext) { return(true); } } } return(false); }
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"); } }
/// <summary> /// Checks if a Wgl extension is supported by the given context. /// </summary> /// <param name="context">The device context.</param> /// <param name="ext">The extension to check.</param> /// <returns>True if the extension is supported by the given context, false otherwise</returns> public static bool SupportsExtension(WinGLContext context, string ext) { if (Wgl.Delegates.wglGetExtensionsStringARB != null) { if (rebuildExtensionList) { rebuildExtensionList = false; extensions = Wgl.Arb.GetExtensionsString(context.DeviceContext).Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (extensions == null || extensions.Length == 0) { return(false); } Array.Sort(extensions); } return(Array.BinarySearch(extensions, ext) != -1); } return(false); }
/// <summary> /// Checks if a Wgl extension is supported by the given context. /// </summary> /// <param name="context">The device context.</param> /// <param name="ext">The extension to check.</param> /// <returns>True if the extension is supported by the given context, false otherwise</returns> public static bool SupportsExtension(WinGLContext context, string ext) { // We cache this locally, as another thread might create a context which doesn't support this method. // The design is far from ideal, but there's no good solution to this issue as long as we are using // static WGL/GL classes. Fortunately, this issue is extremely unlikely to arise in practice, as you'd // have to create one accelerated and one non-accelerated context in the same application, with the // non-accelerated context coming second. Wgl.Delegates.GetExtensionsStringARB get = Wgl.Delegates.wglGetExtensionsStringARB; if (get != null) { string[] extensions = null; unsafe { extensions = new string((sbyte*)get(context.DeviceContext)) .Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); } if (extensions == null || extensions.Length == 0) return false; foreach (string s in extensions) if (s == ext) return true; } return false; }
public void CreateWindow(DisplayMode windowMode, out IGLContext context) { Debug.Print("Creating native window with mode: {0}", windowMode.ToString()); Debug.Indent(); CreateParams cp = new CreateParams(); cp.ClassStyle = (int)WindowClassStyle.OwnDC | (int)WindowClassStyle.VRedraw | (int)WindowClassStyle.HRedraw | (int)WindowClassStyle.Ime; cp.Style = (int)WindowStyle.Visible | (int)WindowStyle.ClipChildren | (int)WindowStyle.ClipSiblings | (int)WindowStyle.OverlappedWindow; Rectangle rect = new Rectangle(); rect.top = rect.left = 0; rect.bottom = windowMode.Height; rect.right = windowMode.Width; Functions.AdjustWindowRect(ref rect, WindowStyle.OverlappedWindow, false); // Not used Top = 0; Left = 0; Right = windowMode.Width; Bottom = windowMode.Height; // -------- top_border = -rect.top; left_border = -rect.left; bottom_border = rect.bottom - windowMode.Height; right_border = rect.right - windowMode.Width; cp.Width = rect.right - rect.left; cp.Height = rect.bottom - rect.top; cp.Caption = "OpenTK Game Window"; // Keep in mind that some construction code runs in WM_CREATE, // which is raised CreateHandle() CreateHandle(cp); if (this.Handle != IntPtr.Zero) { Debug.WriteLine("Window creation succesful."); //context.Info = new OpenTK.Platform.WindowInfo(this); //context.CreateContext(); //Debug.WriteLine("Context creation successful."); exists = true; } else throw new ApplicationException(String.Format( "Could not create native window and/or context. Handle: {0}", this.Handle)); Functions.SetWindowPos(this.Handle, WindowPlacementOptions.TOP, Left, Top, cp.Width, cp.Height, SetWindowPosFlags.SHOWWINDOW); //context = new GLContext(mode, window); //context.CreateContext(); context = new WinGLContext(); (context as IGLContextCreationHack).SetWindowHandle(window.Handle); (context as IGLContextCreationHack).SelectDisplayMode(mode, window); context.CreateContext(true, null); Debug.Unindent(); }
/// <summary> /// Checks if a Wgl extension is supported by the given context. /// </summary> /// <param name="context">The device context.</param> /// <param name="ext">The extension to check.</param> /// <returns>True if the extension is supported by the given context, false otherwise</returns> public static bool SupportsExtension(WinGLContext context, string ext) { if (Wgl.Delegates.wglGetExtensionsStringARB != null) { if (rebuildExtensionList) { rebuildExtensionList = false; extensions = Wgl.Arb.GetExtensionsString(context.DeviceContext).Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (extensions == null || extensions.Length == 0) return false; Array.Sort(extensions); } return Array.BinarySearch(extensions, ext) != -1; } return false; }
public static unsafe bool SupportsExtension(WinGLContext context, string ext) { Wgl.Delegates.GetExtensionsStringARB extensionsStringArb = Wgl.Delegates.wglGetExtensionsStringARB; if (extensionsStringArb != null) { string[] strArray = new string((sbyte*) (void*) extensionsStringArb(context.DeviceContext)).Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (strArray == null || strArray.Length == 0) return false; foreach (string str in strArray) { if (str == ext) return true; } } return false; }
static WinGLContext() { WinGLContext.Init(); }