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

This patch allows one to override the version of an OpenGL, OpenGL ES1, or
OpenGL ES2 context by setting the environment variable MESA_GL_VERSION,
MESA_GLES1_VERSION, or MESA_GLES2_VERSION.

CC: Paul Berry <stereotype...@gmail.com>
Signed-off-by: Chad Versace <c...@chad-versace.us>
---
 src/mesa/main/version.c |   55 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/version.c b/src/mesa/main/version.c
index 80fa0c2..128c3af 100644
--- a/src/mesa/main/version.c
+++ b/src/mesa/main/version.c
@@ -27,7 +27,40 @@
 #include "version.h"
 #include "git_sha1.h"
 
+/**
+ * \brief Override GL version
+ *
+ */
+static void
+override_version(struct gl_context *ctx, GLuint *major, GLuint *minor)
+{
+   const char *env_var;
+   const char *version;
+   int n;
+
+   switch (ctx->API) {
+   case API_OPENGL:
+      env_var = "MESA_GL_VERSION";
+      break;
+   case API_OPENGLES:
+      env_var = "MESA_GLES1_VERSION";
+      break;
+   case API_OPENGLES2:
+      env_var = "MESA_GLES2_VERSION";
+      break;
+   }
 
+   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.
@@ -183,6 +216,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,
@@ -213,13 +249,20 @@ compute_version_es1(struct gl_context *ctx)
                               ctx->Extensions.SGIS_generate_mipmap &&
                               ctx->Extensions.ARB_vertex_buffer_object);
 
+   /* Set to 0 so that we can detect if the version is not set. */
+   ctx->VersionMajor = 0;
+
    if (ver_1_1) {
       ctx->VersionMajor = 1;
       ctx->VersionMinor = 1;
    } else if (ver_1_0) {
       ctx->VersionMajor = 1;
       ctx->VersionMinor = 0;
-   } else {
+   }
+
+   override_version(ctx, &ctx->VersionMajor, &ctx->VersionMinor);
+
+   if (ctx->VersionMajor == 0) {
       _mesa_problem(ctx, "Incomplete OpenGL ES 1.0 support.");
    }
 
@@ -253,10 +296,18 @@ compute_version_es2(struct gl_context *ctx)
                               ctx->Extensions.ARB_fragment_shader &&
                               ctx->Extensions.ARB_texture_non_power_of_two &&
                               ctx->Extensions.EXT_blend_equation_separate);
+
+   /* Set to 0 so that we can detect if the version is not set. */
+   ctx->VersionMajor = 0;
+
    if (ver_2_0) {
       ctx->VersionMajor = 2;
       ctx->VersionMinor = 0;
-   } else {
+   }
+
+   override_version(ctx, &ctx->VersionMajor, &ctx->VersionMinor);
+
+   if (ctx->VersionMajor == 0) {
       _mesa_problem(ctx, "Incomplete OpenGL ES 2.0 support.");
    }
 
-- 
1.7.6.2

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

Reply via email to