2 * Copyright © 2009 Intel Corporation
3 * Copyright © 2011 VMware, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * Eric Anholt <eric@anholt.net>
30 /** @file glsl-fs-fragcoord-zw-ortho.c
32 * Tests that gl_FragCoord.zw produces the expected output in a fragment shader
33 * with an orthographic projection
36 #include "piglit-util-gl.h"
38 PIGLIT_GL_TEST_CONFIG_BEGIN
40 config
.supports_gl_compat_version
= 10;
42 config
.window_width
= 256;
43 config
.window_height
= 256;
44 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_DEPTH
;
45 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
47 PIGLIT_GL_TEST_CONFIG_END
50 draw_quad(float x
, float y
, float w
, float h
)
52 float zLeft
= -1.0, zRight
= 1.0;
72 glVertexPointer(4, GL_FLOAT
, 0, verts
);
73 glEnableClientState(GL_VERTEX_ARRAY
);
75 glDrawArrays(GL_TRIANGLE_FAN
, 0, 4);
77 glDisableClientState(GL_VERTEX_ARRAY
);
85 GLboolean pass
= GL_TRUE
;
88 glClearColor(0.5, 0.5, 0.5, 0.5);
89 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
91 draw_quad(0, 0, piglit_width
, piglit_height
);
94 pass
= piglit_probe_pixel_depth(0, 0, 1.0) && pass
;
95 pass
= piglit_probe_pixel_depth(piglit_width
-1, 0, 0.0) && pass
;
96 pass
= piglit_probe_pixel_depth(piglit_width
-1, piglit_height
-1, 0.0) && pass
;
97 pass
= piglit_probe_pixel_depth(0, piglit_height
-1, 1.0) && pass
;
100 for (y
= 8; y
< piglit_height
&& pass
; y
+= 16) {
101 for (x
= 8; x
< piglit_width
; x
+= 16) {
104 color
[0] = 1.0 - x
/ 256.0; /* gl_FragCoord.z */
105 color
[1] = 1.0; /* gl_FragCoord.w */
108 pass
&= piglit_probe_pixel_rgb(x
, y
, color
);
114 piglit_present_results();
116 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
120 piglit_init(int argc
, char **argv
)
124 piglit_require_gl_version(20);
126 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
128 vs
= piglit_compile_shader(GL_VERTEX_SHADER
,
129 "shaders/glsl-mvp.vert");
130 fs
= piglit_compile_shader(GL_FRAGMENT_SHADER
,
131 "shaders/glsl-fs-fragcoord-zw.frag");
133 prog
= piglit_link_simple_program(vs
, fs
);
137 glEnable(GL_DEPTH_TEST
);