mesa: allow MESA_GL_VERSION_OVERRIDE to override the API type

Change the format to MAJOR.MINOR[FC]
For example: 2.1, 3.0FC, 3.1

The FC suffix indicates a forward compatible context, and
is only valid for versions >= 3.0.

Examples:
2.1:   GL Legacy/Compatibility context
3.0:   GL Legacy/Compatibility context
3.0FC: GL Core Profile context + Forward Compatible
3.1:   GL Core Profile context
3.1FC: GL Core Profile context + Forward Compatible

Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
Jordan Justen 2012-09-01 01:38:08 -07:00
parent e87c63f288
commit 00905dbf19
4 changed files with 88 additions and 23 deletions

View File

@ -69,9 +69,25 @@ If the extension string is too long, the buffer overrun can cause the game
to crash. to crash.
This is a work-around for that. This is a work-around for that.
<li>MESA_GL_VERSION_OVERRIDE - changes the value returned by <li>MESA_GL_VERSION_OVERRIDE - changes the value returned by
glGetString(GL_VERSION). Valid values are point-separated version numbers, glGetString(GL_VERSION) and possibly the GL API type.
such as "3.0". Mesa will not really implement all the features of the given <ul>
version if it's higher than what's normally reported. <li> The format should be MAJOR.MINOR[FC]
<li> FC is an optional suffix that indicates a forward compatible context.
This is only valid for versions &gt;= 3.0.
<li> GL versions &lt; 3.0 are set to a compatibility (non-Core) profile
<li> GL versions = 3.0, see below
<li> GL versions &gt; 3.0 are set to a Core profile
<li> Examples: 2.1, 3.0, 3.0FC, 3.1, 3.1FC
<ul>
<li> 2.1 - select a compatibility (non-Core) profile with GL version 2.1
<li> 3.0 - select a compatibility (non-Core) profile with GL version 3.0
<li> 3.0FC - select a Core+Forward Compatible profile with GL version 3.0
<li> 3.1 - select a Core profile with GL version 3.1
<li> 3.1FC - select a Core+Forward Compatible profile with GL version 3.1
</ul>
<li> Mesa may not really implement all the features of the given version.
(for developers only)
</ul>
<li>MESA_GLSL_VERSION_OVERRIDE - changes the value returned by <li>MESA_GLSL_VERSION_OVERRIDE - changes the value returned by
glGetString(GL_SHADING_LANGUAGE_VERSION). Valid values are integers, such as 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 "130". Mesa will not really implement all the features of the given language version

View File

@ -921,6 +921,10 @@ _mesa_initialize_context(struct gl_context *ctx,
ctx->WinSysDrawBuffer = NULL; ctx->WinSysDrawBuffer = NULL;
ctx->WinSysReadBuffer = NULL; ctx->WinSysReadBuffer = NULL;
if (_mesa_is_desktop_gl(ctx)) {
_mesa_override_gl_version(ctx);
}
/* misc one-time initializations */ /* misc one-time initializations */
one_time_init(ctx); one_time_init(ctx);

View File

@ -28,30 +28,25 @@
#include "git_sha1.h" #include "git_sha1.h"
/** /**
* Override the context's GL version if the environment variable * Scans 'string' to see if it ends with 'ending'.
* MESA_GL_VERSION_OVERRIDE is set. Valid values of MESA_GL_VERSION_OVERRIDE
* are point-separated version numbers, such as "3.0".
*/ */
static void static GLboolean
override_version(struct gl_context *ctx) check_for_ending(char *string, const char *ending)
{ {
const char *env_var = "MESA_GL_VERSION_OVERRIDE"; int len1, len2;
const char *version;
int n;
int major, minor;
version = getenv(env_var); len1 = strlen(string);
if (!version) { len2 = strlen(ending);
return;
if (len2 > len1) {
return GL_FALSE;
} }
n = sscanf(version, "%u.%u", &major, &minor); if (strcmp(string + (len1 - len2), ending) == 0) {
if (n != 2) { return GL_TRUE;
fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version); } else {
return; return GL_FALSE;
} }
ctx->Version = major * 10 + minor;
} }
/** /**
@ -77,6 +72,55 @@ create_version_string(struct gl_context *ctx, const char *prefix)
} }
} }
/**
* 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:
*
* 2.1: select a compatibility (non-Core) profile with GL version 2.1
* 3.0: select a compatibility (non-Core) profile with GL version 3.0
* 3.0FC: select a Core+Forward Compatible profile with GL version 3.0
* 3.1: select a Core profile with GL version 3.1
* 3.1FC: select a Core+Forward Compatible profile with GL version 3.1
*/
void
_mesa_override_gl_version(struct gl_context *ctx)
{
const char *env_var = "MESA_GL_VERSION_OVERRIDE";
const char *version;
int n;
int major, minor;
GLboolean fc_suffix;
version = getenv(env_var);
if (!version) {
return;
}
fc_suffix = check_for_ending(version, "FC");
n = sscanf(version, "%u.%u", &major, &minor);
if (n != 2) {
fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version);
} else {
ctx->Version = major * 10 + minor;
if (ctx->Version < 30 && fc_suffix) {
fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version);
} else {
if (ctx->Version >= 30 && fc_suffix) {
ctx->API = API_OPENGL_CORE;
ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
} else if (ctx->Version >= 31) {
ctx->API = API_OPENGL_CORE;
} else {
ctx->API = API_OPENGL;
}
create_version_string(ctx, "");
}
}
}
/** /**
* Override the context's GLSL version if the environment variable * Override the context's GLSL version if the environment variable
* MESA_GLSL_VERSION_OVERRIDE is set. Valid values for * MESA_GLSL_VERSION_OVERRIDE is set. Valid values for
@ -244,8 +288,6 @@ compute_version(struct gl_context *ctx)
ctx->Version = major * 10 + minor; ctx->Version = major * 10 + minor;
override_version(ctx);
create_version_string(ctx, ""); create_version_string(ctx, "");
} }

View File

@ -45,6 +45,9 @@ struct gl_context;
extern void extern void
_mesa_compute_version(struct gl_context *ctx); _mesa_compute_version(struct gl_context *ctx);
extern void
_mesa_override_gl_version(struct gl_context *ctx);
extern void extern void
_mesa_override_glsl_version(struct gl_context *ctx); _mesa_override_glsl_version(struct gl_context *ctx);