glsl2: Add gl_MaxTextureCoords
authorIan Romanick <ian.d.romanick@intel.com>
Thu, 1 Jul 2010 20:30:50 +0000 (13:30 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Thu, 1 Jul 2010 20:30:50 +0000 (13:30 -0700)
src/glsl/ast_to_hir.cpp
src/glsl/glsl_parser_extras.h
src/glsl/ir_variable.cpp
src/glsl/main.cpp
src/mesa/shader/ir_to_mesa.cpp

index 22d9f7ad5325fed22906414feae50f6fdca9725a..fc5a652f25da31782844b24108a2d9765fbb74db 100644 (file)
@@ -1817,20 +1817,16 @@ ast_declarator_list::hir(exec_list *instructions,
             *
             *     "The size [of gl_TexCoord] can be at most
             *     gl_MaxTextureCoords."
-            *
-            * FINISHME: Every platform that supports GLSL sets
-            * FINISHME: gl_MaxTextureCoords to at least 4, so hard-code 4
-            * FINISHME: for now.
             */
+           const unsigned size = unsigned(var->type->array_size());
            if ((strcmp("gl_TexCoord", var->name) == 0)
-               && (var->type->array_size() > 4)) {
+               && (size > state->Const.MaxTextureCoords)) {
               YYLTYPE loc = this->get_location();
 
               _mesa_glsl_error(& loc, state, "`gl_TexCoord' array size cannot "
                                "be larger than gl_MaxTextureCoords (%u)\n",
-                               4);
-           } else if (var->type->array_size() <=
-                      (int)earlier->max_array_access) {
+                               state->Const.MaxTextureCoords);
+           } else if (size <= earlier->max_array_access) {
               YYLTYPE loc = this->get_location();
 
               _mesa_glsl_error(& loc, state, "array size must be > %u due to "
index f957a926be39f8e8b777539cc254e96545b1df3a..3aeba83cc525129160cfa05a601fdb8d2bf836a9 100644 (file)
@@ -50,6 +50,7 @@ struct _mesa_glsl_parse_state {
     */
    struct {
       unsigned MaxDrawBuffers;
+      unsigned MaxTextureCoords;
    } Const;
 
    /**
index d43809ef9c28d025d3be2591e8ddfda70dab0f05..9daad803e9606e7ec219a5d68c56b42eb1e511c9 100644 (file)
@@ -96,25 +96,28 @@ add_builtin_variable(const builtin_variable *proto, exec_list *instructions,
 
 static void
 generate_110_uniforms(exec_list *instructions,
-                     glsl_symbol_table *symtab)
+                     struct _mesa_glsl_parse_state *state)
 {
    for (unsigned i = 0
           ; i < Elements(builtin_110_deprecated_uniforms)
           ; i++) {
       add_builtin_variable(& builtin_110_deprecated_uniforms[i],
-                          instructions, symtab);
+                          instructions, state->symbols);
    }
 
-   /* FINISHME: The size of this array is implementation dependent based on the
-    * FINISHME: value of GL_MAX_TEXTURE_COORDS.  Every platform that supports
-    * FINISHME: GLSL sets GL_MAX_TEXTURE_COORDS to at least 4, so hard-code 4
-    * FINISHME: for now.
-    */
+   ir_variable *const mtc = add_variable("gl_MaxTextureCoords", ir_var_auto,
+                                        -1, glsl_type::int_type,
+                                        instructions, state->symbols);
+   mtc->constant_value = new(mtc)
+      ir_constant(int(state->Const.MaxTextureCoords));
+
+
    const glsl_type *const mat4_array_type =
-      glsl_type::get_array_instance(symtab, glsl_type::mat4_type, 4);
+      glsl_type::get_array_instance(state->symbols, glsl_type::mat4_type,
+                                   state->Const.MaxTextureCoords);
 
    add_variable("gl_TextureMatrix", ir_var_uniform, -1, mat4_array_type,
-               instructions, symtab);
+               instructions, state->symbols);
 
    /* FINISHME: Add support for gl_DepthRangeParameters */
    /* FINISHME: Add support for gl_ClipPlane[] */
@@ -129,11 +132,11 @@ generate_110_uniforms(exec_list *instructions,
     * FINISHME: at least 8, so hard-code 8 for now.
     */
    const glsl_type *const light_source_array_type =
-      glsl_type::get_array_instance(symtab,
-                                   symtab->get_type("gl_LightSourceParameters"), 8);
+      glsl_type::get_array_instance(state->symbols,
+                                   state->symbols->get_type("gl_LightSourceParameters"), 8);
 
    add_variable("gl_LightSource", ir_var_uniform, -1, light_source_array_type,
-               instructions, symtab);
+               instructions, state->symbols);
 
    /* FINISHME: Add support for gl_LightModel */
    /* FINISHME: Add support for gl_FrontLightProduct[], gl_BackLightProduct[] */
@@ -157,7 +160,7 @@ generate_110_vs_variables(exec_list *instructions,
       add_builtin_variable(& builtin_110_deprecated_vs_variables[i],
                           instructions, state->symbols);
    }
-   generate_110_uniforms(instructions, state->symbols);
+   generate_110_uniforms(instructions, state);
 
    /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec:
     *
@@ -247,7 +250,7 @@ generate_110_fs_variables(exec_list *instructions,
       add_builtin_variable(& builtin_110_deprecated_fs_variables[i],
                           instructions, state->symbols);
    }
-   generate_110_uniforms(instructions, state->symbols);
+   generate_110_uniforms(instructions, state);
 
    /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec:
     *
index fa63853b47687e755937d9597e467c910fc19989..c833c9cde6d3b1b539431db8143cf9ccda287ebe 100644 (file)
@@ -128,6 +128,7 @@ compile_shader(struct gl_shader *shader)
    state->ARB_texture_rectangle_enable = true;
 
    state->Const.MaxDrawBuffers = 2;
+   state->Const.MaxTextureCoords = 4;
 
    const char *source = shader->Source;
    state->error = preprocess(state, &source, &state->info_log);
index 1e186354c588b0121c05b7bb46d28a9b6c3d95d9..14abf602af2d40ef3e0578d275a67ee9c89e498f 100644 (file)
@@ -1710,6 +1710,7 @@ _mesa_glsl_compile_shader(GLcontext *ctx, struct gl_shader *shader)
    state->ARB_texture_rectangle_enable = true;
 
    state->Const.MaxDrawBuffers = ctx->Const.MaxDrawBuffers;
+   state->Const.MaxTextureCoords = ctx->Const.MaxTextureCoordUnits;
 
    const char *source = shader->Source;
    state->error = preprocess(state, &source, &state->info_log);