+ if (api == EGL_OPENGL_API) {
+ /* The EGL_KHR_create_context spec says:
+ *
+ * "If the requested OpenGL version is less than 3.2,
+ * EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR is ignored and the
+ * functionality of the context is determined solely by the
+ * requested version."
+ *
+ * Since the value is ignored, only validate the setting if the version
+ * is >= 3.2.
+ */
+ if (ctx->ClientMajorVersion >= 4
+ || (ctx->ClientMajorVersion == 3 && ctx->ClientMinorVersion >= 2)) {
+ switch (ctx->Profile) {
+ case EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR:
+ case EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR:
+ break;
+
+ default:
+ /* The EGL_KHR_create_context spec says:
+ *
+ * "* If an OpenGL context is requested, the requested version
+ * is greater than 3.2, and the value for attribute
+ * EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR has no bits set; has
+ * any bits set other than EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR
+ * and EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; has
+ * more than one of these bits set; or if the implementation does
+ * not support the requested profile, then an EGL_BAD_MATCH error
+ * is generated."
+ */
+ err = EGL_BAD_MATCH;
+ break;
+ }
+ }
+
+ /* The EGL_KHR_create_context spec says:
+ *
+ * "* If an OpenGL context is requested and the values for
+ * attributes EGL_CONTEXT_MAJOR_VERSION_KHR and
+ * EGL_CONTEXT_MINOR_VERSION_KHR, when considered together with
+ * the value for attribute
+ * EGL_CONTEXT_FORWARD_COMPATIBLE_BIT_KHR, specify an OpenGL
+ * version and feature set that are not defined, than an
+ * EGL_BAD_MATCH error is generated.
+ *
+ * ... Thus, examples of invalid combinations of attributes
+ * include:
+ *
+ * - Major version < 1 or > 4
+ * - Major version == 1 and minor version < 0 or > 5
+ * - Major version == 2 and minor version < 0 or > 1
+ * - Major version == 3 and minor version < 0 or > 2
+ * - Major version == 4 and minor version < 0 or > 2
+ * - Forward-compatible flag set and major version < 3"
+ */
+ if (ctx->ClientMajorVersion < 1 || ctx->ClientMinorVersion < 0)
+ err = EGL_BAD_MATCH;
+
+ switch (ctx->ClientMajorVersion) {
+ case 1:
+ if (ctx->ClientMinorVersion > 5
+ || (ctx->Flags & EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR) != 0)
+ err = EGL_BAD_MATCH;
+ break;
+
+ case 2:
+ if (ctx->ClientMinorVersion > 1
+ || (ctx->Flags & EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR) != 0)
+ err = EGL_BAD_MATCH;
+ break;
+
+ case 3:
+ /* Note: The text above is incorrect. There *is* an OpenGL 3.3!
+ */
+ if (ctx->ClientMinorVersion > 3)
+ err = EGL_BAD_MATCH;
+ break;
+
+ case 4:
+ default:
+ /* Don't put additional version checks here. We don't know that
+ * there won't be versions > 4.2.
+ */
+ break;
+ }
+ } else if (api == EGL_OPENGL_ES_API) {
+ /* The EGL_KHR_create_context spec says:
+ *
+ * "* If an OpenGL ES context is requested and the values for
+ * attributes EGL_CONTEXT_MAJOR_VERSION_KHR and
+ * EGL_CONTEXT_MINOR_VERSION_KHR specify an OpenGL ES version that
+ * is not defined, than an EGL_BAD_MATCH error is generated.
+ *
+ * ... Examples of invalid combinations of attributes include:
+ *
+ * - Major version < 1 or > 2
+ * - Major version == 1 and minor version < 0 or > 1
+ * - Major version == 2 and minor version != 0
+ */
+ if (ctx->ClientMajorVersion < 1 || ctx->ClientMinorVersion < 0)
+ err = EGL_BAD_MATCH;
+
+ switch (ctx->ClientMajorVersion) {
+ case 1:
+ if (ctx->ClientMinorVersion > 1)
+ err = EGL_BAD_MATCH;
+ break;
+
+ case 2:
+ if (ctx->ClientMinorVersion > 0)
+ err = EGL_BAD_MATCH;
+ break;
+
+ case 3:
+ /* Don't put additional version checks here. We don't know that
+ * there won't be versions > 3.0.
+ */
+ break;
+
+ default:
+ err = EGL_BAD_MATCH;
+ break;
+ }
+ }
+
+ switch (ctx->ResetNotificationStrategy) {
+ case EGL_NO_RESET_NOTIFICATION_KHR:
+ case EGL_LOSE_CONTEXT_ON_RESET_KHR:
+ break;
+
+ default:
+ err = EGL_BAD_ATTRIBUTE;
+ break;
+ }
+
+ if ((ctx->Flags & ~(EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR
+ | EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR
+ | EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR)) != 0) {
+ err = EGL_BAD_ATTRIBUTE;
+ }
+