[waffle] [PATCH 2/3] cgl: Handle requested context version more leniently

Chad Versace chad.versace at linux.intel.com
Fri Jul 19 21:43:35 PDT 2013


Before, Waffle required that the requested context version be exactly
1.0 (the default value), in which Waffle created an OpenGL 2.1 context,
  or be exactly 3.2.

Instead, let's be more lenient when handling the requested context
version by emulating EGL_KHR_create_context. Whatever context version
the user requests, now Waffle returns a context of the highest
backwards-compatible version supported by the system.

CC: Nigel Stewart <nigels.com at gmail.com>
CC: Jeff Bland <jksb at linux.com>
Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
 src/waffle/cgl/cgl_config.m | 58 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 55 insertions(+), 3 deletions(-)

diff --git a/src/waffle/cgl/cgl_config.m b/src/waffle/cgl/cgl_config.m
index e1c5027..197fb60 100644
--- a/src/waffle/cgl/cgl_config.m
+++ b/src/waffle/cgl/cgl_config.m
@@ -58,9 +58,49 @@ cgl_config_check_attrs(const struct wcore_config_attrs *attrs)
 {
     switch (attrs->context_api) {
         case WAFFLE_CONTEXT_OPENGL:
+            // Waffle tries to emulate the behavior of EGL whenever applicable.
+            // In particular, Waffle tries here to implement the behavior
+            // described in the EGL_KHR_create_context spec.  According to
+            // EGL_KHR_create_context, "the context returned must be <backwards
+            // compatible> with the requested version".  The spec further
+            // suggests that "the implementation will return the most recent
+            // version of OpenGL it supports which is backwards compatible with
+            // the requested version".  Waffle attempts here to implement that
+            // suggested behavior.
+            //
+            // Here is the current status of Mac's OpenGL support, which
+            // informs the decisions made below.
+            //
+            //    10.4: Waffle doesn't support.
+            //    10.5: OpenGL 2.1
+            //    10.6 to 10.8: OpenGL 2.1 and OpenGL 3.2 Core Profile
+            //
             switch (attrs->context_full_version) {
                 case 10:
+                case 11:
+                case 12:
+                case 14:
+                case 15:
+                case 20:
+                case 21:
+                    // Create OpenGL 2.1 context.
                     return true;
+                case 30:
+                    goto error_unsupported_gl_version;
+                case 31:
+                    #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
+                        // Create an OpenGL 3.2 Core Context.
+                        //
+                        // OpenGL 3.1 is a special case for GLX and EGL.
+                        // According to EGL_KHR_create_context, "if OpenGL 3.1
+                        // is requested, the context returned may implement
+                        // [...] the core profile of verison 3.2 or greater";
+                        // and the "EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR is
+                        // ignored".
+                        return true;
+                    #else
+                        goto error_unsupported_gl_version;
+                    #endif
                 case 32:
                     #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
                         switch (attrs->context_profile) {
@@ -81,11 +121,14 @@ cgl_config_check_attrs(const struct wcore_config_attrs *attrs)
                                      ">= 10.6 is required");
                         return false;
                     #endif
+                error_unsupported_gl_version:
                 default:
                     wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
-                                 "On CGL, the requested OpenGL version must "
-                                 "be 1.0 or 3.2");
-                    assert(false);
+                                 "Waffle's CGL backend does not support "
+                                 "creation of OpenGL %d.%d contexts",
+                                 attrs->context_major_version,
+                                 attrs->context_minor_version);
+                                 attrs->context_minor_version);
                     return false;
             }
         case WAFFLE_CONTEXT_OPENGL_ES1:
@@ -122,9 +165,15 @@ cgl_config_fill_pixel_format_attrs(
         }
 
 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
+    // Validation of context version and profile has already occured in
+    // cgl_check_config_attrs().  The decisions made here are documented in
+    // that function.
     if (attrs->context_full_version == 10) {
         ADD_ATTR(kCGLPFAOpenGLProfile, (int) kCGLOGLPVersion_Legacy);
     }
+    else if (attrs->context_full_version == 31) {
+        ADD_ATTR(kCGLPFAOpenGLProfile, (int) kCGLOGLPVersion_3_2_Core);
+    }
     else if (attrs->context_full_version == 32
              && attrs->context_profile == WAFFLE_CONTEXT_CORE_PROFILE) {
         ADD_ATTR(kCGLPFAOpenGLProfile, (int) kCGLOGLPVersion_3_2_Core);
@@ -135,6 +184,9 @@ cgl_config_fill_pixel_format_attrs(
                              attrs->context_profile);
         return false;
     }
+#else
+    // Create an OpenGL 2.1 context.
+    assert(attrs->context_full_version <= 21);
 #endif
 
     ADD_ATTR(kCGLPFAColorSize,          attrs->rgb_size);
-- 
1.8.3.3



More information about the waffle mailing list