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.

clearspd.c 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /* $Id: clearspd.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
  2. /*
  3. * Simple GLUT program to measure glClear() and glutSwapBuffers() speed.
  4. * Brian Paul February 15, 1997 This file in public domain.
  5. */
  6. /*
  7. * $Log: clearspd.c,v $
  8. * Revision 1.1 1999/08/19 00:55:40 jtg
  9. * Initial revision
  10. *
  11. * Revision 3.3 1999/03/28 18:18:33 brianp
  12. * minor clean-up
  13. *
  14. * Revision 3.2 1999/03/18 08:16:34 joukj
  15. *
  16. * cmpstr needs string.h to included to avoid warnings
  17. *
  18. * Revision 3.1 1998/06/29 02:38:30 brianp
  19. * removed unneeded includes
  20. *
  21. * Revision 3.0 1998/02/14 18:42:29 brianp
  22. * initial rev
  23. *
  24. */
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <math.h>
  28. #include <string.h>
  29. #include <GL/glut.h>
  30. static float MinPeriod = 2.0; /* 2 seconds */
  31. static int ColorMode = GLUT_RGB;
  32. static int Width = 400.0;
  33. static int Height = 400.0;
  34. static int Loops = 100;
  35. static float ClearColor = 0.0;
  36. static GLbitfield BufferMask = GL_COLOR_BUFFER_BIT;
  37. static GLboolean SwapFlag = GL_FALSE;
  38. static void Idle( void )
  39. {
  40. glutPostRedisplay();
  41. }
  42. static void Display( void )
  43. {
  44. double t0, t1;
  45. double clearRate;
  46. double pixelRate;
  47. int i;
  48. glClearColor( ClearColor, ClearColor, ClearColor, 0.0 );
  49. ClearColor += 0.1;
  50. if (ClearColor>1.0)
  51. ClearColor = 0.0;
  52. if (SwapFlag) {
  53. t0 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
  54. for (i=0;i<Loops;i++) {
  55. glClear( BufferMask );
  56. glutSwapBuffers();
  57. }
  58. t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
  59. }
  60. else {
  61. t0 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
  62. for (i=0;i<Loops;i++) {
  63. glClear( BufferMask );
  64. }
  65. t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
  66. glutSwapBuffers();
  67. }
  68. if (t1-t0 < MinPeriod) {
  69. /* Next time do more clears to get longer elapsed time */
  70. Loops *= 2;
  71. return;
  72. }
  73. clearRate = Loops / (t1-t0);
  74. pixelRate = clearRate * Width * Height;
  75. if (SwapFlag) {
  76. printf("Rate: %d clears+swaps in %gs = %g clears+swaps/s %d pixels/s\n",
  77. Loops, t1-t0, clearRate, (int)pixelRate );
  78. }
  79. else {
  80. printf("Rate: %d clears in %gs = %g clears/s %d pixels/s\n",
  81. Loops, t1-t0, clearRate, (int)pixelRate);
  82. }
  83. }
  84. static void Reshape( int width, int height )
  85. {
  86. Width = width;
  87. Height = height;
  88. glViewport( 0, 0, width, height );
  89. glMatrixMode( GL_PROJECTION );
  90. glLoadIdentity();
  91. glOrtho(0.0, width, 0.0, height, -1.0, 1.0);
  92. glMatrixMode( GL_MODELVIEW );
  93. glLoadIdentity();
  94. }
  95. static void Key( unsigned char key, int x, int y )
  96. {
  97. (void) x;
  98. (void) y;
  99. switch (key) {
  100. case 27:
  101. exit(0);
  102. break;
  103. }
  104. glutPostRedisplay();
  105. }
  106. static void Init( int argc, char *argv[] )
  107. {
  108. int i;
  109. for (i=1; i<argc; i++) {
  110. if (strcmp(argv[i],"+rgb")==0)
  111. ColorMode = GLUT_RGB;
  112. else if (strcmp(argv[i],"+ci")==0)
  113. ColorMode = GLUT_INDEX;
  114. else if (strcmp(argv[i],"-color")==0)
  115. BufferMask = 0;
  116. else if (strcmp(argv[i],"+depth")==0)
  117. BufferMask |= GL_DEPTH_BUFFER_BIT;
  118. else if (strcmp(argv[i],"+alpha")==0)
  119. ColorMode = GLUT_RGB | GLUT_ALPHA;
  120. else if (strcmp(argv[i],"+stencil")==0)
  121. BufferMask |= GL_STENCIL_BUFFER_BIT;
  122. else if (strcmp(argv[i],"+accum")==0)
  123. BufferMask |= GL_ACCUM_BUFFER_BIT;
  124. else if (strcmp(argv[i],"-width")==0) {
  125. Width = atoi(argv[i+1]);
  126. i++;
  127. }
  128. else if (strcmp(argv[i],"-height")==0) {
  129. Height = atoi(argv[i+1]);
  130. i++;
  131. }
  132. else if (strcmp(argv[i],"+swap")==0) {
  133. SwapFlag = GL_TRUE;
  134. }
  135. else if (strcmp(argv[i],"-swap")==0) {
  136. SwapFlag = GL_FALSE;
  137. }
  138. else
  139. printf("Unknown option: %s\n", argv[i]);
  140. }
  141. if (ColorMode & GLUT_ALPHA)
  142. printf("Mode: RGB + Alpha\n");
  143. else if (ColorMode==GLUT_RGB)
  144. printf("Mode: RGB\n");
  145. else
  146. printf("Mode: Color Index\n");
  147. printf("SwapBuffers: %s\n", SwapFlag ? "yes" : "no" );
  148. printf("Size: %d x %d\n", Width, Height);
  149. printf("Buffers: ");
  150. if (BufferMask & GL_COLOR_BUFFER_BIT) printf("color ");
  151. if (BufferMask & GL_DEPTH_BUFFER_BIT) printf("depth ");
  152. if (BufferMask & GL_STENCIL_BUFFER_BIT) printf("stencil ");
  153. if (BufferMask & GL_ACCUM_BUFFER_BIT) printf("accum ");
  154. printf("\n");
  155. }
  156. static void Help( const char *program )
  157. {
  158. printf("%s options:\n", program);
  159. printf(" +rgb RGB mode\n");
  160. printf(" +ci color index mode\n");
  161. printf(" -color don't clear color buffer\n");
  162. printf(" +alpha clear alpha buffer\n");
  163. printf(" +depth clear depth buffer\n");
  164. printf(" +stencil clear stencil buffer\n");
  165. printf(" +accum clear accum buffer\n");
  166. printf(" +swap also do SwapBuffers\n");
  167. printf(" -swap don't do SwapBuffers\n");
  168. }
  169. int main( int argc, char *argv[] )
  170. {
  171. printf("For options: %s -help\n", argv[0]);
  172. Init( argc, argv );
  173. glutInit( &argc, argv );
  174. glutInitWindowSize( (int) Width, (int) Height );
  175. glutInitWindowPosition( 0, 0 );
  176. glutInitDisplayMode( ColorMode | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL | GLUT_ACCUM );
  177. glutCreateWindow( argv[0] );
  178. if (argc==2 && strcmp(argv[1],"-help")==0) {
  179. Help(argv[0]);
  180. return 0;
  181. }
  182. glutReshapeFunc( Reshape );
  183. glutKeyboardFunc( Key );
  184. glutDisplayFunc( Display );
  185. glutIdleFunc( Idle );
  186. glutMainLoop();
  187. return 0;
  188. }