diff options
-rw-r--r-- | progs/tests/stencilwrap.c | 191 |
1 files changed, 141 insertions, 50 deletions
diff --git a/progs/tests/stencilwrap.c b/progs/tests/stencilwrap.c index 8e4475316d..753375d0f3 100644 --- a/progs/tests/stencilwrap.c +++ b/progs/tests/stencilwrap.c @@ -10,73 +10,117 @@ #include <math.h> #include <GL/glut.h> +GLboolean wrapping; static void RunTest(void) { const GLenum prim = GL_QUAD_STRIP; GLubyte val; int bits, max, i; + int expected; GLboolean failed; glGetIntegerv(GL_STENCIL_BITS, &bits); max = (1 << bits) - 1; - glClearStencil(0); + glEnable(GL_STENCIL_TEST); glStencilFunc(GL_ALWAYS, 0, ~0); - /* test GL_INCR (saturation) */ + /* test GL_KEEP */ + glClearStencil(max); glClear(GL_STENCIL_BUFFER_BIT); - glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); + glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); failed = GL_FALSE; - printf("Testing GL_INCR...\n"); - for (i = 1; i < max+10; i++) { - int expected = (i > max) ? max : i; - glBegin(prim); - glVertex2f(0, 0); glVertex2f(10, 0); - glVertex2f(0, 10); glVertex2f(10, 10); - glEnd(); - - glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &val); - if (val != expected) { - printf( "Failed GL_INCR test on iteration #%u " - "(got %u, expected %u)\n", i, val, expected ); - failed = GL_TRUE; - } + printf("Testing GL_KEEP...\n"); + expected = max; + glBegin(prim); + glVertex2f(0, 0); + glVertex2f(10, 0); + glVertex2f(0, 10); + glVertex2f(10, 10); + glEnd(); + glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &val); + if (val != expected) { + printf("Failed GL_KEEP test(got %u, expected %u)\n", val, expected); + failed = GL_TRUE; } + else + printf("OK!\n"); - if ( !failed ) printf("OK!\n"); + /* test GL_ZERO */ + glClearStencil(max); + glClear(GL_STENCIL_BUFFER_BIT); + glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO); + failed = GL_FALSE; + printf("Testing GL_ZERO...\n"); + expected = 0; + glBegin(prim); + glVertex2f(0, 0); + glVertex2f(10, 0); + glVertex2f(0, 10); + glVertex2f(10, 10); + glEnd(); + glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &val); + if (val != expected) { + printf("Failed GL_ZERO test(got %u, expected %u)\n", val, expected); + failed = GL_TRUE; + } + else + printf("OK!\n"); + /* test GL_REPLACE */ + glClearStencil(max); + glClear(GL_STENCIL_BUFFER_BIT); + glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); + failed = GL_FALSE; + printf("Testing GL_REPLACE...\n"); + expected = 0; + glBegin(prim); + glVertex2f(0, 0); + glVertex2f(10, 0); + glVertex2f(0, 10); + glVertex2f(10, 10); + glEnd(); + glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &val); + if (val != expected) { + printf("Failed GL_REPLACE test(got %u, expected %u)\n", val, expected); + failed = GL_TRUE; + } + else + printf("OK!\n"); - /* test GL_INCR_WRAP_EXT (wrap around) */ + /* test GL_INCR (saturation) */ + glClearStencil(0); glClear(GL_STENCIL_BUFFER_BIT); - glStencilOp(GL_KEEP, GL_KEEP, GL_INCR_WRAP_EXT); + glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); failed = GL_FALSE; - printf("Testing GL_INCR_WRAP_EXT...\n"); + printf("Testing GL_INCR...\n"); for (i = 1; i < max+10; i++) { - int expected = i % (max + 1); + expected = (i > max) ? max : i; glBegin(prim); glVertex2f(0, 0); glVertex2f(10, 0); glVertex2f(0, 10); glVertex2f(10, 10); glEnd(); + glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &val); if (val != expected) { - printf( "Failed GL_INCR_WRAP test on iteration #%u " + printf( "Failed GL_INCR test on iteration #%u " "(got %u, expected %u)\n", i, val, expected ); failed = GL_TRUE; } } - if ( !failed ) printf("OK!\n"); + if ( !failed ) + printf("OK!\n"); + /* test GL_DECR (saturation) */ glClearStencil(max); - - /* test GL_INCR (saturation) */ glClear(GL_STENCIL_BUFFER_BIT); glStencilOp(GL_KEEP, GL_KEEP, GL_DECR); failed = GL_FALSE; printf("Testing GL_DECR...\n"); for (i = max-1; i > -10; i--) { - int expected = (i < 0) ? 0 : i; + expected = (i < 0) ? 0 : i; glBegin(prim); glVertex2f(0, 0); glVertex2f(10, 0); glVertex2f(0, 10); glVertex2f(10, 10); @@ -88,27 +132,76 @@ static void RunTest(void) failed = GL_TRUE; } } - if ( !failed ) printf("OK!\n"); + if ( !failed ) + printf("OK!\n"); - /* test GL_INCR_WRAP_EXT (wrap-around) */ + /* test GL_INVERT */ + glClearStencil(0); glClear(GL_STENCIL_BUFFER_BIT); - glStencilOp(GL_KEEP, GL_KEEP, GL_DECR_WRAP_EXT); + glStencilOp(GL_KEEP, GL_KEEP, GL_INVERT); failed = GL_FALSE; - printf("Testing GL_DECR_WRAP_EXT...\n"); - for (i = max-1; i > -10; i--) { - int expected = (i < 0) ? max + i + 1: i; - glBegin(prim); - glVertex2f(0, 0); glVertex2f(10, 0); - glVertex2f(0, 10); glVertex2f(10, 10); - glEnd(); - glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &val); - if (val != expected) { - printf( "Failed GL_DECR_WRAP test on iteration #%u " - "(got %u, expected %u)\n", max - i, val, expected ); - failed = GL_TRUE; - } + printf("Testing GL_INVERT...\n"); + expected = max; + glBegin(prim); + glVertex2f(0, 0); + glVertex2f(10, 0); + glVertex2f(0, 10); + glVertex2f(10, 10); + glEnd(); + glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &val); + if (val != expected) { + printf("Failed GL_INVERT test(got %u, expected %u)\n", val, expected); + failed = GL_TRUE; + } + else + printf("OK!\n"); + + if(wrapping) + { + /* test GL_INCR_WRAP_EXT (wrap around) */ + glClearStencil(0); + glClear(GL_STENCIL_BUFFER_BIT); + glStencilOp(GL_KEEP, GL_KEEP, GL_INCR_WRAP_EXT); + failed = GL_FALSE; + printf("Testing GL_INCR_WRAP_EXT...\n"); + for (i = 1; i < max+10; i++) { + expected = i % (max + 1); + glBegin(prim); + glVertex2f(0, 0); glVertex2f(10, 0); + glVertex2f(0, 10); glVertex2f(10, 10); + glEnd(); + glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &val); + if (val != expected) { + printf( "Failed GL_INCR_WRAP test on iteration #%u " + "(got %u, expected %u)\n", i, val, expected ); + failed = GL_TRUE; + } + } + if ( !failed ) + printf("OK!\n"); + + /* test GL_DECR_WRAP_EXT (wrap-around) */ + glClearStencil(max); + glClear(GL_STENCIL_BUFFER_BIT); + glStencilOp(GL_KEEP, GL_KEEP, GL_DECR_WRAP_EXT); + failed = GL_FALSE; + printf("Testing GL_DECR_WRAP_EXT...\n"); + for (i = max-1; i > -10; i--) { + expected = (i < 0) ? max + i + 1: i; + glBegin(prim); + glVertex2f(0, 0); glVertex2f(10, 0); + glVertex2f(0, 10); glVertex2f(10, 10); + glEnd(); + glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &val); + if (val != expected) { + printf( "Failed GL_DECR_WRAP test on iteration #%u " + "(got %u, expected %u)\n", max - i, val, expected ); + failed = GL_TRUE; + } + } + if ( !failed ) + printf("OK!\n"); } - if ( !failed ) printf("OK!\n"); glDisable(GL_STENCIL_TEST); } @@ -158,7 +251,7 @@ static void Init( void ) /* Check for both the extension string and GL version 1.4 on the - * outside chance that some silly vendor exports version 1.4 but doesn't + * outside chance that some vendor exports version 1.4 but doesn't * export the extension string. The stencil-wrap modes are a required * part of GL 1.4. */ @@ -166,11 +259,9 @@ static void Init( void ) ver_str = glGetString( GL_VERSION ); version = (ver_str == NULL) ? 1.0 : atof( ver_str ); - if ( !glutExtensionSupported("GL_EXT_stencil_wrap") - && (version < 1.4) ) { - printf("Sorry, GL_EXT_stencil_wrap not supported.\n"); - exit(1); - } + wrapping = (glutExtensionSupported("GL_EXT_stencil_wrap") || (version >= 1.4)); + if (!wrapping) + printf("GL_EXT_stencil_wrap not supported. Only testing the rest.\n"); } |