glsl2: Use Elements macro
authorIan Romanick <ian.d.romanick@intel.com>
Fri, 16 Jul 2010 22:31:23 +0000 (15:31 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Mon, 19 Jul 2010 21:50:43 +0000 (14:50 -0700)
src/glsl/builtin_function.cpp
src/glsl/builtins/tools/generate_builtins.pl

index 75e058c41c83a3dd9fc97e5e9e24f0f198f0de19..fbb2638fc936ecd157c61407453779358016911b 100644 (file)
@@ -4748,6 +4748,10 @@ static const char *functions_for_EXT_texture_array_fs [] = {
    builtins_EXT_texture_array_fs_textures,
 };
 
+#ifndef Elements
+#define Elements(x) (sizeof(x)/sizeof(*(x)))
+#endif
+
 void
 _mesa_glsl_initialize_functions(exec_list *instructions,
                                struct _mesa_glsl_parse_state *state)
@@ -4755,46 +4759,46 @@ _mesa_glsl_initialize_functions(exec_list *instructions,
    if (state->language_version >= 110)
       read_builtins(state, instructions,
                     functions_for_110,
-                    sizeof(functions_for_110) / sizeof(const char *));
+                    Elements(functions_for_110));
 
    if (state->target == fragment_shader && state->language_version >= 110)
       read_builtins(state, instructions,
                     functions_for_110_fs,
-                    sizeof(functions_for_110_fs) / sizeof(const char *));
+                    Elements(functions_for_110_fs));
 
    if (state->target == vertex_shader && state->language_version >= 110)
       read_builtins(state, instructions,
                     functions_for_110_vs,
-                    sizeof(functions_for_110_vs) / sizeof(const char *));
+                    Elements(functions_for_110_vs));
 
    if (state->language_version >= 120)
       read_builtins(state, instructions,
                     functions_for_120,
-                    sizeof(functions_for_120) / sizeof(const char *));
+                    Elements(functions_for_120));
 
    if (state->language_version >= 130)
       read_builtins(state, instructions,
                     functions_for_130,
-                    sizeof(functions_for_130) / sizeof(const char *));
+                    Elements(functions_for_130));
 
    if (state->target == fragment_shader && state->language_version >= 130)
       read_builtins(state, instructions,
                     functions_for_130_fs,
-                    sizeof(functions_for_130_fs) / sizeof(const char *));
+                    Elements(functions_for_130_fs));
 
    if (state->ARB_texture_rectangle_enable)
       read_builtins(state, instructions,
                     functions_for_ARB_texture_rectangle,
-                    sizeof(functions_for_ARB_texture_rectangle) / sizeof(const char *));
+                    Elements(functions_for_ARB_texture_rectangle));
 
    if (state->EXT_texture_array_enable)
       read_builtins(state, instructions,
                     functions_for_EXT_texture_array,
-                    sizeof(functions_for_EXT_texture_array) / sizeof(const char *));
+                    Elements(functions_for_EXT_texture_array));
 
    if (state->target == fragment_shader && state->EXT_texture_array_enable)
       read_builtins(state, instructions,
                     functions_for_EXT_texture_array_fs,
-                    sizeof(functions_for_EXT_texture_array_fs) / sizeof(const char *));
+                    Elements(functions_for_EXT_texture_array_fs));
 
 }
index 8b640ab8ff97bcb844d5b9aa5d55637dff54c8e2..a0b5c1f421c5df135099176b954dcbce68927ea9 100755 (executable)
@@ -91,6 +91,10 @@ foreach $version (@versions) {
 }
 
 print << 'EOF';
+#ifndef Elements
+#define Elements(x) (sizeof(x)/sizeof(*(x)))
+#endif
+
 void
 _mesa_glsl_initialize_functions(exec_list *instructions,
                                struct _mesa_glsl_parse_state *state)
@@ -116,8 +120,7 @@ foreach $version_xs (@versions) {
    print "   if ($check)\n";
    print "      read_builtins(state, instructions,\n";
    print "                    functions_for_$version_xs,\n";
-   print "                    sizeof(functions_for_$version_xs) / ";
-   print "sizeof(const char *));\n\n"
+   print "                    Elements(functions_for_$version_xs));\n\n"
 }
 
 print "}\n";