1 /* Test GL_EXT_stencil_wrap extension.
2 * This is by no means complete, just a quick check.
4 * Brian Paul 30 October 2002
14 static void RunTest(void)
16 const GLenum prim
= GL_QUAD_STRIP
;
21 glGetIntegerv(GL_STENCIL_BITS
, &bits
);
22 max
= (1 << bits
) - 1;
25 glEnable(GL_STENCIL_TEST
);
26 glStencilFunc(GL_ALWAYS
, 0, ~0);
28 /* test GL_INCR (saturation) */
29 glClear(GL_STENCIL_BUFFER_BIT
);
30 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
32 printf("Testing GL_INCR...\n");
33 for (i
= 1; i
< max
+10; i
++) {
34 int expected
= (i
> max
) ? max
: i
;
36 glVertex2f(0, 0); glVertex2f(10, 0);
37 glVertex2f(0, 10); glVertex2f(10, 10);
40 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
41 if (val
!= expected
) {
42 printf( "Failed GL_INCR test on iteration #%u "
43 "(got %u, expected %u)\n", i
, val
, expected
);
48 if ( !failed
) printf("OK!\n");
51 /* test GL_INCR_WRAP_EXT (wrap around) */
52 glClear(GL_STENCIL_BUFFER_BIT
);
53 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR_WRAP_EXT
);
55 printf("Testing GL_INCR_WRAP_EXT...\n");
56 for (i
= 1; i
< max
+10; i
++) {
57 int expected
= i
% (max
+ 1);
59 glVertex2f(0, 0); glVertex2f(10, 0);
60 glVertex2f(0, 10); glVertex2f(10, 10);
62 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
63 if (val
!= expected
) {
64 printf( "Failed GL_INCR_WRAP test on iteration #%u "
65 "(got %u, expected %u)\n", i
, val
, expected
);
69 if ( !failed
) printf("OK!\n");
73 /* test GL_INCR (saturation) */
74 glClear(GL_STENCIL_BUFFER_BIT
);
75 glStencilOp(GL_KEEP
, GL_KEEP
, GL_DECR
);
77 printf("Testing GL_DECR...\n");
78 for (i
= max
-1; i
> -10; i
--) {
79 int expected
= (i
< 0) ? 0 : i
;
81 glVertex2f(0, 0); glVertex2f(10, 0);
82 glVertex2f(0, 10); glVertex2f(10, 10);
84 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
85 if (val
!= expected
) {
86 printf( "Failed GL_DECR test on iteration #%u "
87 "(got %u, expected %u)\n", max
- i
, val
, expected
);
91 if ( !failed
) printf("OK!\n");
93 /* test GL_INCR_WRAP_EXT (wrap-around) */
94 glClear(GL_STENCIL_BUFFER_BIT
);
95 glStencilOp(GL_KEEP
, GL_KEEP
, GL_DECR_WRAP_EXT
);
97 printf("Testing GL_DECR_WRAP_EXT...\n");
98 for (i
= max
-1; i
> -10; i
--) {
99 int expected
= (i
< 0) ? max
+ i
+ 1: i
;
101 glVertex2f(0, 0); glVertex2f(10, 0);
102 glVertex2f(0, 10); glVertex2f(10, 10);
104 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
105 if (val
!= expected
) {
106 printf( "Failed GL_DECR_WRAP test on iteration #%u "
107 "(got %u, expected %u)\n", max
- i
, val
, expected
);
111 if ( !failed
) printf("OK!\n");
113 glDisable(GL_STENCIL_TEST
);
117 static void Display( void )
119 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
127 static void Reshape( int width
, int height
)
129 glViewport( 0, 0, width
, height
);
130 glMatrixMode( GL_PROJECTION
);
132 glOrtho(0, width
, 0, height
, -1, 1);
133 glMatrixMode( GL_MODELVIEW
);
138 static void Key( unsigned char key
, int x
, int y
)
151 static void Init( void )
153 const char * ver_str
;
156 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
157 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
160 /* Check for both the extension string and GL version 1.4 on the
161 * outside chance that some silly vendor exports version 1.4 but doesn't
162 * export the extension string. The stencil-wrap modes are a required
166 ver_str
= glGetString( GL_VERSION
);
167 version
= (ver_str
== NULL
) ? 1.0 : strtof( ver_str
, NULL
);
169 if ( !glutExtensionSupported("GL_EXT_stencil_wrap")
170 && (version
< 1.4) ) {
171 printf("Sorry, GL_EXT_stencil_wrap not supported.\n");
177 int main( int argc
, char *argv
[] )
179 glutInit( &argc
, argv
);
180 glutInitWindowPosition( 0, 0 );
181 glutInitWindowSize( 400, 400 );
182 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_STENCIL
);
183 glutCreateWindow(argv
[0]);
184 glutReshapeFunc( Reshape
);
185 glutKeyboardFunc( Key
);
186 glutDisplayFunc( Display
);