st-api: Clean-up OpenGL profile handling
authorIan Romanick <ian.d.romanick@intel.com>
Thu, 1 Dec 2011 22:24:55 +0000 (14:24 -0800)
committerIan Romanick <ian.d.romanick@intel.com>
Fri, 23 Dec 2011 16:49:47 +0000 (08:49 -0800)
There seems to have been two different ways to communicate the
profile.  There were flags and there were profiles.  I've opted to
remove the profile flags and use ST_PROFILE_DEFAULT (compatibility
profile) and ST_PROFILE_OPENGL_CORE (core profile) consistently
instead.

Also change the values of the ST_CONTEXT_FLAG_DEBUG and
ST_CONTEXT_FLAG_FORWARD_COMPATIBLE flags to match the WGL and GLX
values.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Chia-I Wu <olv@lunarg.com>
src/gallium/include/state_tracker/st_api.h
src/gallium/state_trackers/glx/xlib/xm_api.c
src/gallium/state_trackers/wgl/stw_context.c

index f7cc2437747edbd4a601adc43d5ede576564436d..3267cb25ef0e2f66c1da3bedc31c46213b2dff80 100644 (file)
@@ -57,10 +57,10 @@ enum st_api_type {
  */
 enum st_profile_type
 {
-   ST_PROFILE_DEFAULT,
-   ST_PROFILE_OPENGL_CORE,
-   ST_PROFILE_OPENGL_ES1,
-   ST_PROFILE_OPENGL_ES2
+   ST_PROFILE_DEFAULT,                 /**< OpenGL compatibility profile */
+   ST_PROFILE_OPENGL_CORE,             /**< OpenGL 3.2+ core profile */
+   ST_PROFILE_OPENGL_ES1,              /**< OpenGL ES 1.x */
+   ST_PROFILE_OPENGL_ES2               /**< OpenGL ES 2.0 */
 };
 
 /* for profile_mask in st_api */
@@ -71,12 +71,13 @@ enum st_profile_type
 
 /**
  * New context flags for GL 3.0 and beyond.
+ *
+ * Profile information (core vs. compatibilty for OpenGL 3.2+) is communicated
+ * through the \c st_profile_type, not through flags.
  */
-#define ST_CONTEXT_FLAG_CORE_PROFILE        (1 << 0)
-#define ST_CONTEXT_FLAG_COMPATIBLE_PROFILE  (1 << 1)
-#define ST_CONTEXT_FLAG_FORWARD_COMPATIBLE  (1 << 2)
-#define ST_CONTEXT_FLAG_DEBUG               (1 << 3)
-#define ST_CONTEXT_FLAG_ROBUST_ACCESS       (1 << 4)
+#define ST_CONTEXT_FLAG_DEBUG               (1 << 0)
+#define ST_CONTEXT_FLAG_FORWARD_COMPATIBLE  (1 << 1)
+#define ST_CONTEXT_FLAG_ROBUST_ACCESS       (1 << 2)
 
 /**
  * Used in st_context_iface->teximage.
index 75e9e11e05dacacc12924a472427ab40a82d44db..5d99e5f7a4e3a892a4cae280ccc2eb6c0c8da00b 100644 (file)
@@ -878,7 +878,6 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list,
    c->xm_read_buffer = NULL;
 
    memset(&attribs, 0, sizeof(attribs));
-   attribs.profile = ST_PROFILE_DEFAULT;
    attribs.visual = v->stvis;
    attribs.major = major;
    attribs.minor = minor;
@@ -888,10 +887,23 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list,
       attribs.flags |= ST_CONTEXT_FLAG_DEBUG;
    if (contextFlags & GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB)
       attribs.flags |= ST_CONTEXT_FLAG_ROBUST_ACCESS;
-   if (profileMask & GLX_CONTEXT_CORE_PROFILE_BIT_ARB)
-      attribs.flags |= ST_CONTEXT_FLAG_CORE_PROFILE;
-   if (profileMask & GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB)
-      attribs.flags |= ST_CONTEXT_FLAG_COMPATIBLE_PROFILE;
+
+   /* There are no profiles before OpenGL 3.2.  The
+    * GLX_ARB_create_context_profile spec says:
+    *
+    *     "If the requested OpenGL version is less than 3.2,
+    *     GLX_CONTEXT_PROFILE_MASK_ARB is ignored and the functionality of the
+    *     context is determined solely by the requested version."
+    *
+    * The spec also says:
+    *
+    *     "The default value for GLX_CONTEXT_PROFILE_MASK_ARB is
+    *     GLX_CONTEXT_CORE_PROFILE_BIT_ARB."
+    */
+   attribs.profile = ST_PROFILE_DEFAULT;
+   if ((major > 3 || (major == 3 && minor >= 2))
+       && ((profileMask & GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB) == 0))
+      attribs.profile = ST_PROFILE_OPENGL_CORE;
 
    c->st = stapi->create_context(stapi, xmdpy->smapi,
          &attribs, (share_list) ? share_list->st : NULL);
index 6cc8a83150c3e263f779fadb46a55ee6d0ce034a..2c4fb0ef084544b2f4eedb8691433b45fbfa44bb 100644 (file)
@@ -169,7 +169,6 @@ stw_create_context_attribs(
    ctx->iPixelFormat = iPixelFormat;
 
    memset(&attribs, 0, sizeof(attribs));
-   attribs.profile = ST_PROFILE_DEFAULT;
    attribs.visual = pfi->stvis;
    attribs.major = majorVersion;
    attribs.minor = minorVersion;
@@ -177,10 +176,23 @@ stw_create_context_attribs(
       attribs.flags |= ST_CONTEXT_FLAG_FORWARD_COMPATIBLE;
    if (contextFlags & WGL_CONTEXT_DEBUG_BIT_ARB)
       attribs.flags |= ST_CONTEXT_FLAG_DEBUG;
-   if (profileMask & WGL_CONTEXT_CORE_PROFILE_BIT_ARB)
-      attribs.flags |= ST_CONTEXT_FLAG_CORE_PROFILE;
-   if (profileMask & WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB)
-      attribs.flags |= ST_CONTEXT_FLAG_COMPATIBLE_PROFILE;
+
+   /* There are no profiles before OpenGL 3.2.  The
+    * WGL_ARB_create_context_profile spec says:
+    *
+    *     "If the requested OpenGL version is less than 3.2,
+    *     WGL_CONTEXT_PROFILE_MASK_ARB is ignored and the functionality of the
+    *     context is determined solely by the requested version."
+    *
+    * The spec also says:
+    *
+    *     "The default value for WGL_CONTEXT_PROFILE_MASK_ARB is
+    *     WGL_CONTEXT_CORE_PROFILE_BIT_ARB."
+    */
+   attribs.profile = ST_PROFILE_DEFAULT;
+   if ((major > 3 || (major == 3 && minor >= 2))
+       && ((profileMask & WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB) == 0))
+      attribs.profile = ST_PROFILE_OPENGL_CORE;
 
    ctx->st = stw_dev->stapi->create_context(stw_dev->stapi,
          stw_dev->smapi, &attribs, shareCtx ? shareCtx->st : NULL);