glsl: allow ForceGLSLVersion to override #version directives
authorBrian Paul <brianp@vmware.com>
Fri, 27 Mar 2015 16:54:10 +0000 (10:54 -0600)
committerBrian Paul <brianp@vmware.com>
Mon, 30 Mar 2015 17:25:39 +0000 (11:25 -0600)
Previously, the ctx->Const.ForceGLSLVersion setting only worked if
the shader lacked a #version directive.  Now, the ForceGLSLVersion
setting will override the #version directive too.

This change should be safe since it should be rare to have an app
that has a mix of shader versions and we only wanted to override
the #version for shaders which lacked the #version directive.

Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
src/glsl/glsl_parser_extras.cpp
src/glsl/glsl_parser_extras.h
src/mesa/main/mtypes.h

index 79624bc263cc1e0a10708bc6b4386ac6ddb49397..0aa3c54fc8ba120348fcd9016856d828a024e278 100644 (file)
@@ -73,8 +73,8 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx,
    this->uses_builtin_functions = false;
 
    /* Set default language version and extensions */
-   this->language_version = ctx->Const.ForceGLSLVersion ?
-                            ctx->Const.ForceGLSLVersion : 110;
+   this->language_version = 110;
+   this->forced_language_version = ctx->Const.ForceGLSLVersion;
    this->es_shader = false;
    this->ARB_texture_rectangle_enable = true;
 
@@ -320,11 +320,14 @@ _mesa_glsl_parse_state::process_version_directive(YYLTYPE *locp, int version,
       this->ARB_texture_rectangle_enable = false;
    }
 
-   this->language_version = version;
+   if (this->forced_language_version)
+      this->language_version = this->forced_language_version;
+   else
+      this->language_version = version;
 
    bool supported = false;
    for (unsigned i = 0; i < this->num_supported_versions; i++) {
-      if (this->supported_versions[i].ver == (unsigned) version
+      if (this->supported_versions[i].ver == this->language_version
           && this->supported_versions[i].es == this->es_shader) {
          supported = true;
          break;
index 0975c86ed7a16a71f613d1d86f72af4f55129221..1f5478bdf7e4276cbbc5c04a47b8067a864d6f9d 100644 (file)
@@ -226,6 +226,7 @@ struct _mesa_glsl_parse_state {
 
    bool es_shader;
    unsigned language_version;
+   unsigned forced_language_version;
    gl_shader_stage stage;
 
    /**
index 8e1dba6f079051e2653ccd8240ec0aba1eff47de..f7187686955b42ecd309f0553b44f8fd12fa81bf 100644 (file)
@@ -3527,8 +3527,8 @@ struct gl_constants
    GLboolean ForceGLSLExtensionsWarn;
 
    /**
-    * If non-zero, forces GLSL shaders without the #version directive to behave
-    * as if they began with "#version ForceGLSLVersion".
+    * If non-zero, forces GLSL shaders to behave as if they began
+    * with "#version ForceGLSLVersion".
     */
    GLuint ForceGLSLVersion;