glsl: test loop unroll with uint overflow
[piglit.git] / tests / general / depthfunc.c
blob297336961bccd00330c2b7b3272e92a8994490a5
1 /*
2 * Copyright © 2009 Intel Corporation
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 * Authors:
24 * Eric Anholt <eric@anholt.net>
28 /** @file depthfunc.c
30 * Tests that glDepthFunc()'s various modes all work correctly.
33 #include "piglit-util-gl.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config.supports_gl_compat_version = 10;
39 config.window_height = 200;
40 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DEPTH;
41 config.khr_no_error_support = PIGLIT_NO_ERRORS;
43 PIGLIT_GL_TEST_CONFIG_END
45 /**
46 * Convenience function to draw an axis-aligned rectangle.
48 static void
49 draw_rect_depth(float x, float y, float w, float h, float d)
51 float verts[4][4];
53 verts[0][0] = x;
54 verts[0][1] = y;
55 verts[0][2] = d;
56 verts[0][3] = 1.0;
57 verts[1][0] = x + w;
58 verts[1][1] = y;
59 verts[1][2] = d;
60 verts[1][3] = 1.0;
61 verts[2][0] = x + w;
62 verts[2][1] = y + h;
63 verts[2][2] = d;
64 verts[2][3] = 1.0;
65 verts[3][0] = x;
66 verts[3][1] = y + h;
67 verts[3][2] = d;
68 verts[3][3] = 1.0;
70 glVertexPointer(4, GL_FLOAT, 0, verts);
71 glEnableClientState(GL_VERTEX_ARRAY);
73 glDrawArrays(GL_QUADS, 0, 4);
75 glDisableClientState(GL_VERTEX_ARRAY);
78 enum piglit_result
79 piglit_display(void)
81 GLboolean pass = GL_TRUE;
82 int i;
83 GLenum funcs[] = {
84 GL_NEVER,
85 GL_LESS,
86 GL_EQUAL,
87 GL_LEQUAL,
88 GL_GREATER,
89 GL_NOTEQUAL,
90 GL_GEQUAL,
91 GL_ALWAYS,
93 const float green[4] = {0, 1, 0, 0};
94 const float blue[4] = {0, 0, 1, 0};
96 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
97 /* Clear gray. */
98 glClearColor(0.5, 0.5, 0.5, 0.0);
99 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
101 glColor4f(0.0, 1.0, 0.0, 0.0);
102 glEnable(GL_DEPTH_TEST);
103 glDepthFunc(GL_ALWAYS);
104 for (i = 0; i < ARRAY_SIZE(funcs); i++) {
105 draw_rect_depth(10, 10 + 20 * i, 10, 10, 0.0);
106 draw_rect_depth(30, 10 + 20 * i, 10, 10, 0.0);
107 draw_rect_depth(50, 10 + 20 * i, 10, 10, 0.0);
110 glColor4f(0.0, 0.0, 1.0, 0.0);
111 for (i = 0; i < ARRAY_SIZE(funcs); i++) {
112 glDepthFunc(funcs[i]);
113 draw_rect_depth(10, 10 + 20 * i, 10, 10, 0.5);
114 draw_rect_depth(30, 10 + 20 * i, 10, 10, 0.0);
115 draw_rect_depth(50, 10 + 20 * i, 10, 10, -0.5);
118 for (i = 0; i < ARRAY_SIZE(funcs); i++) {
119 glDepthFunc(funcs[i]);
120 pass = pass && piglit_probe_pixel_rgb(15, 15 + 20 * i,
121 i & 1 ? blue : green);
122 pass = pass && piglit_probe_pixel_rgb(35, 15 + 20 * i,
123 i & 2 ? blue : green);
124 pass = pass && piglit_probe_pixel_rgb(55, 15 + 20 * i,
125 i & 4 ? blue : green);
128 piglit_present_results();
130 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
133 void piglit_init(int argc, char**argv)