[Mesa-dev] [PATCH v2] mesa: Allow override of GL version with environment variable

Ian Romanick idr at freedesktop.org
Tue Sep 27 09:29:13 PDT 2011


On 09/26/2011 01:50 PM, Chad Versace wrote:
> [idr and kwg, I see your point. I've removed the overrides for GLES1 and
> GLES2.]
>
> 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 the OpenGL context by
> setting the environment variable MESA_GL_VERSION_OVERRIDE.
>
> v2
> ---
> - [brianp] Change variable name to MESA_GL_VERSION_OVERRIDE.
> - [brianp] Document in envvars.html.
> - [idr, kwg] Remove overrides for GLES1 and GLES2.
>
> Reviewed-by: Brian Paul<brianp at vmware.com>
> Signed-off-by: Chad Versace<chad at chad-versace.us>

Other than the comment below and Brian's comment about the envvars.html 
description,

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

> ---
>   docs/envvars.html       |    2 ++
>   src/mesa/main/version.c |   24 ++++++++++++++++++++++++
>   2 files changed, 26 insertions(+), 0 deletions(-)
>
> diff --git a/docs/envvars.html b/docs/envvars.html
> index 986d2f8..7280f2b 100644
> --- a/docs/envvars.html
> +++ b/docs/envvars.html
> @@ -58,6 +58,8 @@ 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 - sets the GL version. For example, the value "3.0"
> +will enable support for GL 3.0.
>   <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 80fa0c2..bd6feeb 100644
> --- a/src/mesa/main/version.c
> +++ b/src/mesa/main/version.c
> @@ -27,7 +27,28 @@
>   #include "version.h"
>   #include "git_sha1.h"
>
> +/**
> + * Override GL version by setting environment variable
> + * MESA_GL_VERSION_OVERRIDE.
> + */
> +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);
                                 ^
Spurious period?

> +   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 +204,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,


More information about the mesa-dev mailing list