glsl2: Add definitions of the builtin constants present in GLSL 1.10.
authorEric Anholt <eric@anholt.net>
Tue, 20 Jul 2010 21:03:35 +0000 (14:03 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 20 Jul 2010 21:03:35 +0000 (14:03 -0700)
Fixes:
glsl1-built-in constants

src/glsl/glsl_parser_extras.h
src/glsl/ir_variable.cpp
src/glsl/main.cpp
src/mesa/shader/ir_to_mesa.cpp

index 4b28ae118df1bab03647ab3d3055e2d47b8be68f..fed6e8c823f030cb5eb9e810cc962c8e61453bee 100644 (file)
@@ -49,8 +49,21 @@ struct _mesa_glsl_parse_state {
     * \sa struct gl_constants (in mtypes.h)
     */
    struct {
-      unsigned MaxDrawBuffers;
+      /* 1.10 */
+      unsigned MaxLights;
+      unsigned MaxClipPlanes;
+      unsigned MaxTextureUnits;
       unsigned MaxTextureCoords;
+      unsigned MaxVertexAttribs;
+      unsigned MaxVertexUniformComponents;
+      unsigned MaxVaryingFloats;
+      unsigned MaxVertexTextureImageUnits;
+      unsigned MaxCombinedTextureImageUnits;
+      unsigned MaxTextureImageUnits;
+      unsigned MaxFragmentUniformComponents;
+
+      /* ARB_draw_buffers */
+      unsigned MaxDrawBuffers;
    } Const;
 
    /**
index a0b66b777028f76408f695a6de3230811953b511..4593c1811278c2d23d024ad1e5b9137a3657d39b 100644 (file)
@@ -93,6 +93,16 @@ add_builtin_variable(const builtin_variable *proto, exec_list *instructions,
                symtab);
 }
 
+static void
+add_builtin_constant(exec_list *instructions,
+                    struct _mesa_glsl_parse_state *state,
+                    const char *name, int value)
+{
+   ir_variable *const var = add_variable(name, ir_var_auto,
+                                        -1, glsl_type::int_type,
+                                        instructions, state->symbols);
+   var->constant_value = new(var) ir_constant(value);
+}
 
 static void
 generate_110_uniforms(exec_list *instructions,
@@ -105,12 +115,28 @@ generate_110_uniforms(exec_list *instructions,
                           instructions, state->symbols);
    }
 
-   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));
-
+   add_builtin_constant(instructions, state, "gl_MaxLights",
+                       state->Const.MaxLights);
+   add_builtin_constant(instructions, state, "gl_MaxClipPlanes",
+                       state->Const.MaxClipPlanes);
+   add_builtin_constant(instructions, state, "gl_MaxTextureUnits",
+                       state->Const.MaxTextureUnits);
+   add_builtin_constant(instructions, state, "gl_MaxTextureCoords",
+                       state->Const.MaxTextureCoords);
+   add_builtin_constant(instructions, state, "gl_MaxVertexAttribs",
+                       state->Const.MaxVertexAttribs);
+   add_builtin_constant(instructions, state, "gl_MaxVertexUniformComponents",
+                       state->Const.MaxVertexUniformComponents);
+   add_builtin_constant(instructions, state, "gl_MaxVaryingFloats",
+                       state->Const.MaxVaryingFloats);
+   add_builtin_constant(instructions, state, "gl_MaxVertexTextureImageUnits",
+                       state->Const.MaxVertexTextureImageUnits);
+   add_builtin_constant(instructions, state, "gl_MaxCombinedTextureImageUnits",
+                       state->Const.MaxCombinedTextureImageUnits);
+   add_builtin_constant(instructions, state, "gl_MaxTextureImageUnits",
+                       state->Const.MaxTextureImageUnits);
+   add_builtin_constant(instructions, state, "gl_MaxFragmentUniformComponents",
+                       state->Const.MaxFragmentUniformComponents);
 
    const glsl_type *const mat4_array_type =
       glsl_type::get_array_instance(state->symbols, glsl_type::mat4_type,
index 3ae0eebab3c39d79058216a6cbecea3e07188941..6b1a01c7046892de6a03c213e9d17e6bad1ba1d7 100644 (file)
@@ -148,9 +148,26 @@ compile_shader(struct gl_shader *shader)
 
    memset(&ext, 0, sizeof(ext));
    state->extensions = &ext;
-   state->Const.MaxDrawBuffers = 2;
+   /* 1.10 minimums. */
+   state->Const.MaxLights = 8;
+   state->Const.MaxClipPlanes = 8;
+   state->Const.MaxTextureUnits = 2;
+
+   /* More than the 1.10 minimum to appease parser tests taken from
+    * apps that (hopefully) already checked the number of coords.
+    */
    state->Const.MaxTextureCoords = 4;
 
+   state->Const.MaxVertexAttribs = 16;
+   state->Const.MaxVertexUniformComponents = 512;
+   state->Const.MaxVaryingFloats = 32;
+   state->Const.MaxVertexTextureImageUnits = 0;
+   state->Const.MaxCombinedTextureImageUnits = 2;
+   state->Const.MaxTextureImageUnits = 2;
+   state->Const.MaxFragmentUniformComponents = 64;
+
+   state->Const.MaxDrawBuffers = 2;
+
    const char *source = shader->Source;
    state->error = preprocess(state, &source, &state->info_log, &ext);
 
index 848fb0fb6c2d9085f672b57debfe8e7273880310..5803960d4443cb7df594696b99314b762516f92b 100644 (file)
@@ -2170,8 +2170,20 @@ _mesa_glsl_compile_shader(GLcontext *ctx, struct gl_shader *shader)
    state->ARB_texture_rectangle_enable = true;
 
    state->extensions = &ctx->Extensions;
-   state->Const.MaxDrawBuffers = ctx->Const.MaxDrawBuffers;
+
+   state->Const.MaxLights = ctx->Const.MaxLights;
+   state->Const.MaxClipPlanes = ctx->Const.MaxClipPlanes;
+   state->Const.MaxTextureUnits = ctx->Const.MaxTextureUnits;
    state->Const.MaxTextureCoords = ctx->Const.MaxTextureCoordUnits;
+   state->Const.MaxVertexAttribs = ctx->Const.VertexProgram.MaxAttribs;
+   state->Const.MaxVertexUniformComponents = ctx->Const.VertexProgram.MaxUniformComponents;
+   state->Const.MaxVaryingFloats = ctx->Const.MaxVarying * 4;
+   state->Const.MaxVertexTextureImageUnits = ctx->Const.MaxVertexTextureImageUnits;
+   state->Const.MaxCombinedTextureImageUnits = ctx->Const.MaxCombinedTextureImageUnits;
+   state->Const.MaxTextureImageUnits = ctx->Const.MaxTextureImageUnits;
+   state->Const.MaxFragmentUniformComponents = ctx->Const.FragmentProgram.MaxUniformComponents;
+
+   state->Const.MaxDrawBuffers = ctx->Const.MaxDrawBuffers;
 
    const char *source = shader->Source;
    state->error = preprocess(state, &source, &state->info_log,