Add a negative test for bitwise not used in a larger expression.
[piglit/hramrach.git] / tests / general / depth-clamp-range.c
blob6999bd5911e7d2180ca37420b3ad42fce95e6d40
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
21 * DEALINGS IN THE SOFTWARE.
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
27 /** @file depth-clamp-range.c
29 * Tests that ARB_depth_clamp enablement didn't break DepthRange functionality,
30 * and properly uses the min/max selection.
33 #include "piglit-util.h"
35 int piglit_width = 150, piglit_height = 150;
36 int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH;
38 /* In case the headers have the old enum name but not the new */
39 #ifndef GL_DEPTH_CLAMP
40 #define GL_DEPTH_CLAMP GL_DEPTH_CLAMP_NV
41 #endif
43 void
44 piglit_init(int argc, char **argv)
46 piglit_require_extension("GL_ARB_depth_clamp");
48 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
51 void
52 quad(float base_x, float base_y, float z)
54 glBegin(GL_QUADS);
55 glVertex3f(base_x, base_y, z);
56 glVertex3f(base_x + 10, base_y, z);
57 glVertex3f(base_x + 10, base_y + 10, z);
58 glVertex3f(base_x, base_y + 10, z);
59 glEnd();
62 enum piglit_result
63 piglit_display(void)
65 GLboolean pass = GL_TRUE;
66 float white[3] = {1.0, 1.0, 1.0};
67 float clear[3] = {0.0, 0.0, 0.0};
69 glClearDepth(0.5);
70 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
71 glEnable(GL_DEPTH_TEST);
72 glDepthFunc(GL_LEQUAL);
74 glColor4fv(white);
76 /* Keep in mind that the ortho projection flips near and far's signs,
77 * so 1.0 to quad()'s z maps to glDepthRange's near, and -1.0 maps to
78 * glDepthRange's far.
81 /* Basic glDepthRange testing. */
82 glDisable(GL_DEPTH_CLAMP);
83 glDepthRange(0, 1);
84 quad(10, 10, 0.5); /* .25 - drawn. */
86 glDepthRange(1, 0);
87 quad(10, 30, 0.5); /* 0.75 - not drawn. */
89 /* Now, test that near depth clamping works.*/
90 glEnable(GL_DEPTH_CLAMP);
91 glDepthRange(0.25, 1.0);
92 quad(30, 10, 2); /* 0.25 - drawn. */
94 glDepthRange(0.75, 1.0);
95 quad(30, 30, 2); /* 0.75 - not drawn. */
97 /* Test that far clamping works.*/
98 glDepthRange(0.0, 0.25);
99 quad(50, 10, -2); /* 0.25 - drawn. */
101 glDepthRange(0.0, 0.75);
102 quad(50, 30, -2); /* 0.75 - not drawn. */
104 /* Now, flip near and far around and make sure that it's doing the
105 * min/max of near and far in the clamping.
108 /* Test that near (max) clamping works. */
109 glDepthRange(0.25, 0.0);
110 quad(70, 10, 2); /* 0.25 - drawn. */
112 glDepthRange(0.75, 0.0);
113 quad(70, 30, 2); /* 0.75 - not drawn. */
115 /* Now, test far (min) clamping works. */
116 glDepthRange(1.0, 0.0);
117 quad(90, 10, -2); /* 0.0 - drawn */
119 glDepthRange(1.0, 0.75);
120 quad(90, 30, -2); /* 0.75 - not drawn*/
122 pass = piglit_probe_pixel_rgb(15, 15, white) && pass;
123 pass = piglit_probe_pixel_rgb(15, 35, clear) && pass;
124 pass = piglit_probe_pixel_rgb(35, 15, white) && pass;
125 pass = piglit_probe_pixel_rgb(35, 35, clear) && pass;
126 pass = piglit_probe_pixel_rgb(55, 15, white) && pass;
127 pass = piglit_probe_pixel_rgb(55, 35, clear) && pass;
128 pass = piglit_probe_pixel_rgb(75, 15, white) && pass;
129 pass = piglit_probe_pixel_rgb(75, 35, clear) && pass;
130 pass = piglit_probe_pixel_rgb(95, 15, white) && pass;
131 pass = piglit_probe_pixel_rgb(95, 35, clear) && pass;
133 glutSwapBuffers();
135 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;