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 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
=
41 "void main() { gl_Position = vertex; }\n"
44 static const char *fs_text
=
50 " a[0] = vec4(1.0);\n"
51 " a[1] = vec4(2.0);\n"
55 static const char *fs_text2
=
58 " gl_FragColor = vec4(0.0);\n"
62 static const char *fs_text3
=
65 " gl_FragData[0] = vec4(0.0);\n"
75 void piglit_init(int argc
, char **argv
)
77 GLint max_draw_buffers
;
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) {
92 "OpenGL 3.0 requires GL_MAX_DRAW_BUFFERS >= 8. "
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
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
);
122 fprintf(stderr
, "Expected location = -1, got %d\n", loc
);
123 piglit_report_result(PIGLIT_FAIL
);
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
);
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
152 glBindFragDataLocation(prog
, 0, "v");
153 glBindFragDataLocation(prog
, 1, "a");
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
235 fprintf(stderr
, "Expected location = -1, got %d\n", loc
);
236 piglit_report_result(PIGLIT_FAIL
);
239 piglit_report_result(PIGLIT_PASS
);