Add a negative test for bitwise not used in a larger expression.
[piglit/hramrach.git] / tests / bugs / fdo10370.c
blobc89cfe4aaa0d0f2a8c5b9ee50479dfe67866368a
1 /*
2 * Test case from fdo bug #10370
3 * http://bugs.freedesktop.org/show_bug.cgi?id=10370
4 */
6 #include "piglit-util.h"
8 static int Automatic = 0;
10 #define WIN_WIDTH 128
11 #define WIN_HEIGHT 128
12 #define BITMAP_WIDTH 1
13 #define BITMAP_HEIGHT 1
14 #define ALIGN 1
15 GLfloat read_buf[4 * BITMAP_WIDTH * BITMAP_HEIGHT];
16 static GLfloat r_map[] = { 0, 1 };
17 static GLfloat g_map[] = { 0, 0 };
18 static GLfloat b_map[] = { 1, 0 };
19 static GLfloat a_map[] = { 1, 1 };
20 static GLubyte data[] = { 0x8f, 0xff, 0x7f, 0x70 };
22 static GLuint tex_name;
24 void init(void)
26 glMatrixMode(GL_PROJECTION);
27 glLoadIdentity();
28 glTranslatef(-1.0, -1.0, 0.0);
29 glScalef(2.0/WIN_WIDTH, 2.0/WIN_HEIGHT, 1.0);
31 glDisable(GL_DITHER);
32 glClearColor(1, 1, 1, 1);
33 glBlendFunc(GL_SRC_ALPHA, GL_ZERO);
35 glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 2, r_map);
36 glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 2, g_map);
37 glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 2, b_map);
38 glPixelMapfv(GL_PIXEL_MAP_I_TO_A, 2, a_map);
40 glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
42 glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
43 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
44 glPixelStorei(GL_UNPACK_ALIGNMENT, ALIGN);
46 glGenTextures(1, &tex_name);
47 glBindTexture(GL_TEXTURE_2D, tex_name);
49 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
50 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
51 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
56 void display(void)
58 int i, j, k, col, pixel;
59 GLfloat expected[4];
60 float dmax = 0.0;
62 memset(read_buf, 0xff, sizeof(read_buf)); //reset
64 for (k = 0; k < (sizeof(data)/sizeof(GLubyte)); k ++) {
66 glClear(GL_COLOR_BUFFER_BIT);
67 glNewList(1, GL_COMPILE_AND_EXECUTE);
68 glEnable(GL_TEXTURE_2D);
69 glBindTexture(GL_TEXTURE_2D, tex_name);
71 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
72 BITMAP_WIDTH, BITMAP_HEIGHT, 0,
73 GL_COLOR_INDEX, GL_BITMAP, &data[k]);
75 glBegin(GL_POLYGON);
76 glTexCoord2f(0,0); glVertex2f(0, 0);
77 glTexCoord2f(1,0); glVertex2f(BITMAP_WIDTH, 0);
78 glTexCoord2f(1,1); glVertex2f(BITMAP_WIDTH, BITMAP_HEIGHT);
79 glTexCoord2f(0,1); glVertex2f(0, BITMAP_HEIGHT);
80 glEnd();
81 glDisable(GL_TEXTURE_2D);
82 glEndList();
83 glFlush();
85 glReadPixels(0, 0, BITMAP_WIDTH, BITMAP_HEIGHT,
86 GL_RGBA, GL_FLOAT, read_buf);
88 printf("data[0x%x], ", data[k]);
89 if (data[k] & 0x80) {
90 printf("foreground: expected RGBA (%1.1f, %1.1f %1.1f %1.1f)\n",
91 r_map[1], g_map[1], b_map[1], a_map[1]);
92 expected[0] = r_map[1];
93 expected[1] = g_map[1];
94 expected[2] = b_map[1];
95 expected[3] = a_map[1];
96 } else {
97 printf("background: expected RGBA (%1.1f, %1.1f %1.1f %1.1f)\n",
98 r_map[0], g_map[0], b_map[0], a_map[0]);
99 expected[0] = r_map[0];
100 expected[1] = g_map[0];
101 expected[2] = b_map[0];
102 expected[3] = a_map[0];
105 printf("First execution, Readback RGBA:\n");
106 for (i = 0; i < BITMAP_HEIGHT; i ++) {
107 for (j = 0; j < BITMAP_WIDTH; j ++) {
108 pixel = j + i*BITMAP_WIDTH;
109 printf("pixel[%d, %d]: %1.1f %1.1f %1.1f %1.1f\n", j, i,
110 read_buf[pixel*4], read_buf[pixel*4+1],
111 read_buf[pixel*4+2], read_buf[pixel*4+3]);
113 for(col = 0; col < 4; ++col) {
114 float delta = read_buf[pixel*4+col] - expected[col];
115 if (delta > dmax) dmax = delta;
116 else if (-delta > dmax) dmax = -delta;
121 /* 2nd time execution from call list */
122 glCallList(1);
123 glDeleteLists(1,1);
125 memset(read_buf, 0xff, sizeof(read_buf)); //reset
126 glReadPixels(0, 0, BITMAP_WIDTH, BITMAP_HEIGHT,
127 GL_RGBA, GL_FLOAT, read_buf);
129 printf("CallList execution, Readback RGBA:\n");
130 for (i = 0; i < BITMAP_HEIGHT; i ++) {
131 for (j = 0; j < BITMAP_WIDTH; j ++) {
132 pixel = j + i*BITMAP_WIDTH;
133 printf("pixel[%d, %d]: %1.1f %1.1f %1.1f %1.1f\n", j, i,
134 read_buf[pixel*4], read_buf[pixel*4+1],
135 read_buf[pixel*4+2], read_buf[pixel*4+3]);
136 for(col = 0; col < 4; ++col) {
137 float delta = read_buf[pixel*4+col] - expected[col];
138 if (delta > dmax) dmax = delta;
139 else if (-delta > dmax) dmax = -delta;
143 printf("------------------------------------\n");
144 } //end for(k)
146 printf("max delta: %f\n", dmax);
148 if (Automatic) {
149 if (dmax > 0.02)
150 printf("PIGLIT: {'result': 'fail' }\n");
151 else
152 printf("PIGLIT: {'result': 'pass' }\n");
154 exit(0);
159 int main(int argc, char**argv)
161 glutInit(&argc, argv);
162 if (argc == 2 && !strcmp(argv[1], "-auto"))
163 Automatic = 1;
164 glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
165 glutInitWindowSize (WIN_WIDTH, WIN_HEIGHT);
166 glutInitWindowPosition (100, 100);
167 glutCreateWindow ("fdo10370");
168 init();
169 glutDisplayFunc(display);
170 glutMainLoop();
172 return 0;