2 * Copyright © 2014 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * \file array-elements.c
27 * Tests that array elements get sequential locations.
29 * The GL_ARB_explicit_uniform_location spec says:
30 * "Individual elements of a uniform array are assigned consecutive
31 * locations with the first element taking location <location>."
33 #include "piglit-util-gl.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config
.supports_gl_compat_version
= 30;
38 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
;
39 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
41 PIGLIT_GL_TEST_CONFIG_END
49 static const char vs_text
[] =
52 "gl_Position = vertex;\n"
55 static const char fs_text
[] =
57 "#extension GL_ARB_explicit_attrib_location: require\n"
58 "#extension GL_ARB_explicit_uniform_location: require\n"
59 "#define ARRAY_SIZE 16\n"
60 "layout(location = 1) uniform float r;\n"
61 "layout(location = 2) uniform float g;\n"
62 "layout(location = 3) uniform float a[ARRAY_SIZE];\n"
63 "layout(location = 19) uniform float b;\n"
65 "gl_FragColor = vec4(r, g, b, a[ARRAY_SIZE - 1]);\n"
69 piglit_init(int argc
, char **argv
)
73 piglit_require_extension("GL_ARB_explicit_attrib_location");
74 piglit_require_extension("GL_ARB_explicit_uniform_location");
76 prog
= piglit_build_simple_program(vs_text
, fs_text
);
78 /* verify that locations are sequential */
79 for (i
= 0; i
< 16; i
++) {
81 if (asprintf(&element
, "a[%d]", i
) == -1)
82 piglit_report_result(PIGLIT_FAIL
);
84 if (glGetUniformLocation(prog
, element
) != 3 + i
)
85 piglit_report_result(PIGLIT_FAIL
);
90 glDeleteProgram(prog
);
91 piglit_report_result(PIGLIT_PASS
);