/// <summary>
        /// Attempts to create an OpenGL context.
        /// </summary>
        private static IntPtr?TryCreateOpenGLContext(UltravioletContext uv, OpenGLEnvironment environment,
                                                     Version versionRequested, Version versionRequired, Boolean debug, Boolean throwOnFailure)
        {
            if (!environment.RequestDebugContext(debug))
            {
                environment.ThrowPlatformErrorException();
            }

            var gles                = (uv.Platform == UltravioletPlatform.Android || uv.Platform == UltravioletPlatform.iOS);
            var versionArray        = gles ? KnownOpenGLESVersions : KnownOpenGLVersions;
            var versionMin          = versionRequested ?? versionRequired;
            var versionCurrent      = versionRequested ?? versionArray[0];
            var versionCurrentIndex = Array.IndexOf(versionArray, versionCurrent);

            IntPtr context;

            do
            {
                if (versionCurrent < versionMin)
                {
                    if (throwOnFailure)
                    {
                        throw new InvalidOperationException(OpenGLStrings.DoesNotMeetMinimumVersionRequirement.Format(versionMin.Major, versionMin.Minor));
                    }

                    return(null);
                }

                if (!environment.RequestOpenGLVersion(versionCurrent))
                {
                    environment.ThrowPlatformErrorException();
                }

                versionCurrent = versionArray[++versionCurrentIndex];
            }while ((context = environment.CreateOpenGLContext()) == IntPtr.Zero);

            return(context);
        }