2 * Copyright © 2009 VMware, Inc.
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
29 * @file glsl-arb-fragment-coord-conventions.c
31 * Test ARB_fragment_coord_conventions extension.
34 #include "piglit-util-gl.h"
36 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config
.supports_gl_compat_version
= 20;
40 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
42 PIGLIT_GL_TEST_CONFIG_END
45 /* Test size / region */
50 static const float black
[4] = {0.0, 0.0, 0.0, 0.0};
51 static const float red
[4] = {1.0, 0.0, 0.0, 0.0};
52 static const float green
[4] = {0.0, 1.0, 0.0, 0.0};
53 static const float yellow
[4] = {1.0, 1.0, 0.0, 0.0};
54 static const float gray25_l
[4] = {0.25, 0.25, 0.0, 0.0};
55 static const float gray25_r
[4] = {0.25, 0.25, 1.0, 0.0};
56 static const float gray75_l
[4] = {0.75, 0.75, 0.5, 0.0};
57 static const float gray75_r
[4] = {0.75, 0.75, 1.0, 0.0};
62 * For each of the various pixel center/origin layout qualifier modes
63 * draw a full-window quad where the fragment color is a function of
64 * the fragment coordinate.
71 GLboolean pass
= GL_TRUE
;
73 if (piglit_width
< WIDTH
|| piglit_height
< HEIGHT
) {
74 printf("window is too small.\n");
78 piglit_ortho_projection(WIDTH
, HEIGHT
, GL_FALSE
);
80 vs
= piglit_compile_shader(GL_VERTEX_SHADER
, "shaders/glsl-mvp.vert");
82 /* No layout: test regular gl_FragCoord */
83 if (piglit_automatic
|| test
== 0)
85 const char *fragtext
=
88 " gl_FragColor = gl_FragCoord * 0.01; \n"
91 printf("Regular gl_FragCoord\n");
92 fs
= piglit_compile_shader_text(GL_FRAGMENT_SHADER
, fragtext
);
93 prog
= piglit_link_simple_program(vs
, fs
);
96 glClear(GL_COLOR_BUFFER_BIT
);
97 glViewport(0, 0, WIDTH
, HEIGHT
);
99 piglit_draw_rect(0, 0, WIDTH
, HEIGHT
);
101 /* lower-left corner */
102 pass
= piglit_probe_pixel_rgb(0, 0, black
) && pass
;
104 /* upper-right corner */
105 pass
= piglit_probe_pixel_rgb(WIDTH
- 1, HEIGHT
- 1, yellow
) && pass
;
108 /* No layout, test pixel center is half integer */
109 if (piglit_automatic
|| test
== 1)
111 const char *fragtext
=
112 "#extension GL_ARB_fragment_coord_conventions: enable \n"
115 " gl_FragColor = fract(gl_FragCoord) + 0.25; \n"
116 " gl_FragColor.z = (gl_FragCoord.x + gl_FragCoord.y) * 0.5; \n"
119 printf("Pixel center half integer\n");
120 fs
= piglit_compile_shader_text(GL_FRAGMENT_SHADER
, fragtext
);
121 prog
= piglit_link_simple_program(vs
, fs
);
124 glClear(GL_COLOR_BUFFER_BIT
);
125 glViewport(0, 0, WIDTH
, HEIGHT
);
127 piglit_draw_rect(0, 0, WIDTH
, HEIGHT
);
129 /* lower-left corner */
130 pass
= piglit_probe_pixel_rgb(0, 0, gray75_l
) && pass
;
132 /* upper-right corner */
133 pass
= piglit_probe_pixel_rgb(WIDTH
- 1, HEIGHT
- 1, gray75_r
) && pass
;
136 /* Pixel center integer */
137 if (piglit_automatic
|| test
== 2)
139 const char *fragtext
=
140 "#extension GL_ARB_fragment_coord_conventions: enable \n"
141 "layout(pixel_center_integer) varying vec4 gl_FragCoord; \n"
144 " gl_FragColor = fract(gl_FragCoord) + 0.25; \n"
145 " gl_FragColor.z = (gl_FragCoord.x + gl_FragCoord.y) * 0.5; \n"
148 printf("Pixel center integer\n");
149 fs
= piglit_compile_shader_text(GL_FRAGMENT_SHADER
, fragtext
);
150 prog
= piglit_link_simple_program(vs
, fs
);
153 glClear(GL_COLOR_BUFFER_BIT
);
154 glViewport(0, 0, WIDTH
, HEIGHT
);
156 piglit_draw_rect(0, 0, WIDTH
, HEIGHT
);
158 /* lower-left corner */
159 pass
= piglit_probe_pixel_rgb(0, 0, gray25_l
) && pass
;
161 /* upper-right corner */
162 pass
= piglit_probe_pixel_rgb(WIDTH
- 1, HEIGHT
- 1, gray25_r
) && pass
;
165 /* Pixel origin upper left */
166 if (piglit_automatic
|| test
== 3)
168 const char *fragtext
=
169 "#extension GL_ARB_fragment_coord_conventions: enable \n"
170 "layout(origin_upper_left) varying vec4 gl_FragCoord; \n"
173 " gl_FragColor = gl_FragCoord * 0.01; \n"
174 " gl_FragColor.z = 0.0; \n"
176 int y0
= piglit_height
- HEIGHT
;
178 printf("Pixel origin upper left\n");
179 fs
= piglit_compile_shader_text(GL_FRAGMENT_SHADER
, fragtext
);
180 prog
= piglit_link_simple_program(vs
, fs
);
183 glClear(GL_COLOR_BUFFER_BIT
);
184 glViewport(0, y0
, WIDTH
, HEIGHT
);
186 piglit_draw_rect(0, 0, WIDTH
, HEIGHT
);
188 /* lower-left corner */
189 pass
= piglit_probe_pixel_rgb(0, y0
, green
) && pass
;
191 /* upper-right corner */
192 pass
= piglit_probe_pixel_rgb(WIDTH
- 1, y0
+ HEIGHT
- 1, red
) && pass
;
195 /* Pixel origin upper left and pixel center integer */
196 if (piglit_automatic
|| test
== 4)
198 static const float color1
[4] = {0.125, 0.3725, 0.0, 0.0};
199 static const float color2
[4] = {0.3725, 0.125, 0.0, 0.0};
200 const char *fragtext
=
201 "#extension GL_ARB_fragment_coord_conventions: enable \n"
202 "layout(origin_upper_left, pixel_center_integer) varying vec4 gl_FragCoord; \n"
205 " gl_FragColor = gl_FragCoord * 0.0025 + 0.125; \n"
206 " gl_FragColor.z = 0.0; \n"
208 int y0
= piglit_height
- HEIGHT
;
210 printf("Pixel origin upper left and pixel center integer\n");
211 fs
= piglit_compile_shader_text(GL_FRAGMENT_SHADER
, fragtext
);
212 prog
= piglit_link_simple_program(vs
, fs
);
215 glClear(GL_COLOR_BUFFER_BIT
);
216 glViewport(0, y0
, WIDTH
, HEIGHT
);
218 piglit_draw_rect(0, 0, WIDTH
, HEIGHT
);
220 /* lower-left corner */
221 pass
= piglit_probe_pixel_rgb(0, y0
, color1
) && pass
;
223 /* upper-right corner */
224 pass
= piglit_probe_pixel_rgb(WIDTH
- 1, y0
+ HEIGHT
- 1, color2
) && pass
;
227 piglit_present_results();
229 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
232 static void key_func(unsigned char key
, int x
, int y
)
236 test
= (test
+ 1) % 5;
240 piglit_escape_exit_key(key
, x
, y
);
243 void piglit_init(int argc
, char **argv
)
245 piglit_require_extension("GL_ARB_fragment_coord_conventions");
247 if (!piglit_automatic
) {
248 printf("Press t to switch between subtests.\n");
249 piglit_set_keyboard_func(key_func
);