Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stencilwrap.c 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* Test GL_EXT_stencil_wrap extension.
  2. * This is by no means complete, just a quick check.
  3. *
  4. * Brian Paul 30 October 2002
  5. */
  6. #include <assert.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <math.h>
  10. #include <GL/glut.h>
  11. static void RunTest(void)
  12. {
  13. const GLenum prim = GL_LINES;
  14. GLubyte val;
  15. int bits, max, i;
  16. glGetIntegerv(GL_STENCIL_BITS, &bits);
  17. max = (1 << bits) - 1;
  18. glClearStencil(0);
  19. glEnable(GL_STENCIL_TEST);
  20. glStencilFunc(GL_ALWAYS, 0, ~0);
  21. /* test GL_INCR (saturation) */
  22. glClear(GL_STENCIL_BUFFER_BIT);
  23. glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
  24. printf("Testing GL_INCR...\n");
  25. for (i = 1; i < max+10; i++) {
  26. int expected = (i > max) ? max : i;
  27. glBegin(prim);
  28. glVertex2f(0.5, 0.5); glVertex2f(9.5, 0.5);
  29. glEnd();
  30. glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &val);
  31. assert(val == expected);
  32. }
  33. printf("OK!\n");
  34. /* test GL_INCR_WRAP_EXT (wrap around) */
  35. glClear(GL_STENCIL_BUFFER_BIT);
  36. glStencilOp(GL_KEEP, GL_KEEP, GL_INCR_WRAP_EXT);
  37. printf("Testing GL_INCR_WRAP_EXT...\n");
  38. for (i = 1; i < max+10; i++) {
  39. int expected = i % (max + 1);
  40. glBegin(prim);
  41. glVertex2f(0.5, 0.5); glVertex2f(9.5, 0.5);
  42. glEnd();
  43. glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &val);
  44. assert(val == expected);
  45. }
  46. printf("OK!\n");
  47. glClearStencil(max);
  48. /* test GL_INCR (saturation) */
  49. glClear(GL_STENCIL_BUFFER_BIT);
  50. glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
  51. printf("Testing GL_DECR...\n");
  52. for (i = max-1; i > -10; i--) {
  53. int expected = (i < 0) ? 0 : i;
  54. glBegin(prim);
  55. glVertex2f(0.5, 0.5); glVertex2f(9.5, 0.5);
  56. glEnd();
  57. glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &val);
  58. assert(val == expected);
  59. }
  60. printf("OK!\n");
  61. /* test GL_INCR_WRAP_EXT (wrap-around) */
  62. glClear(GL_STENCIL_BUFFER_BIT);
  63. glStencilOp(GL_KEEP, GL_KEEP, GL_DECR_WRAP_EXT);
  64. printf("Testing GL_DECR_WRAP_EXT...\n");
  65. for (i = max-1; i > -10; i--) {
  66. int expected = (i < 0) ? max + i + 1: i;
  67. glBegin(prim);
  68. glVertex2f(0.5, 0.5); glVertex2f(9.5, 0.5);
  69. glEnd();
  70. glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &val);
  71. assert(val == expected);
  72. }
  73. printf("OK!\n");
  74. glDisable(GL_STENCIL_TEST);
  75. }
  76. static void Display( void )
  77. {
  78. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  79. RunTest();
  80. glutSwapBuffers();
  81. }
  82. static void Reshape( int width, int height )
  83. {
  84. glViewport( 0, 0, width, height );
  85. glMatrixMode( GL_PROJECTION );
  86. glLoadIdentity();
  87. glOrtho(0, width, 0, height, -1, 1);
  88. glMatrixMode( GL_MODELVIEW );
  89. glLoadIdentity();
  90. }
  91. static void Key( unsigned char key, int x, int y )
  92. {
  93. (void) x;
  94. (void) y;
  95. switch (key) {
  96. case 27:
  97. exit(0);
  98. break;
  99. }
  100. glutPostRedisplay();
  101. }
  102. static void Init( void )
  103. {
  104. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  105. printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  106. if (!glutExtensionSupported("GL_EXT_stencil_wrap")) {
  107. printf("Sorry, GL_EXT_stencil_wrap not supported.\n");
  108. exit(1);
  109. }
  110. }
  111. int main( int argc, char *argv[] )
  112. {
  113. glutInit( &argc, argv );
  114. glutInitWindowPosition( 0, 0 );
  115. glutInitWindowSize( 400, 400 );
  116. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_STENCIL );
  117. glutCreateWindow(argv[0]);
  118. glutReshapeFunc( Reshape );
  119. glutKeyboardFunc( Key );
  120. glutDisplayFunc( Display );
  121. Init();
  122. glutMainLoop();
  123. return 0;
  124. }