Clone of mesa.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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