mesa version: add _mesa_get_gl_version_override
[mesa.git] / src / mesa / main / version.c
index eef8f437d62bf557d79bd7122822f1c6a8f530d5..c903189812930f1ebead7eb0b2f11d873884eb51 100644 (file)
@@ -49,6 +49,45 @@ check_for_ending(const char *string, const char *ending)
    }
 }
 
+/**
+ * Returns the gl override data
+ *
+ * version > 0 indicates there is an override requested
+ * fwd_context is only valid if version > 0
+ */
+static void
+get_gl_override(int *version, GLboolean *fwd_context)
+{
+   const char *env_var = "MESA_GL_VERSION_OVERRIDE";
+   const char *version_str;
+   int major, minor, n;
+   static int override_version = -1;
+   static GLboolean fc_suffix = GL_FALSE;
+
+   if (override_version < 0) {
+      override_version = 0;
+
+      version_str = getenv(env_var);
+      if (version_str) {
+         fc_suffix = check_for_ending(version_str, "FC");
+
+         n = sscanf(version_str, "%u.%u", &major, &minor);
+         if (n != 2) {
+            fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version_str);
+            override_version = 0;
+         } else {
+            override_version = major * 10 + minor;
+            if (override_version < 30 && fc_suffix) {
+               fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version_str);
+            }
+         }
+      }
+   }
+
+   *version = override_version;
+   *fwd_context = fc_suffix;
+}
+
 /**
  * Builds the MESA version string.
  */
@@ -87,40 +126,41 @@ create_version_string(struct gl_context *ctx, const char *prefix)
 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;
+   int version;
+   GLboolean fwd_context;
 
-   version = getenv(env_var);
-   if (!version) {
-      return;
-   }
+   get_gl_override(&version, &fwd_context);
 
-   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);
+   if (version > 0) {
+      ctx->Version = version;
+      if (version >= 30 && fwd_context) {
+         ctx->API = API_OPENGL_CORE;
+         ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
+      } else if (version >= 31) {
+         ctx->API = API_OPENGL_CORE;
       } 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_COMPAT;
-         }
-         create_version_string(ctx, "");
+         ctx->API = API_OPENGL_COMPAT;
       }
+      create_version_string(ctx, "");
    }
 }
 
+/**
+ * Returns the gl override value
+ *
+ * version > 0 indicates there is an override requested
+ */
+int
+_mesa_get_gl_version_override(void)
+{
+   int version;
+   GLboolean fwd_context;
+
+   get_gl_override(&version, &fwd_context);
+
+   return version;
+}
+
 /**
  * Override the context's GLSL version if the environment variable
  * MESA_GLSL_VERSION_OVERRIDE is set. Valid values for
@@ -323,7 +363,30 @@ 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);
-   if (ver_2_0) {
+   /* FINISHME: This list isn't quite right. */
+   const GLboolean ver_3_0 = (ctx->Extensions.ARB_half_float_vertex &&
+                              ctx->Extensions.ARB_internalformat_query &&
+                              ctx->Extensions.ARB_map_buffer_range &&
+                              ctx->Extensions.ARB_shader_texture_lod &&
+                              ctx->Extensions.ARB_texture_float &&
+                              ctx->Extensions.ARB_texture_rg &&
+                              ctx->Extensions.ARB_texture_compression_rgtc &&
+                              ctx->Extensions.EXT_draw_buffers2 &&
+                              /* ctx->Extensions.ARB_framebuffer_object && */
+                              ctx->Extensions.EXT_framebuffer_sRGB &&
+                              ctx->Extensions.EXT_packed_float &&
+                              ctx->Extensions.EXT_texture_array &&
+                              ctx->Extensions.EXT_texture_shared_exponent &&
+                              ctx->Extensions.EXT_transform_feedback &&
+                              ctx->Extensions.NV_conditional_render &&
+                              ctx->Extensions.ARB_draw_instanced &&
+                              ctx->Extensions.ARB_uniform_buffer_object &&
+                              ctx->Extensions.EXT_texture_snorm &&
+                              ctx->Extensions.NV_primitive_restart &&
+                              ctx->Extensions.OES_depth_texture_cube_map);
+   if (ver_3_0) {
+      ctx->Version = 30;
+   } else if (ver_2_0) {
       ctx->Version = 20;
    } else {
       _mesa_problem(ctx, "Incomplete OpenGL ES 2.0 support.");
@@ -345,6 +408,12 @@ _mesa_compute_version(struct gl_context *ctx)
 
    switch (ctx->API) {
    case API_OPENGL_COMPAT:
+      /* Disable GLSL 1.40 and later for legacy contexts.
+       * This disallows creation of the GL 3.1 compatibility context. */
+      if (ctx->Const.GLSLVersion > 130) {
+         ctx->Const.GLSLVersion = 130;
+      }
+      /* fall through */
    case API_OPENGL_CORE:
       compute_version(ctx);
       break;