2 * Copyright © 2008 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
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
24 * Eric Anholt <eric@anholt.net>
28 /** @file scissor-bitmap.c
30 * Tests that clipping of glBitmap to the backbuffer works correctly, whether
31 * it's to window boundaries or glScissor.
34 #include "piglit-util.h"
35 #include "piglit-framework.h"
37 int piglit_width
= 400;
38 int piglit_height
= 400;
39 int piglit_window_mode
= GLUT_DOUBLE
| GLUT_RGB
;
42 struct test_position
{
56 add_probe(struct probes
*probes
,
57 const char *name
, const GLfloat
*color
,
58 int x
, int y
, int width
, int height
,
59 int bitmap_x_off
, int bitmap_y_off
)
61 probes
->probes
[probes
->n_probes
].color
= color
;
62 probes
->probes
[probes
->n_probes
].name
= name
;
63 probes
->probes
[probes
->n_probes
].x
= x
;
64 probes
->probes
[probes
->n_probes
].y
= y
;
65 probes
->probes
[probes
->n_probes
].bitmap_x_off
= bitmap_x_off
;
66 probes
->probes
[probes
->n_probes
].bitmap_y_off
= bitmap_y_off
;
67 probes
->probes
[probes
->n_probes
].width
= width
;
68 probes
->probes
[probes
->n_probes
].height
= height
;
73 get_bitmap_bit(int x
, int y
)
75 const uint8_t *row
= &fdo_bitmap
[y
* fdo_bitmap_width
/ 8];
77 return (row
[x
/ 8] >> (7 - x
% 8)) & 1;
81 verify_bitmap_pixel(struct probes
*probes
, int i
, int x
, int y
)
83 const GLfloat black
[4] = {0.0, 0.0, 0.0, 0.0};
84 int x1
= probes
->probes
[i
].x
;
85 int y1
= probes
->probes
[i
].y
;
86 int bitmap_x1
= probes
->probes
[i
].bitmap_x_off
;
87 int bitmap_y1
= probes
->probes
[i
].bitmap_y_off
;
88 const GLfloat
*expected
;
91 if (probes
->probes
[i
].color
== NULL
) {
96 on
= get_bitmap_bit(x
- x1
+ bitmap_x1
,
98 /* Verify that the region is black if unset, or the foreground
102 expected
= probes
->probes
[i
].color
;
107 /* Make sure the region is black */
108 pass
= piglit_probe_pixel_rgb(x
, y
, expected
);
110 printf("glBitmap error in %s (test offset %d,%d)\n",
111 probes
->probes
[i
].name
,
112 x
- probes
->probes
[i
].x
,
113 y
- probes
->probes
[i
].y
);
118 verify_bitmap_contents(struct probes
*probes
, int i
)
121 int x1
= probes
->probes
[i
].x
;
122 int y1
= probes
->probes
[i
].y
;
123 int x2
= probes
->probes
[i
].x
+ probes
->probes
[i
].width
;
124 int y2
= probes
->probes
[i
].y
+ probes
->probes
[i
].height
;
125 GLboolean pass
= GL_TRUE
;
127 for (y
= y1
; y
< y2
; y
++) {
128 if (y
< 0 || y
>= piglit_height
)
130 for (x
= x1
; x
< x2
; x
++) {
131 if (x
< 0 || x
>= piglit_width
)
134 pass
&= verify_bitmap_pixel(probes
, i
, x
, y
);
146 const GLfloat red
[4] = {1.0, 0.0, 0.0, 0.0};
147 const GLfloat green
[4] = {0.0, 1.0, 0.0, 0.0};
148 const GLfloat blue
[4] = {0.0, 0.0, 1.0, 0.0};
150 int center_x_start
= (piglit_width
- fdo_bitmap_width
) / 2;
151 int center_y_start
= (piglit_height
- fdo_bitmap_height
) / 2;
152 int start_x
, start_y
;
153 struct probes probes
;
154 GLboolean pass
= GL_TRUE
;
155 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
157 memset(&probes
, 0, sizeof(probes
));
159 glClearColor(0, 0, 0, 0);
160 glClear(GL_COLOR_BUFFER_BIT
);
163 /* Center: full image */
164 glRasterPos2f(center_x_start
, center_y_start
);
165 glBitmap(fdo_bitmap_width
, fdo_bitmap_height
, 0, 0, 0, 0, fdo_bitmap
);
166 add_probe(&probes
, "center full", red
,
167 center_x_start
, center_y_start
,
168 fdo_bitmap_width
, fdo_bitmap_height
,
171 glEnable(GL_SCISSOR_TEST
);
174 start_x
= center_x_start
- fdo_bitmap_width
- 10;
175 start_y
= center_y_start
;
176 glScissor(start_x
+ fdo_bitmap_width
/ 4,
180 glRasterPos2f(start_x
, start_y
);
181 glBitmap(fdo_bitmap_width
, fdo_bitmap_height
, 0, 0, 0, 0, fdo_bitmap
);
182 add_probe(&probes
, "left glscissor clipped area", NULL
,
184 fdo_bitmap_width
/ 4, fdo_bitmap_height
,
186 add_probe(&probes
, "left glscissor unclipped area", green
,
187 start_x
+ fdo_bitmap_width
/ 4, start_y
,
188 fdo_bitmap_width
* 3 / 4, fdo_bitmap_height
,
189 fdo_bitmap_width
/ 4, 0);
192 start_x
= center_x_start
+ fdo_bitmap_width
+ 10;
193 start_y
= center_y_start
;
196 fdo_bitmap_width
* 3 / 4,
198 glRasterPos2f(start_x
, start_y
);
199 glBitmap(fdo_bitmap_width
, fdo_bitmap_height
, 0, 0, 0, 0, fdo_bitmap
);
200 add_probe(&probes
, "right glscissor clipped area", NULL
,
201 start_x
+ fdo_bitmap_width
* 3 /4,
203 fdo_bitmap_width
/ 4,
206 add_probe(&probes
, "right glscissor unclipped area", green
,
208 fdo_bitmap_width
* 3 / 4, fdo_bitmap_height
,
212 start_x
= center_x_start
;
213 start_y
= center_y_start
+ fdo_bitmap_height
+ 10;
217 fdo_bitmap_height
* 3 / 4);
218 glRasterPos2f(start_x
, start_y
);
219 glBitmap(fdo_bitmap_width
, fdo_bitmap_height
, 0, 0, 0, 0, fdo_bitmap
);
220 add_probe(&probes
, "top glscissor clipped area", NULL
,
222 start_y
+ fdo_bitmap_height
* 3 /4,
224 fdo_bitmap_height
/ 4,
226 add_probe(&probes
, "top glscissor unclipped area", green
,
228 fdo_bitmap_width
, fdo_bitmap_height
* 3 / 4,
232 start_x
= center_x_start
;
233 start_y
= center_y_start
- fdo_bitmap_height
- 10;
235 start_y
+ fdo_bitmap_height
/ 4,
238 glRasterPos2f(start_x
, start_y
);
239 glBitmap(fdo_bitmap_width
, fdo_bitmap_height
, 0, 0, 0, 0, fdo_bitmap
);
240 add_probe(&probes
, "bottom glscissor clipped area", NULL
,
242 fdo_bitmap_width
, fdo_bitmap_height
/ 4,
244 add_probe(&probes
, "bottom glscissor unclipped area", green
,
245 start_x
, start_y
+ fdo_bitmap_height
/ 4,
246 fdo_bitmap_width
, fdo_bitmap_height
* 3 / 4,
247 0, fdo_bitmap_height
/ 4);
249 glDisable(GL_SCISSOR_TEST
);
251 /* Left side of window (not drawn due to invalid pos) */
252 start_x
= -fdo_bitmap_width
/ 4;
253 start_y
= center_y_start
;
254 glRasterPos2f(start_x
, start_y
);
255 glBitmap(fdo_bitmap_width
, fdo_bitmap_height
, 0, 0, 0, 0, fdo_bitmap
);
256 add_probe(&probes
, "left window clipped area", NULL
,
257 start_x
+ fdo_bitmap_width
/ 4, start_y
,
258 fdo_bitmap_width
* 3 / 4, fdo_bitmap_height
,
259 fdo_bitmap_width
/ 4, 0);
260 /* Right side of window */
261 start_x
= piglit_width
- fdo_bitmap_width
* 3 / 4;
262 start_y
= center_y_start
;
263 glRasterPos2f(start_x
, start_y
);
264 glBitmap(fdo_bitmap_width
, fdo_bitmap_height
, 0, 0, 0, 0, fdo_bitmap
);
265 add_probe(&probes
, "right window unclipped area", blue
,
267 fdo_bitmap_width
* 3 / 4, fdo_bitmap_height
,
271 start_x
= center_x_start
;
272 start_y
= piglit_height
- fdo_bitmap_height
* 3 / 4;
273 glRasterPos2f(start_x
, start_y
);
274 glBitmap(fdo_bitmap_width
, fdo_bitmap_height
, 0, 0, 0, 0, fdo_bitmap
);
275 add_probe(&probes
, "top window unclipped area", blue
,
277 fdo_bitmap_width
, fdo_bitmap_height
* 3 / 4,
279 /* Bottom of window (not drawn due to invalid pos) */
280 start_x
= center_x_start
;
281 start_y
= -fdo_bitmap_height
/ 4;
282 glRasterPos2f(start_x
, start_y
);
283 glBitmap(fdo_bitmap_width
, fdo_bitmap_height
, 0, 0, 0, 0, fdo_bitmap
);
284 add_probe(&probes
, "bottom window clipped area", NULL
,
286 fdo_bitmap_width
, fdo_bitmap_height
* 3 / 4,
292 for (i
= 0; i
< probes
.n_probes
; i
++) {
293 pass
= pass
&& verify_bitmap_contents(&probes
, i
);
296 return pass
? PIGLIT_SUCCESS
: PIGLIT_FAILURE
;
301 piglit_init(int argc
, char **argv
)
303 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);