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
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-copypixels.c
30 * Tests that glScissor properly affects glClear(GL_DEPTH_BUFFER_BIT).
33 #include "piglit-util.h"
35 int piglit_width
= 100, piglit_height
= 100;
36 int piglit_window_mode
= GLUT_DOUBLE
| GLUT_RGB
| GLUT_DEPTH
| GLUT_STENCIL
;
41 GLboolean pass
= GL_TRUE
;
43 static float green
[] = {0.0, 1.0, 0.0, 0.0};
44 static float blue
[] = {0.0, 0.0, 1.0, 0.0};
46 /* whole window green -- depth fail will be this. */
47 glClearColor(0.0, 1.0, 0.0, 0.0);
48 glClear(GL_COLOR_BUFFER_BIT
);
50 /* Clear depth to 0 (fail) */
52 glClear(GL_DEPTH_BUFFER_BIT
);
54 /* Clear depth quad at 10, 10 to be drawn blue. */
55 glEnable(GL_SCISSOR_TEST
);
56 glScissor(10, 10, 10, 10);
58 glClear(GL_DEPTH_BUFFER_BIT
);
60 /* Clear a 0x0 depth quad a 10, 30 that shouldn't be drawn. */
61 glScissor(10, 30, 0, 0);
63 glClear(GL_DEPTH_BUFFER_BIT
);
65 /* Now draw a quad midway between 0.0 and 1.0 depth so only that
66 * scissored depth clear will get rasterized.
68 glEnable(GL_DEPTH_TEST
);
69 glDisable(GL_SCISSOR_TEST
);
72 piglit_draw_rect(0, 0, piglit_width
, piglit_height
);
74 for (y
= 0; y
< piglit_height
; y
++) {
75 for (x
= 0; x
< piglit_width
; x
++) {
78 if (x
>= 10 && x
< 20 && y
>= 10 && y
< 20)
83 pass
&= piglit_probe_pixel_rgb(x
, y
, expected
);
89 return pass
? PIGLIT_SUCCESS
: PIGLIT_FAILURE
;
93 static void reshape(int width
, int height
)
96 piglit_height
= height
;
98 glViewport(0, 0, width
, height
);
99 glMatrixMode(GL_PROJECTION
);
102 glOrtho(0.0, width
, 0.0, height
, -1.0, 1.0);
103 glMatrixMode(GL_MODELVIEW
);
108 piglit_init(int argc
, char **argv
)
110 reshape(piglit_width
, piglit_height
);