Module: Mesa
Branch: master
Commit: 0527c11d7aa42bd74f4527d7299e3c18f37c4c44
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=0527c11d7aa42bd74f4527d7299e3c18f37c4c44

Author: Chad Versace <c...@chad-versace.us>
Date:   Mon Sep 26 11:48:46 2011 -0700

mesa: Allow override of GL version with environment variable

It is necessary to manually set the GL version to 3.0 in order to run
Piglit tests that use glGetUniform*().

This patch allows one to override the version of the OpenGL context by
setting the environment variable MESA_GL_VERSION_OVERRIDE.

Reviewed-by: Brian Paul <bri...@vmware.com>
Reviewed-by: Kenneth Graunke <kenn...@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.roman...@intel.com>
Signed-off-by: Chad Versace <c...@chad-versace.us>

---

 docs/envvars.html       |    4 ++++
 src/mesa/main/version.c |   25 +++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/docs/envvars.html b/docs/envvars.html
index 986d2f8..6402ec5 100644
--- a/docs/envvars.html
+++ b/docs/envvars.html
@@ -58,6 +58,10 @@ copied into a fixed-size buffer without truncating.
 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.
 <li>MESA_GLSL - <a href="shading.html#envvars">shading language compiler 
options</a>
 </ul>
 
diff --git a/src/mesa/main/version.c b/src/mesa/main/version.c
index 3842814..a5deeab 100644
--- a/src/mesa/main/version.c
+++ b/src/mesa/main/version.c
@@ -27,7 +27,29 @@
 #include "version.h"
 #include "git_sha1.h"
 
+/**
+ * Override the context's GL version if the environment variable
+ * MESA_GL_VERSION_OVERRIDE is set. Valid values of MESA_GL_VERSION_OVERRIDE
+ * are point-separated version numbers, such as "3.0".
+ */
+static void
+override_version(struct gl_context *ctx, GLuint *major, GLuint *minor)
+{
+   const char *env_var = "MESA_GL_VERSION_OVERRIDE";
+   const char *version;
+   int n;
+
+   version = getenv(env_var);
+   if (!version) {
+      return;
+   }
 
+   n = sscanf(version, "%d.%d", major, minor);
+   if (n != 2) {
+      fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version);
+      return;
+   }
+}
 
 /**
  * Examine enabled GL extensions to determine GL version.
@@ -178,6 +200,9 @@ compute_version(struct gl_context *ctx)
 
    ctx->VersionMajor = major;
    ctx->VersionMinor = minor;
+
+   override_version(ctx, &ctx->VersionMajor, &ctx->VersionMinor);
+
    ctx->VersionString = (char *) malloc(max);
    if (ctx->VersionString) {
       _mesa_snprintf(ctx->VersionString, max,

_______________________________________________
mesa-commit mailing list
mesa-commit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to