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 stencil-drawpixels.c
30 * Tests that glDrawPixels(GL_STENCIL) minimally works.
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};
46 static float square
[100];
48 /* whole window gray -- none should be visible */
49 glClearColor(0.5, 0.5, 0.5, 0.0);
50 glClear(GL_COLOR_BUFFER_BIT
);
52 /* Clear stencil to 0, which will be drawn red */
54 glClear(GL_STENCIL_BUFFER_BIT
);
56 /* quad at 10, 10 that will be drawn green. */
57 for (i
= 0; i
< 100; i
++)
59 glRasterPos2i(10, 10);
60 glDrawPixels(10, 10, GL_STENCIL_INDEX
, GL_FLOAT
, square
);
62 /* quad at 30, 10 that will be drawn blue. */
63 for (i
= 0; i
< 100; i
++)
65 glRasterPos2i(30, 10);
66 glDrawPixels(10, 10, GL_STENCIL_INDEX
, GL_FLOAT
, square
);
68 glDisable(GL_SCISSOR_TEST
);
69 glEnable(GL_STENCIL_TEST
);
70 glStencilOp(GL_KEEP
, GL_KEEP
, GL_KEEP
);
72 /* First quad -- stencil == 0 gets red */
73 glStencilFunc(GL_EQUAL
, 0, ~0);
75 piglit_draw_rect(0, 0, piglit_width
, piglit_height
);
77 /* Second quad -- stencil == 1 gets green */
78 glStencilFunc(GL_EQUAL
, 1, ~0);
80 piglit_draw_rect(0, 0, piglit_width
, piglit_height
);
82 /* Last quad -- stencil == 2 gets blue */
83 glStencilFunc(GL_EQUAL
, 2, ~0);
85 piglit_draw_rect(0, 0, piglit_width
, piglit_height
);
87 assert(glGetError() == 0);
89 for (y
= 0; y
< piglit_height
; y
++) {
90 for (x
= 0; x
< piglit_width
; x
++) {
93 if (x
>= 10 && x
< 20 && y
>= 10 && y
< 20)
95 else if (x
>= 30 && x
< 40 && y
>= 10 && y
< 20)
100 pass
&= piglit_probe_pixel_rgb(x
, y
, expected
);
106 return pass
? PIGLIT_SUCCESS
: PIGLIT_FAILURE
;
110 static void reshape(int width
, int height
)
112 piglit_width
= width
;
113 piglit_height
= height
;
115 glViewport(0, 0, width
, height
);
117 piglit_ortho_projection(width
, height
, GL_FALSE
);
121 piglit_init(int argc
, char **argv
)
123 reshape(piglit_width
, piglit_height
);