/// <summary> /// Query the version of the current OpenGL context. /// </summary> /// <returns> /// It returns the <see cref="KhronosVersion"/> specifying teh actual version of <paramref name="ctx"/>. /// </returns> internal static KhronosVersion QueryContextVersion() { IntPtr ctx = GetCurrentContext(); if (ctx == null) { throw new InvalidOperationException("no current context"); } // Load minimal Gl functions for querying information IGetProcAddress getProcAddress = GetProcAddress.GetProcAddressGL; if (Egl.IsRequired == false) { Gl.BindAPIFunction(Gl.Version_100, "glGetError", getProcAddress); Gl.BindAPIFunction(Gl.Version_100, "glGetString", getProcAddress); } else { Gl.BindAPIFunction(Gl.Version_320_ES, "glGetError", getProcAddress); Gl.BindAPIFunction(Gl.Version_320_ES, "glGetString", getProcAddress); } // Parse version string (effective for detecting Desktop and ES contextes) KhronosVersion glversion = KhronosVersion.Parse(Gl.GetString(StringName.Version)); // ATM do not support fancy context creation flags return(glversion); }
/// <summary> /// Query the version of the current OpenGL context. /// </summary> /// <returns> /// It returns the <see cref="KhronosVersion"/> specifying teh actual version of <paramref name="ctx"/>. /// </returns> private static KhronosVersion QueryContextVersion() { IntPtr ctx = DeviceContext.GetCurrentContext(); if (ctx == null) { throw new InvalidOperationException("no current context"); } // Load minimal Gl functions for querying information IGetProcAddress getProcAddress = GetProcAddress.GetProcAddressGL; if (Egl.IsRequired == false) { Gl.BindAPIFunction(Gl.Version_100, null, "glGetError", getProcAddress); Gl.BindAPIFunction(Gl.Version_100, null, "glGetString", getProcAddress); Gl.BindAPIFunction(Gl.Version_100, null, "glGetIntegerv", getProcAddress); } else { Gl.BindAPIFunction(Gl.Version_320_ES, null, "glGetError", getProcAddress); Gl.BindAPIFunction(Gl.Version_320_ES, null, "glGetString", getProcAddress); Gl.BindAPIFunction(Gl.Version_320_ES, null, "glGetIntegerv", getProcAddress); } // Parse version string (effective for detecting Desktop and ES contextes) KhronosVersion glversion = KhronosVersion.Parse(Gl.GetString(StringName.Version)); // Context profile if (glversion.Api == KhronosVersion.ApiGl && glversion >= Gl.Version_320) { string glProfile = null; int ctxProfile = 0; Gl.Get(Gl.CONTEXT_PROFILE_MASK, out ctxProfile); if ((ctxProfile & Gl.CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0) { glProfile = KhronosVersion.ProfileCompatibility; } else if ((ctxProfile & Gl.CONTEXT_CORE_PROFILE_BIT) != 0) { glProfile = KhronosVersion.ProfileCore; } else { glProfile = KhronosVersion.ProfileCompatibility; } return(new KhronosVersion(glversion, glProfile)); } else { return(new KhronosVersion(glversion, KhronosVersion.ProfileCompatibility)); } }