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.6KB

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