cmake: move defaults into the per-platform section
[piglit.git] / tests / shaders / glsl-fs-fragcoord-zw-ortho.c
blob711fa974e88a97d9fe0cdaaf4d29f59fa913f415
1 /*
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
14 * Software.
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
22 * IN THE SOFTWARE.
24 * Authors:
25 * Eric Anholt <eric@anholt.net>
26 * Brian Paul
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
49 static void
50 draw_quad(float x, float y, float w, float h)
52 float zLeft = -1.0, zRight = 1.0;
53 float verts[4][4];
55 verts[0][0] = x;
56 verts[0][1] = y;
57 verts[0][2] = zLeft;
58 verts[0][3] = 1.0;
59 verts[1][0] = x + w;
60 verts[1][1] = y;
61 verts[1][2] = zRight;
62 verts[1][3] = 1.0;
63 verts[2][0] = x + w;
64 verts[2][1] = y + h;
65 verts[2][2] = zRight;
66 verts[2][3] = 1.0;
67 verts[3][0] = x;
68 verts[3][1] = y + h;
69 verts[3][2] = zLeft;
70 verts[3][3] = 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);
82 enum piglit_result
83 piglit_display(void)
85 GLboolean pass = GL_TRUE;
86 int x, y;
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);
93 /* Test Z values */
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;
99 /* Test colors */
100 for (y = 8; y < piglit_height && pass; y += 16) {
101 for (x = 8; x < piglit_width; x += 16) {
102 float color[3];
104 color[0] = 1.0 - x / 256.0; /* gl_FragCoord.z */
105 color[1] = 1.0; /* gl_FragCoord.w */
106 color[2] = 0;
108 pass &= piglit_probe_pixel_rgb(x, y, color);
109 if (!pass)
110 break;
114 piglit_present_results();
116 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
119 void
120 piglit_init(int argc, char **argv)
122 GLint vs, fs, prog;
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);
135 glUseProgram(prog);
137 glEnable(GL_DEPTH_TEST);