Add a negative test for bitwise not used in a larger expression.
[piglit/hramrach.git] / tests / general / depthfunc.c
blobb707cd618e617595387fdd85a5cd4ee4606270a9
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.h"
34 #include "piglit-framework.h"
36 int piglit_width = 100;
37 int piglit_height = 200;
38 int piglit_window_mode = GLUT_RGB | GLUT_ALPHA | GLUT_DEPTH;
40 /**
41 * Convenience function to draw an axis-aligned rectangle.
43 static void
44 draw_rect_depth(float x, float y, float w, float h, float d)
46 float verts[4][4];
48 verts[0][0] = x;
49 verts[0][1] = y;
50 verts[0][2] = d;
51 verts[0][3] = 1.0;
52 verts[1][0] = x + w;
53 verts[1][1] = y;
54 verts[1][2] = d;
55 verts[1][3] = 1.0;
56 verts[2][0] = x + w;
57 verts[2][1] = y + h;
58 verts[2][2] = d;
59 verts[2][3] = 1.0;
60 verts[3][0] = x;
61 verts[3][1] = y + h;
62 verts[3][2] = d;
63 verts[3][3] = 1.0;
65 glVertexPointer(4, GL_FLOAT, 0, verts);
66 glEnableClientState(GL_VERTEX_ARRAY);
68 glDrawArrays(GL_QUADS, 0, 4);
70 glDisableClientState(GL_VERTEX_ARRAY);
73 enum piglit_result
74 piglit_display(void)
76 GLboolean pass = GL_TRUE;
77 int i;
78 GLenum funcs[] = {
79 GL_NEVER,
80 GL_LESS,
81 GL_EQUAL,
82 GL_LEQUAL,
83 GL_GREATER,
84 GL_NOTEQUAL,
85 GL_GEQUAL,
86 GL_ALWAYS,
88 const float green[4] = {0, 1, 0, 0};
89 const float blue[4] = {0, 0, 1, 0};
91 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
92 /* Clear gray. */
93 glClearColor(0.5, 0.5, 0.5, 0.0);
94 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
96 glColor4f(0.0, 1.0, 0.0, 0.0);
97 glEnable(GL_DEPTH_TEST);
98 glDepthFunc(GL_ALWAYS);
99 for (i = 0; i < ARRAY_SIZE(funcs); i++) {
100 draw_rect_depth(10, 10 + 20 * i, 10, 10, 0.0);
101 draw_rect_depth(30, 10 + 20 * i, 10, 10, 0.0);
102 draw_rect_depth(50, 10 + 20 * i, 10, 10, 0.0);
105 glColor4f(0.0, 0.0, 1.0, 0.0);
106 for (i = 0; i < ARRAY_SIZE(funcs); i++) {
107 glDepthFunc(funcs[i]);
108 draw_rect_depth(10, 10 + 20 * i, 10, 10, 0.5);
109 draw_rect_depth(30, 10 + 20 * i, 10, 10, 0.0);
110 draw_rect_depth(50, 10 + 20 * i, 10, 10, -0.5);
113 for (i = 0; i < ARRAY_SIZE(funcs); i++) {
114 glDepthFunc(funcs[i]);
115 pass = pass && piglit_probe_pixel_rgb(15, 15 + 20 * i,
116 i & 1 ? blue : green);
117 pass = pass && piglit_probe_pixel_rgb(35, 15 + 20 * i,
118 i & 2 ? blue : green);
119 pass = pass && piglit_probe_pixel_rgb(55, 15 + 20 * i,
120 i & 4 ? blue : green);
123 glutSwapBuffers();
125 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
128 void piglit_init(int argc, char**argv)