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-stencil-clear.c
30 * Tests that glScissor properly affects glClear of the stencil buffer.
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 red
[] = {1.0, 0.0, 0.0, 0.0};
44 static float green
[] = {0.0, 1.0, 0.0, 0.0};
45 static float blue
[] = {0.0, 0.0, 1.0, 0.0};
47 /* whole window gray -- none should be visible */
48 glClearColor(0.5, 0.5, 0.5, 0.0);
49 glClear(GL_COLOR_BUFFER_BIT
);
51 /* Clear stencil to 0, which will be drawn green */
53 glClear(GL_STENCIL_BUFFER_BIT
);
55 /* quad at 10, 10 that will be drawn blue. */
56 glEnable(GL_SCISSOR_TEST
);
57 glScissor(10, 10, 10, 10);
59 glClear(GL_STENCIL_BUFFER_BIT
);
61 /* 0-sized quad at 10, 30 that shouldn't be drawn (red) */
62 glScissor(10, 30, 0, 0);
64 glClear(GL_STENCIL_BUFFER_BIT
);
66 glDisable(GL_SCISSOR_TEST
);
67 glEnable(GL_STENCIL_TEST
);
68 glStencilOp(GL_KEEP
, GL_KEEP
, GL_KEEP
);
70 /* First quad -- stencil == 0 gets green */
71 glStencilFunc(GL_EQUAL
, 0, ~0);
73 piglit_draw_rect(0, 0, piglit_width
, piglit_height
);
75 /* Second quad -- stencil == 1 gets blue */
76 glStencilFunc(GL_EQUAL
, 1, ~0);
78 piglit_draw_rect(0, 0, piglit_width
, piglit_height
);
80 /* Last quad -- stencil == 2 gets red (shouldn't occur!) */
81 glStencilFunc(GL_EQUAL
, 2, ~0);
83 piglit_draw_rect(0, 0, piglit_width
, piglit_height
);
85 for (y
= 0; y
< piglit_height
; y
++) {
86 for (x
= 0; x
< piglit_width
; x
++) {
89 if (x
>= 10 && x
< 20 && y
>= 10 && y
< 20)
94 pass
&= piglit_probe_pixel_rgb(x
, y
, expected
);
100 return pass
? PIGLIT_SUCCESS
: PIGLIT_FAILURE
;
104 static void reshape(int width
, int height
)
106 piglit_width
= width
;
107 piglit_height
= height
;
109 piglit_ortho_projection(width
, height
, GL_FALSE
);
113 piglit_init(int argc
, char **argv
)
115 reshape(piglit_width
, piglit_height
);