/// <summary> /// Only valid to be called after the render context is created, this function attempts to /// move the render context to the OpenGL version originally requested. If this is > 2.1, this /// means building a new context. If this fails, we'll have to make do with 2.1. /// </summary> /// <param name="gl">The OpenGL instance.</param> protected void UpdateContextVersion(OpenGL gl) { // If the request version number is anything up to and including 2.1, standard render contexts // will provide what we need (as long as the graphics card drivers are up to date). var requestedVersionNumber = VersionAttribute.GetVersionAttribute(requestedOpenGLVersion); if (requestedVersionNumber.IsAtLeastVersion(3, 0) == false) { createdOpenGLVersion = requestedOpenGLVersion; return; } // Now the none-trivial case. We must use the WGL_ARB_create_context extension to // attempt to create a 3.0+ context. try { int[] attributes = { OpenGL.WGL_CONTEXT_MAJOR_VERSION_ARB, requestedVersionNumber.Major, OpenGL.WGL_CONTEXT_MINOR_VERSION_ARB, requestedVersionNumber.Minor, OpenGL.WGL_CONTEXT_FLAGS_ARB, OpenGL.WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, 0 }; var hrc = gl.CreateContextAttribsARB(IntPtr.Zero, attributes); Win32.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero); Win32.wglDeleteContext(renderContextHandle); Win32.wglMakeCurrent(deviceContextHandle, hrc); renderContextHandle = hrc; } catch (Exception) { // TODO: can we actually get the real version? createdOpenGLVersion = OpenGLVersion.OpenGL2_1; } }
/// <summary> /// Only valid to be called after the render context is created, this function attempts to /// move the render context to the OpenGL version originally requested. If this is > 2.1, this /// means building a new context. If this fails, we'll have to make do with 2.1. /// </summary> /// <param name="gl">The OpenGL instance.</param> protected void UpdateContextVersion() { // If the request version number is anything up to and including 2.1, standard render contexts // will provide what we need (as long as the graphics card drivers are up to date). var requestedVersionNumber = VersionAttribute.GetVersionAttribute(requestedOpenGLVersion); if (requestedVersionNumber.IsAtLeastVersion(3, 0) == false) { createdOpenGLVersion = requestedOpenGLVersion; return; } // Now the none-trivial case. We must use the WGL_ARB_create_context extension to // attempt to create a 3.0+ context. try { int[] attributes = { WGL_CONTEXT_MAJOR_VERSION_ARB, requestedVersionNumber.Major, WGL_CONTEXT_MINOR_VERSION_ARB, requestedVersionNumber.Minor, WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, 0 }; //// var hrc = gl.CreateContextAttribsARB(IntPtr.Zero, attributes); IWindowInfo window_info = Utilities.CreateWindowsWindowInfo(IntPtr.Zero); GraphicsMode mode = new GraphicsMode(DisplayDevice.Default.BitsPerPixel, 24, 0, 4, 0, 2, false); GraphicsContext context = new GraphicsContext(mode, window_info, 1, 0, GraphicsContextFlags.Default); Win32.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero); Win32.wglDeleteContext(renderContextHandle); Win32.wglMakeCurrent(deviceContextHandle, hrc); renderContextHandle = hrc; } catch (Exception) { // TODO: can we actually get the real version? createdOpenGLVersion = OpenGLVersion.OpenGL2_1; } }