1 /* Test GL_EXT_stencil_wrap extension.
2 * This is by no means complete, just a quick check.
4 * Brian Paul 30 October 2002
15 static void RunTest(void)
17 const GLenum prim
= GL_QUAD_STRIP
;
23 glGetIntegerv(GL_STENCIL_BITS
, &bits
);
24 max
= (1 << bits
) - 1;
27 glEnable(GL_STENCIL_TEST
);
28 glStencilFunc(GL_ALWAYS
, 0, ~0);
32 glClear(GL_STENCIL_BUFFER_BIT
);
33 glStencilOp(GL_KEEP
, GL_KEEP
, GL_KEEP
);
35 printf("Testing GL_KEEP...\n");
43 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
44 if (val
!= expected
) {
45 printf("Failed GL_KEEP test(got %u, expected %u)\n", val
, expected
);
53 glClear(GL_STENCIL_BUFFER_BIT
);
54 glStencilOp(GL_KEEP
, GL_KEEP
, GL_ZERO
);
56 printf("Testing GL_ZERO...\n");
64 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
65 if (val
!= expected
) {
66 printf("Failed GL_ZERO test(got %u, expected %u)\n", val
, expected
);
74 glClear(GL_STENCIL_BUFFER_BIT
);
75 glStencilOp(GL_KEEP
, GL_KEEP
, GL_REPLACE
);
77 printf("Testing GL_REPLACE...\n");
85 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
86 if (val
!= expected
) {
87 printf("Failed GL_REPLACE test(got %u, expected %u)\n", val
, expected
);
93 /* test GL_INCR (saturation) */
95 glClear(GL_STENCIL_BUFFER_BIT
);
96 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
98 printf("Testing GL_INCR...\n");
99 for (i
= 1; i
< max
+10; i
++) {
100 expected
= (i
> max
) ? max
: i
;
102 glVertex2f(0, 0); glVertex2f(10, 0);
103 glVertex2f(0, 10); glVertex2f(10, 10);
106 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
107 if (val
!= expected
) {
108 printf( "Failed GL_INCR test on iteration #%u "
109 "(got %u, expected %u)\n", i
, val
, expected
);
116 /* test GL_DECR (saturation) */
118 glClear(GL_STENCIL_BUFFER_BIT
);
119 glStencilOp(GL_KEEP
, GL_KEEP
, GL_DECR
);
121 printf("Testing GL_DECR...\n");
122 for (i
= max
-1; i
> -10; i
--) {
123 expected
= (i
< 0) ? 0 : i
;
125 glVertex2f(0, 0); glVertex2f(10, 0);
126 glVertex2f(0, 10); glVertex2f(10, 10);
128 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
129 if (val
!= expected
) {
130 printf( "Failed GL_DECR test on iteration #%u "
131 "(got %u, expected %u)\n", max
- i
, val
, expected
);
140 glClear(GL_STENCIL_BUFFER_BIT
);
141 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INVERT
);
143 printf("Testing GL_INVERT...\n");
151 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
152 if (val
!= expected
) {
153 printf("Failed GL_INVERT test(got %u, expected %u)\n", val
, expected
);
161 /* test GL_INCR_WRAP_EXT (wrap around) */
163 glClear(GL_STENCIL_BUFFER_BIT
);
164 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR_WRAP_EXT
);
166 printf("Testing GL_INCR_WRAP_EXT...\n");
167 for (i
= 1; i
< max
+10; i
++) {
168 expected
= i
% (max
+ 1);
170 glVertex2f(0, 0); glVertex2f(10, 0);
171 glVertex2f(0, 10); glVertex2f(10, 10);
173 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
174 if (val
!= expected
) {
175 printf( "Failed GL_INCR_WRAP test on iteration #%u "
176 "(got %u, expected %u)\n", i
, val
, expected
);
183 /* test GL_DECR_WRAP_EXT (wrap-around) */
185 glClear(GL_STENCIL_BUFFER_BIT
);
186 glStencilOp(GL_KEEP
, GL_KEEP
, GL_DECR_WRAP_EXT
);
188 printf("Testing GL_DECR_WRAP_EXT...\n");
189 for (i
= max
-1; i
> -10; i
--) {
190 expected
= (i
< 0) ? max
+ i
+ 1: i
;
192 glVertex2f(0, 0); glVertex2f(10, 0);
193 glVertex2f(0, 10); glVertex2f(10, 10);
195 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
196 if (val
!= expected
) {
197 printf( "Failed GL_DECR_WRAP test on iteration #%u "
198 "(got %u, expected %u)\n", max
- i
, val
, expected
);
206 glDisable(GL_STENCIL_TEST
);
210 static void Display( void )
212 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
220 static void Reshape( int width
, int height
)
222 glViewport( 0, 0, width
, height
);
223 glMatrixMode( GL_PROJECTION
);
225 glOrtho(0, width
, 0, height
, -1, 1);
226 glMatrixMode( GL_MODELVIEW
);
231 static void Key( unsigned char key
, int x
, int y
)
244 static void Init( void )
246 const char * ver_str
;
249 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
250 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
253 /* Check for both the extension string and GL version 1.4 on the
254 * outside chance that some vendor exports version 1.4 but doesn't
255 * export the extension string. The stencil-wrap modes are a required
259 ver_str
= glGetString( GL_VERSION
);
260 version
= (ver_str
== NULL
) ? 1.0 : atof( ver_str
);
262 wrapping
= (glutExtensionSupported("GL_EXT_stencil_wrap") || (version
>= 1.4));
264 printf("GL_EXT_stencil_wrap not supported. Only testing the rest.\n");
268 int main( int argc
, char *argv
[] )
270 glutInit( &argc
, argv
);
271 glutInitWindowPosition( 0, 0 );
272 glutInitWindowSize( 400, 400 );
273 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_STENCIL
);
274 glutCreateWindow(argv
[0]);
275 glutReshapeFunc( Reshape
);
276 glutKeyboardFunc( Key
);
277 glutDisplayFunc( Display
);