diff --git a/tests/all.tests b/tests/all.tests index 2e0b225..7e18b29 100644 --- a/tests/all.tests +++ b/tests/all.tests @@ -640,6 +640,7 @@ add_plain_test(shaders, 'glsl-link-initializer-04') add_plain_test(shaders, 'glsl-link-initializer-05') add_plain_test(shaders, 'glsl-link-initializer-06') add_plain_test(shaders, 'glsl-link-invariant-01') +add_plain_test(shaders, 'glsl-link-centroid-01') add_plain_test(shaders, 'glsl-link-struct-array') add_shader_generic(shaders, 'glsl-link-varying-TexCoord') add_shader_generic(shaders, 'glsl-override-builtin') diff --git a/tests/shaders/CMakeLists.txt b/tests/shaders/CMakeLists.txt index b5173fa..637a263 100644 --- a/tests/shaders/CMakeLists.txt +++ b/tests/shaders/CMakeLists.txt @@ -117,6 +117,7 @@ add_executable (glsl-link-initializer-04 glsl-link-initializer-04.c) add_executable (glsl-link-initializer-05 glsl-link-initializer-05.c) add_executable (glsl-link-initializer-06 glsl-link-initializer-06.c) add_executable (glsl-link-invariant-01 glsl-link-invariant-01.c) +add_executable (glsl-link-centroid-01 glsl-link-centroid-01.c) add_executable (glsl-link-struct-array glsl-link-struct-array.c) add_executable (gpu_shader4_attribs gpu_shader4_attribs.c) add_executable (vp-address-01 vp-address-01.c) diff --git a/tests/shaders/glsl-link-centroid-01.c b/tests/shaders/glsl-link-centroid-01.c new file mode 100644 index 0000000..b254d03 --- /dev/null +++ b/tests/shaders/glsl-link-centroid-01.c @@ -0,0 +1,111 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/** + * \file glsl-link-centroid-01.c + * C file derived from glsl-link-invariant-01.c + * + * Negative test for inconsistent centroid qualifier usage between vertex + * shaders. + * + * Both vertex shaders involved in this test have a varying float variable + * with the same name. But the first shader declares it with the centroid + * qualifier while the second not. + * The test verifies that linking the 2 shaders together results in an error, + * according to GLSL 1.20 section 4.3.6: + * The type and presence of the centroid and invariant qualifiers of varying + * variables with the same name declared in linked vertex and fragments shaders + * must match, otherwise the link command will fail. + * + * \author Gordon Jin + */ + +#include "piglit-util.h" + +int piglit_width = 100, piglit_height = 100; +int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE; + +enum piglit_result +piglit_display(void) +{ + return PIGLIT_FAILURE; +} + +/** + * Don't use piglit_link_check_status because it will log a message to stderr + * when the link fails. Since this test wants the link to fail, logging an + * error message will cause the test to be listed as "warn" instead of "pass". + */ +GLboolean +link_check_status(GLint prog) +{ + GLint ok; + + glGetProgramiv(prog, GL_LINK_STATUS, &ok); + if (!ok) { + GLchar *info; + GLint size; + + glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size); + info = malloc(size); + + glGetProgramInfoLog(prog, size, NULL, info); + printf("Failed to link: %s\n", info); + + free(info); + } + + return ok; +} + +void piglit_init(int argc, char **argv) +{ + GLint vert[2]; + GLint prog; + GLboolean ok; + + if (!GLEW_VERSION_2_0) { + printf("Requires OpenGL 2.0\n"); + piglit_report_result(PIGLIT_SKIP); + } + + vert[0] = + piglit_compile_shader(GL_VERTEX_SHADER, + "shaders/glsl-link-centroid-01a.vert"); + vert[1] = + piglit_compile_shader(GL_VERTEX_SHADER, + "shaders/glsl-link-centroid-01b.vert"); + prog = glCreateProgram(); + glAttachShader(prog, vert[0]); + glAttachShader(prog, vert[1]); + glLinkProgram(prog); + + ok = link_check_status(prog); + if (ok) + fprintf(stderr, + "Program should have failed linking, but " + "it was (incorrectly) successful.\n"); + + piglit_report_result((!ok) ? PIGLIT_SUCCESS : PIGLIT_FAILURE); +} + diff --git a/tests/shaders/glsl-link-centroid-01a.vert b/tests/shaders/glsl-link-centroid-01a.vert new file mode 100644 index 0000000..0e86fc5 --- /dev/null +++ b/tests/shaders/glsl-link-centroid-01a.vert @@ -0,0 +1,7 @@ +#version 120 +centroid varying float var; + +void main() +{ + gl_Position = gl_Vertex; +} diff --git a/tests/shaders/glsl-link-centroid-01b.vert b/tests/shaders/glsl-link-centroid-01b.vert new file mode 100644 index 0000000..680572a --- /dev/null +++ b/tests/shaders/glsl-link-centroid-01b.vert @@ -0,0 +1,6 @@ +#version 120 +varying float var; + +void myfunc() +{ +}