1 /* Copyright © 2011 Intel Corporation
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * \file bindfragdata-nonexistent-variable.c
25 * Test the behavior of glBindFragDataLocation on a non-existent variable
27 * \author Ian Romanick
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
33 config
.supports_gl_compat_version
= 10;
34 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
35 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
37 PIGLIT_GL_TEST_CONFIG_END
39 static const char *vs_text
=
42 "void main() { gl_Position = vertex; }\n"
45 static const char *fs_text
=
59 void piglit_init(int argc
, char **argv
)
61 GLint max_draw_buffers
;
67 piglit_require_gl_version(30);
69 /* This test needs some number of draw buffers, so make sure the
70 * implementation isn't broken. This enables the test to generate a
71 * useful failure message.
73 glGetIntegerv(GL_MAX_DRAW_BUFFERS
, &max_draw_buffers
);
74 if (max_draw_buffers
< 8) {
76 "OpenGL 3.0 requires GL_MAX_DRAW_BUFFERS >= 8. "
79 piglit_report_result(PIGLIT_FAIL
);
82 prog
= glCreateProgram();
83 vs
= piglit_compile_shader_text(GL_VERTEX_SHADER
, vs_text
);
84 fs
= piglit_compile_shader_text(GL_FRAGMENT_SHADER
, fs_text
);
85 if (!piglit_check_gl_error(GL_NO_ERROR
))
86 piglit_report_result(PIGLIT_FAIL
);
88 /* First, verify that the program will link without making any
89 * location assignments through the API.
91 printf("Basic test...\n");
93 glAttachShader(prog
, vs
);
94 glAttachShader(prog
, fs
);
96 if (!piglit_check_gl_error(GL_NO_ERROR
))
97 piglit_report_result(PIGLIT_FAIL
);
99 if (!piglit_link_check_status(prog
)) {
100 piglit_report_result(PIGLIT_FAIL
);
103 /* Page 237 (page 253 of the PDF) of the OpenGL 3.0 spec says:
105 * "Assigned bindings for variables that do not exist are
108 printf("Binding `unicorn' to a non-conflicting location...\n");
110 glBindFragDataLocation(prog
, 0, "v");
111 if (!piglit_check_gl_error(GL_NO_ERROR
))
112 piglit_report_result(PIGLIT_FAIL
);
113 glBindFragDataLocation(prog
, 1, "unicorn");
114 if (!piglit_check_gl_error(GL_NO_ERROR
))
115 piglit_report_result(PIGLIT_FAIL
);
118 if (!piglit_check_gl_error(GL_NO_ERROR
))
119 piglit_report_result(PIGLIT_FAIL
);
121 if (!piglit_link_check_status(prog
)) {
123 "Linking failed when it should have been "
125 piglit_report_result(PIGLIT_FAIL
);
128 loc
= glGetFragDataLocation(prog
, "unicorn");
129 if (!piglit_check_gl_error(GL_NO_ERROR
))
130 piglit_report_result(PIGLIT_FAIL
);
133 fprintf(stderr
, "Expected location = -1, got %d\n", loc
);
134 piglit_report_result(PIGLIT_FAIL
);
137 printf("Binding `unicorn' to a conflicting location...\n");
139 glBindFragDataLocation(prog
, 0, "v");
140 if (!piglit_check_gl_error(GL_NO_ERROR
))
141 piglit_report_result(PIGLIT_FAIL
);
142 glBindFragDataLocation(prog
, 0, "unicorn");
143 if (!piglit_check_gl_error(GL_NO_ERROR
))
144 piglit_report_result(PIGLIT_FAIL
);
147 if (!piglit_check_gl_error(GL_NO_ERROR
))
148 piglit_report_result(PIGLIT_FAIL
);
150 if (!piglit_link_check_status(prog
)) {
152 "Linking failed when it should have been "
154 piglit_report_result(PIGLIT_FAIL
);
157 loc
= glGetFragDataLocation(prog
, "unicorn");
158 if (!piglit_check_gl_error(GL_NO_ERROR
))
159 piglit_report_result(PIGLIT_FAIL
);
162 fprintf(stderr
, "Expected location = -1, got %d\n", loc
);
163 piglit_report_result(PIGLIT_FAIL
);
166 piglit_report_result(PIGLIT_PASS
);