[Mesa-dev] [PATCH] mesa: allow MESA_GL_VERSION_OVERRIDE to override the API type

Jordan Justen jordan.l.justen at intel.com
Sat Sep 1 10:14:54 PDT 2012


Change the format to [MAJOR.MINOR][CORE|COMPAT]
For example: 3.0, CORE, COMPAT, 3.2CORE

Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
---
 docs/envvars.html       |   11 +++--
 src/mesa/main/context.c |    4 ++
 src/mesa/main/version.c |  104 ++++++++++++++++++++++++++++++++++++++++++-----
 src/mesa/main/version.h |    3 ++
 4 files changed, 108 insertions(+), 14 deletions(-)

diff --git a/docs/envvars.html b/docs/envvars.html
index 89f7173..a42018e 100644
--- a/docs/envvars.html
+++ b/docs/envvars.html
@@ -62,9 +62,14 @@ If the extension string is too long, the buffer overrun can cause the game
 to crash.
 This is a work-around for that.
 <li>MESA_GL_VERSION_OVERRIDE - changes the value returned by
-glGetString(GL_VERSION). Valid values are point-separated version numbers,
-such as "3.0". Mesa will not really implement all the features of the given
-version if it's higher than what's normally reported.
+glGetString(GL_VERSION) and/or the GL API type.
+<ul>
+<li> The format should be [MAJOR.MINOR][CORE|COMPAT]
+<li> Some valid examples are: 3.0, CORE, COMPAT, 3.2CORE
+<li> 3.0 - override the version, but not affect the API type
+<li> CORE or COMPAT - override the API type, but not affect the version
+<li> 3.2CORE - override both the version and the API type
+</ul>
 <li>MESA_GLSL_VERSION_OVERRIDE - changes the value returned by
 glGetString(GL_SHADING_LANGUAGE_VERSION). Valid values are integers, such as
 "130".  Mesa will not really implement all the features of the given language version
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index feddbaa..a31cada 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -932,6 +932,10 @@ _mesa_initialize_context(struct gl_context *ctx,
    ctx->WinSysDrawBuffer = NULL;
    ctx->WinSysReadBuffer = NULL;
 
+   if (_mesa_is_desktop_gl(ctx)) {
+      _mesa_override_gl_version(ctx);
+   }
+
    /* misc one-time initializations */
    one_time_init(ctx);
 
diff --git a/src/mesa/main/version.c b/src/mesa/main/version.c
index 512a9d7..3187e7a 100644
--- a/src/mesa/main/version.c
+++ b/src/mesa/main/version.c
@@ -55,6 +55,98 @@ override_version(struct gl_context *ctx)
 }
 
 /**
+ * Scans 'string' to see if it ends with 'ending' and if it
+ * does, 'string' is modified to remove the ending value.
+ */
+static GLboolean
+check_for_ending_and_remove(char *string, const char *ending)
+{
+   int len1, len2;
+
+   len1 = strlen(string);
+   len2 = strlen(ending);
+
+   if (len2 > len1) {
+      return GL_FALSE;
+   }
+
+   if (strcmp(string + (len1 - len2), ending) == 0) {
+      string[len1 - len2] = 0;
+      return GL_TRUE;
+   } else {
+      return GL_FALSE;
+   }
+}
+
+/**
+ * Scans 'string' to see if it ends with 'ending' and if it
+ * does, 'string' is modified to remove the ending value.
+ */
+static GLboolean
+create_gl_version_string(struct gl_context *ctx)
+{
+   static const int max = 100;
+
+   ctx->VersionString = (char *) malloc(max);
+   if (ctx->VersionString) {
+      _mesa_snprintf(ctx->VersionString, max,
+		     "%u.%u Mesa " MESA_VERSION_STRING
+#ifdef MESA_GIT_SHA1
+		     " (" MESA_GIT_SHA1 ")"
+#endif
+		     ,
+		     _mesa_get_version_major(ctx), _mesa_get_version_minor(ctx));
+   }
+}
+
+/**
+ * Override the context's version and/or API type if the
+ * environment variable MESA_GL_VERSION_OVERRIDE is set.
+ *
+ * Example uses of MESA_GL_VERSION_OVERRIDE:
+ *
+ * 3.0: Override version to 3.0, but don't change API type
+ * COMPAT: Override API type to API_OPENGL, but don't change the version
+ * CORE: Override API type to API_OPENGL_CORE, but don't change the version
+ * 3.2CORE: Override API type to API_OPENGL_CORE, and the version to 3.2
+ */
+void
+_mesa_override_gl_version(struct gl_context *ctx)
+{
+   const char *env_var = "MESA_GL_VERSION_OVERRIDE";
+   const char *version;
+   char *version_dup;
+   int n;
+   int major, minor;
+
+   version = getenv(env_var);
+   if (!version) {
+      return;
+   }
+
+   version_dup = strdup(version);
+   assert (version != NULL);
+
+   if (check_for_ending_and_remove(version_dup, "CORE")) {
+      ctx->API = API_OPENGL_CORE;
+   } else if (check_for_ending_and_remove(version_dup, "COMPAT")) {
+      ctx->API = API_OPENGL;
+   }
+
+   if (version_dup[0] != 0) {
+      n = sscanf(version, "%u.%u", &major, &minor);
+      if (n != 2) {
+         fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version);
+      } else {
+         _mesa_set_version(ctx, major, minor);
+         create_gl_version_string(ctx);
+      }
+   }
+
+   free(version_dup);
+}
+
+/**
  * Override the context's GLSL version if the environment variable
  * MESA_GLSL_VERSION_OVERRIDE is set. Valid values for
  * MESA_GLSL_VERSION_OVERRIDE are integers, such as "130".
@@ -85,7 +177,6 @@ static void
 compute_version(struct gl_context *ctx)
 {
    GLuint major, minor;
-   static const int max = 100;
 
    const GLboolean ver_1_3 = (ctx->Extensions.ARB_texture_border_clamp &&
                               ctx->Extensions.ARB_texture_cube_map &&
@@ -224,16 +315,7 @@ compute_version(struct gl_context *ctx)
 
    override_version(ctx);
 
-   ctx->VersionString = (char *) malloc(max);
-   if (ctx->VersionString) {
-      _mesa_snprintf(ctx->VersionString, max,
-		     "%u.%u Mesa " MESA_VERSION_STRING
-#ifdef MESA_GIT_SHA1
-		     " (" MESA_GIT_SHA1 ")"
-#endif
-		     ,
-		     major, minor);
-   }
+   create_gl_version_string(ctx);
 }
 
 static void
diff --git a/src/mesa/main/version.h b/src/mesa/main/version.h
index d60cde6..992bb74 100644
--- a/src/mesa/main/version.h
+++ b/src/mesa/main/version.h
@@ -51,6 +51,9 @@ extern void
 _mesa_compute_version(struct gl_context *ctx);
 
 extern void
+_mesa_override_gl_version(struct gl_context *ctx);
+
+extern void
 _mesa_override_glsl_version(struct gl_context *ctx);
 
 /**
-- 
1.7.9.5



More information about the mesa-dev mailing list