arb_program_interface_query: set vs_input2[1][0] as valid name
[piglit.git] / tests / spec / gl-3.0 / api / getfragdatalocation.c
blob0c91f00078bdfc12f73d8e707ce7e4711aec7e0c
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
12 * Software.
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
20 * IN THE SOFTWARE.
23 /**
24 * \file getfragdatalocation.c
26 * \author Ian Romanick
28 #include "piglit-util-gl.h"
30 PIGLIT_GL_TEST_CONFIG_BEGIN
32 config.supports_gl_compat_version = 10;
33 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
34 config.khr_no_error_support = PIGLIT_NO_ERRORS;
36 PIGLIT_GL_TEST_CONFIG_END
38 static const char *vs_text =
39 "#version 130\n"
40 "in vec4 vertex;\n"
41 "void main() { gl_Position = vertex; }\n"
44 static const char *fs_text =
45 "#version 130\n"
46 "out vec4 v;\n"
47 "out vec4 a[2];\n"
48 "void main() {\n"
49 " v = vec4(0.0);\n"
50 " a[0] = vec4(1.0);\n"
51 " a[1] = vec4(2.0);\n"
52 "}\n"
55 static const char *fs_text2 =
56 "#version 130\n"
57 "void main() {\n"
58 " gl_FragColor = vec4(0.0);\n"
59 "}\n"
62 static const char *fs_text3 =
63 "#version 130\n"
64 "void main() {\n"
65 " gl_FragData[0] = vec4(0.0);\n"
66 "}\n"
69 enum piglit_result
70 piglit_display(void)
72 return PIGLIT_FAIL;
75 void piglit_init(int argc, char **argv)
77 GLint max_draw_buffers;
78 GLuint prog;
79 GLuint vs;
80 GLuint fs, fs2, fs3;
81 GLint loc;
83 piglit_require_gl_version(30);
85 /* This test needs some number of draw buffers, so make sure the
86 * implementation isn't broken. This enables the test to generate a
87 * useful failure message.
89 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &max_draw_buffers);
90 if (max_draw_buffers < 8) {
91 fprintf(stderr,
92 "OpenGL 3.0 requires GL_MAX_DRAW_BUFFERS >= 8. "
93 "Only got %d!\n",
94 max_draw_buffers);
95 piglit_report_result(PIGLIT_FAIL);
98 prog = glCreateProgram();
99 vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_text);
100 fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_text);
101 fs2 = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_text2);
102 fs3 = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_text3);
103 glAttachShader(prog, vs);
104 glAttachShader(prog, fs);
105 if (!piglit_check_gl_error(GL_NO_ERROR))
106 piglit_report_result(PIGLIT_FAIL);
108 if (!piglit_khr_no_error) {
109 /* Page 237 (page 253 of the PDF) of the OpenGL 3.0 spec says:
111 * "If program has not been successfully linked, the error
112 * INVALID OPERATION is generated. If name is not a varying
113 * out variable, or if an error occurs, -1 will be
114 * returned."
116 printf("Querying location before linking...\n");
117 loc = glGetFragDataLocation(prog, "v");
118 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
119 piglit_report_result(PIGLIT_FAIL);
121 if (loc != -1) {
122 fprintf(stderr, "Expected location = -1, got %d\n", loc);
123 piglit_report_result(PIGLIT_FAIL);
127 glLinkProgram(prog);
128 if (!piglit_check_gl_error(GL_NO_ERROR))
129 piglit_report_result(PIGLIT_FAIL);
131 if (!piglit_link_check_status(prog)) {
132 piglit_report_result(PIGLIT_FAIL);
135 printf("Querying location of nonexistent variable...\n");
136 loc = glGetFragDataLocation(prog, "waldo");
137 if (!piglit_check_gl_error(GL_NO_ERROR))
138 piglit_report_result(PIGLIT_FAIL);
140 if (loc != -1) {
141 fprintf(stderr, "Expected location = -1, got %d\n", loc);
142 piglit_report_result(PIGLIT_FAIL);
145 /* Page 236 (page 252 of the PDF) of the OpenGL 3.0 spec says:
147 * "BindFragDataLocation has no effect until the program is
148 * linked. In particular, it doesn’t modify the bindings of
149 * varying out variables in a program that has already been
150 * linked."
152 glBindFragDataLocation(prog, 0, "v");
153 glBindFragDataLocation(prog, 1, "a");
154 glLinkProgram(prog);
155 if (!piglit_check_gl_error(GL_NO_ERROR))
156 piglit_report_result(PIGLIT_FAIL);
158 if (!piglit_link_check_status(prog)) {
159 piglit_report_result(PIGLIT_FAIL);
162 printf("Querying locations after binding and linking...\n");
163 loc = glGetFragDataLocation(prog, "v");
164 if (!piglit_check_gl_error(GL_NO_ERROR))
165 piglit_report_result(PIGLIT_FAIL);
167 if (loc != 0) {
168 fprintf(stderr, "Expected location = 0, got %d\n", loc);
169 piglit_report_result(PIGLIT_FAIL);
172 loc = glGetFragDataLocation(prog, "a");
173 if (!piglit_check_gl_error(GL_NO_ERROR))
174 piglit_report_result(PIGLIT_FAIL);
176 if (loc != 1) {
177 fprintf(stderr, "Expected location = 1, got %d\n", loc);
178 piglit_report_result(PIGLIT_FAIL);
181 printf("Querying locations after just binding...\n");
182 glBindFragDataLocation(prog, 2, "v");
183 glBindFragDataLocation(prog, 0, "a");
184 if (!piglit_check_gl_error(GL_NO_ERROR))
185 piglit_report_result(PIGLIT_FAIL);
187 loc = glGetFragDataLocation(prog, "v");
188 if (!piglit_check_gl_error(GL_NO_ERROR))
189 piglit_report_result(PIGLIT_FAIL);
191 if (loc != 0) {
192 fprintf(stderr, "Expected location = 0, got %d\n", loc);
193 piglit_report_result(PIGLIT_FAIL);
196 loc = glGetFragDataLocation(prog, "a");
197 if (!piglit_check_gl_error(GL_NO_ERROR))
198 piglit_report_result(PIGLIT_FAIL);
200 if (loc != 1) {
201 fprintf(stderr, "Expected location = 1, got %d\n", loc);
202 piglit_report_result(PIGLIT_FAIL);
205 printf("Querying location of gl_FragColor...\n");
206 glDetachShader(prog, fs);
207 glAttachShader(prog, fs2);
208 glLinkProgram(prog);
209 if (!piglit_link_check_status(prog)) {
210 piglit_report_result(PIGLIT_FAIL);
213 loc = glGetFragDataLocation(prog, "gl_FragColor");
214 if (!piglit_check_gl_error(GL_NO_ERROR))
215 piglit_report_result(PIGLIT_FAIL);
217 if (loc != -1) {
218 fprintf(stderr, "Expected location = -1, got %d\n", loc);
219 piglit_report_result(PIGLIT_FAIL);
222 printf("Querying location of gl_FragData[0]...\n");
223 glDetachShader(prog, fs2);
224 glAttachShader(prog, fs3);
225 glLinkProgram(prog);
226 if (!piglit_link_check_status(prog)) {
227 piglit_report_result(PIGLIT_FAIL);
230 loc = glGetFragDataLocation(prog, "gl_FragData[0]");
231 if (!piglit_check_gl_error(GL_NO_ERROR))
232 piglit_report_result(PIGLIT_FAIL);
234 if (loc != -1) {
235 fprintf(stderr, "Expected location = -1, got %d\n", loc);
236 piglit_report_result(PIGLIT_FAIL);
239 piglit_report_result(PIGLIT_PASS);