aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mesa/main/context.c4
-rw-r--r--src/mesa/main/version.c82
-rw-r--r--src/mesa/main/version.h3
3 files changed, 69 insertions, 20 deletions
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index e55e2fdee3b..8d5dd1e5bd2 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -921,6 +921,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 19d514d4aa9..a1fcec46dcd 100644
--- a/src/mesa/main/version.c
+++ b/src/mesa/main/version.c
@@ -28,30 +28,25 @@
#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".
+ * Scans 'string' to see if it ends with 'ending'.
*/
-static void
-override_version(struct gl_context *ctx)
+static GLboolean
+check_for_ending(char *string, const char *ending)
{
- const char *env_var = "MESA_GL_VERSION_OVERRIDE";
- const char *version;
- int n;
- int major, minor;
+ int len1, len2;
- version = getenv(env_var);
- if (!version) {
- return;
- }
+ len1 = strlen(string);
+ len2 = strlen(ending);
- n = sscanf(version, "%u.%u", &major, &minor);
- if (n != 2) {
- fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version);
- return;
+ if (len2 > len1) {
+ return GL_FALSE;
}
- ctx->Version = major * 10 + minor;
+ if (strcmp(string + (len1 - len2), ending) == 0) {
+ return GL_TRUE;
+ } else {
+ return GL_FALSE;
+ }
}
/**
@@ -78,6 +73,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
* MESA_GLSL_VERSION_OVERRIDE is set. Valid values for
* MESA_GLSL_VERSION_OVERRIDE are integers, such as "130".
@@ -244,8 +288,6 @@ compute_version(struct gl_context *ctx)
ctx->Version = major * 10 + minor;
- override_version(ctx);
-
create_version_string(ctx, "");
}
diff --git a/src/mesa/main/version.h b/src/mesa/main/version.h
index f0ba6f267fb..1aab37d6936 100644
--- a/src/mesa/main/version.h
+++ b/src/mesa/main/version.h
@@ -46,6 +46,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);
#endif /* VERSION_H */