Add a negative test for bitwise not used in a larger expression.
[piglit/hramrach.git] / tests / general / stencil-twoside.c
blobe5166bb53c29ba7c405c021cfcea2309e86e16b3
1 /*
2 * (C) Copyright IBM Corporation 2004
3 * All Rights Reserved.
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 /**
26 * \file stencil_twoside.c
28 * Simple test of GL_ATI_separate_stencil (or the OGL 2.0 equivalent)
29 * functionality.
31 * Five squares (or six if stencil wrap is available) are drawn
32 * with different stencil modes, but all should be rendered with the same
33 * final color.
36 #include "piglit-util.h"
38 static int use20syntax = 1;
39 int piglit_width = 650;
40 int piglit_height = 200;
41 int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL;
42 static const GLfloat Near = 5.0, Far = 25.0;
45 enum piglit_result
46 piglit_display(void)
48 GLboolean pass = GL_TRUE;
49 GLint max_stencil;
50 GLint stencil_bits;
51 unsigned i;
52 float expected[4] = {0.5, 0.5, 0.5, 0.5};
53 int w = piglit_width / (6 * 2 + 1);
54 int h = w;
55 int start_y = (piglit_height - h) / 2;
57 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
59 glGetIntegerv(GL_STENCIL_BITS, & stencil_bits);
60 max_stencil = (1U << stencil_bits) - 1;
61 printf("Stencil bits = %u, maximum stencil value = 0x%08x\n",
62 stencil_bits, max_stencil);
64 glClearStencil(1);
65 glClearColor(0.2, 0.2, 0.8, 0);
66 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
67 | GL_STENCIL_BUFFER_BIT);
69 /* This is the "reference" square. */
70 glDisable(GL_STENCIL_TEST);
71 glColor3f(0.5, 0.5, 0.5);
72 piglit_draw_rect(w * 1, start_y, w, h);
74 glEnable(GL_STENCIL_TEST);
76 /* Draw the first two squares using incr for the affected face
79 /* 2nd square */
80 if (use20syntax) {
81 glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 0, ~0);
82 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 0, ~0);
83 glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR);
84 glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR);
86 else {
87 glStencilFuncSeparateATI(GL_ALWAYS, GL_ALWAYS, 0, ~0);
88 glStencilOpSeparateATI(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR);
89 glStencilOpSeparateATI(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR);
92 glColor3f(0.9, 0.9, 0.9);
93 for (i = 0 ; i < (max_stencil + 5) ; i++) {
94 /* this should be front facing */
95 piglit_draw_rect(w * 3, start_y, w, h);
98 /* stencil vals should be equal to max_stencil */
99 glStencilFunc(GL_EQUAL, max_stencil, ~0);
100 glColor3f(0.5, 0.5, 0.5);
101 piglit_draw_rect(w * 3, start_y, w, h);
103 /* 3rd square */
104 if (use20syntax) {
105 glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 0, ~0);
106 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 0, ~0);
107 glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_DECR);
108 glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR);
110 else {
111 glStencilFuncSeparateATI(GL_ALWAYS, GL_ALWAYS, 0, ~0);
112 glStencilOpSeparateATI(GL_FRONT, GL_KEEP, GL_KEEP, GL_DECR);
113 glStencilOpSeparateATI(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR);
116 glColor3f(0.9, 0.9, 0.9);
117 for (i = 0 ; i < (max_stencil + 5) ; i++) {
118 /* this should be back facing */
119 piglit_draw_rect(w * 5, start_y + h, w, -h);
122 /* stencil vals should be equal to max_stencil */
123 glStencilFunc(GL_EQUAL, max_stencil, ~0);
124 glColor3f(0.5, 0.5, 0.5);
125 piglit_draw_rect(w * 5, start_y, w, h);
127 /* 4th square */
128 if (use20syntax) {
129 glStencilFuncSeparate(GL_FRONT, GL_NEVER, 0, ~0);
130 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 0, ~0);
131 glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_DECR);
132 glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR);
134 else {
135 glStencilFuncSeparateATI(GL_NEVER, GL_ALWAYS, 0, ~0);
136 glStencilOpSeparateATI(GL_FRONT, GL_KEEP, GL_KEEP, GL_DECR);
137 glStencilOpSeparateATI(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR);
140 glColor3f(0.9, 0.9, 0.9);
141 for (i = 0 ; i < (max_stencil + 5) ; i++) {
142 /* this should be back facing */
143 piglit_draw_rect(w * 7, start_y + h, w, -h);
144 /* this should be front facing */
145 piglit_draw_rect(w * 7, start_y, w, h);
148 /* stencil vals should be equal to max_stencil */
149 glStencilFunc(GL_EQUAL, max_stencil, ~0);
150 glColor3f(0.5, 0.5, 0.5);
151 piglit_draw_rect(w * 7, start_y, w, h);
153 /* 5th square */
154 if (use20syntax) {
155 glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 0, ~0);
156 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 0, ~0);
157 glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR);
158 glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR);
160 else {
161 glStencilFuncSeparateATI(GL_ALWAYS, GL_ALWAYS, 0, ~0);
162 glStencilOpSeparateATI(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR);
163 glStencilOpSeparateATI(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR);
166 glColor3f(0.9, 0.9, 0.9);
167 for (i = 0 ; i < (max_stencil + 5) ; i++) {
168 /* this should be back facing */
169 piglit_draw_rect(w * 9, start_y + h, w, -h);
170 /* this should be front facing */
171 piglit_draw_rect(w * 9, start_y, w, h);
174 glStencilFunc(GL_EQUAL, 1, ~0);
175 glColor3f(0.5, 0.5, 0.5);
176 piglit_draw_rect(w * 9, start_y, w, h);
178 /* 6th square */
179 if (GLEW_EXT_stencil_wrap) {
180 if (use20syntax) {
181 glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 0, ~0);
182 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 0, ~0);
183 glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_KEEP);
184 glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR_WRAP);
186 else {
187 glStencilFuncSeparateATI(GL_ALWAYS, GL_ALWAYS, 0, ~0);
188 glStencilOpSeparateATI(GL_FRONT, GL_KEEP, GL_KEEP, GL_KEEP);
189 glStencilOpSeparateATI(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR_WRAP);
192 glColor3f(0.9, 0.9, 0.9);
193 for (i = 0 ; i < (max_stencil + 5) ; i++) {
194 /* this should be back facing */
195 piglit_draw_rect(w * 11, start_y + h, w, -h);
196 /* this should be front facing */
197 piglit_draw_rect(w * 11, start_y, w, h);
200 glStencilFunc(GL_EQUAL, 260 - 255, ~0);
201 glColor3f(0.5, 0.5, 0.5);
202 piglit_draw_rect(w * 11, start_y, w, h);
205 pass = piglit_probe_pixel_rgb(w * 1.5, piglit_height / 2, expected);
206 pass = piglit_probe_pixel_rgb(w * 3.5, piglit_height / 2, expected);
207 pass = piglit_probe_pixel_rgb(w * 5.5, piglit_height / 2, expected);
208 pass = piglit_probe_pixel_rgb(w * 7.5, piglit_height / 2, expected);
209 pass = piglit_probe_pixel_rgb(w * 9.5, piglit_height / 2, expected);
210 pass = piglit_probe_pixel_rgb(w * 11.5, piglit_height / 2, expected);
212 glutSwapBuffers();
214 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
217 void
218 piglit_init(int argc, char **argv)
220 if (!GLEW_ATI_separate_stencil && !GLEW_VERSION_2_0) {
221 printf("Sorry, this program requires either "
222 "GL_ATI_separate_stencil or OpenGL 2.0.\n");
223 piglit_report_result(PIGLIT_SKIP);
226 if (!GLEW_VERSION_2_0) {
227 use20syntax = 0;
230 printf("\nAll 5 (or 6) squares should be the same color.\n");