Add more structure constructor tests.
[piglit/hramrach.git] / tests / shaders / glsl-arb-fragment-coord-conventions.c
blobd3be2a461c12f4533234d67bebe7e0e54e63e897
1 /*
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
13 * Software.
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
21 * IN THE SOFTWARE.
23 * Author:
24 * Brian Paul
28 /**
29 * @file glsl-arb-fragment-coord-conventions.c
31 * Test ARB_fragment_coord_conventions extension.
34 #include "piglit-util.h"
36 int piglit_width = 100, piglit_height = 100;
37 int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
39 static const float black[4] = {0.0, 0.0, 0.0, 0.0};
40 static const float red[4] = {1.0, 0.0, 0.0, 0.0};
41 static const float green[4] = {0.0, 1.0, 0.0, 0.0};
42 static const float yellow[4] = {1.0, 1.0, 0.0, 0.0};
43 static const float gray25[4] = {0.25, 0.25, 0.0, 0.0};
44 static const float gray75[4] = {0.75, 0.75, 0.0, 0.0};
48 * For each of the various pixel center/origin layout qualifier modes
49 * draw a full-window quad where the fragment color is a function of
50 * the fragment coordinate.
52 enum piglit_result
53 piglit_display(void)
55 GLuint prog;
56 GLuint vs, fs;
57 GLboolean pass = GL_TRUE;
59 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
61 vs = piglit_compile_shader(GL_VERTEX_SHADER, "shaders/glsl-mvp.vert");
63 /* No layout: test regular gl_FragCoord */
65 const char *fragtext =
66 "void main(void) \n"
67 "{ \n"
68 " gl_FragColor = gl_FragCoord * 0.01; \n"
69 "} \n";
71 fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fragtext);
72 prog = piglit_link_simple_program(vs, fs);
73 glUseProgram(prog);
75 glClear(GL_COLOR_BUFFER_BIT);
77 piglit_draw_rect(0, 0, piglit_width, piglit_height);
79 /* lower-left corner */
80 pass = pass && piglit_probe_pixel_rgb(0, 0, black);
82 /* upper-right corner */
83 pass = pass && piglit_probe_pixel_rgb(99, 99, yellow);
86 /* No layout, test pixel center is half integer */
88 const char *fragtext =
89 "#extension GL_ARB_fragment_coord_conventions: enable \n"
90 "void main(void) \n"
91 "{ \n"
92 " gl_FragColor = fract(gl_FragCoord) + 0.25; \n"
93 " gl_FragColor.z = 0.0; \n"
94 "} \n";
96 fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fragtext);
97 prog = piglit_link_simple_program(vs, fs);
98 glUseProgram(prog);
100 glClear(GL_COLOR_BUFFER_BIT);
102 piglit_draw_rect(0, 0, piglit_width, piglit_height);
104 /* lower-left corner */
105 pass = pass && piglit_probe_pixel_rgb(0, 0, gray75);
107 /* upper-right corner */
108 pass = pass && piglit_probe_pixel_rgb(99, 99, gray75);
111 /* Pixel center integer */
113 const char *fragtext =
114 "#extension GL_ARB_fragment_coord_conventions: enable \n"
115 "layout(pixel_center_integer) varying vec4 gl_FragCoord; \n"
116 "void main(void) \n"
117 "{ \n"
118 " gl_FragColor = fract(gl_FragCoord) + 0.25; \n"
119 " gl_FragColor.z = 0.0; \n"
120 "} \n";
122 fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fragtext);
123 prog = piglit_link_simple_program(vs, fs);
124 glUseProgram(prog);
126 glClear(GL_COLOR_BUFFER_BIT);
128 piglit_draw_rect(0, 0, piglit_width, piglit_height);
130 /* lower-left corner */
131 pass = pass && piglit_probe_pixel_rgb(0, 0, gray25);
133 /* upper-right corner */
134 pass = pass && piglit_probe_pixel_rgb(99, 99, gray25);
137 /* Pixel origin upper left */
139 const char *fragtext =
140 "#extension GL_ARB_fragment_coord_conventions: enable \n"
141 "layout(origin_upper_left) varying vec4 gl_FragCoord; \n"
142 "void main(void) \n"
143 "{ \n"
144 " gl_FragColor = gl_FragCoord * 0.01; \n"
145 " gl_FragColor.z = 0.0; \n"
146 "} \n";
148 fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fragtext);
149 prog = piglit_link_simple_program(vs, fs);
150 glUseProgram(prog);
152 glClear(GL_COLOR_BUFFER_BIT);
154 piglit_draw_rect(0, 0, piglit_width, piglit_height);
156 /* lower-left corner */
157 pass = pass && piglit_probe_pixel_rgb(0, 0, green);
159 /* upper-right corner */
160 pass = pass && piglit_probe_pixel_rgb(99, 99, red);
163 /* Pixel origin upper left and pixel center integer */
165 static const float color1[4] = {0.125, 0.3725, 0.0, 0.0};
166 static const float color2[4] = {0.3725, 0.125, 0.0, 0.0};
167 const char *fragtext =
168 "#extension GL_ARB_fragment_coord_conventions: enable \n"
169 "layout(origin_upper_left, pixel_center_integer) varying vec4 gl_FragCoord; \n"
170 "void main(void) \n"
171 "{ \n"
172 " gl_FragColor = gl_FragCoord * 0.0025 + 0.125; \n"
173 " gl_FragColor.z = 0.0; \n"
174 "} \n";
176 fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fragtext);
177 prog = piglit_link_simple_program(vs, fs);
178 glUseProgram(prog);
180 glClear(GL_COLOR_BUFFER_BIT);
182 piglit_draw_rect(0, 0, piglit_width, piglit_height);
184 /* lower-left corner */
185 pass = pass && piglit_probe_pixel_rgb(0, 0, color1);
187 /* upper-right corner */
188 pass = pass && piglit_probe_pixel_rgb(99, 99, color2);
191 glutSwapBuffers();
193 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
197 void
198 piglit_init(int argc, char **argv)
200 if (!GLEW_VERSION_2_0) {
201 printf("Requires OpenGL 2.0\n");
202 piglit_report_result(PIGLIT_SKIP);
205 piglit_require_extension("GL_ARB_fragment_coord_conventions");