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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. * Simple GLUT program to measure triangle strip rendering speed.
  3. * Brian Paul February 15, 1997 This file is in the public domain.
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <math.h>
  8. #include <string.h>
  9. #include <GL/glut.h>
  10. static float MinPeriod = 2.0; /* 2 seconds */
  11. static float Width = 400.0;
  12. static float Height = 400.0;
  13. static int Loops = 1;
  14. static int Size = 50;
  15. static int Texture = 0;
  16. static void Idle( void )
  17. {
  18. glutPostRedisplay();
  19. }
  20. static void Display( void )
  21. {
  22. float x, y;
  23. float xStep;
  24. float yStep;
  25. double t0, t1;
  26. double triRate;
  27. double pixelRate;
  28. int triCount;
  29. int i;
  30. float red[3] = { 1.0, 0.0, 0.0 };
  31. float blue[3] = { 0.0, 0.0, 1.0 };
  32. xStep = yStep = sqrt( 2.0 * Size );
  33. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  34. triCount = 0;
  35. t0 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
  36. if (Texture) {
  37. float uStep = xStep / Width;
  38. float vStep = yStep / Height;
  39. float u, v;
  40. for (i=0; i<Loops; i++) {
  41. for (y=1.0, v=0.0f; y<Height-yStep; y+=yStep, v+=vStep) {
  42. glBegin(GL_TRIANGLE_STRIP);
  43. for (x=1.0, u=0.0f; x<Width; x+=xStep, u+=uStep) {
  44. glColor3fv(red);
  45. glTexCoord2f(u, v);
  46. glVertex2f(x, y);
  47. glColor3fv(blue);
  48. glTexCoord2f(u, v+vStep);
  49. glVertex2f(x, y+yStep);
  50. triCount += 2;
  51. }
  52. glEnd();
  53. triCount -= 2;
  54. }
  55. }
  56. }
  57. else {
  58. for (i=0; i<Loops; i++) {
  59. for (y=1.0; y<Height-yStep; y+=yStep) {
  60. glBegin(GL_TRIANGLE_STRIP);
  61. for (x=1.0; x<Width; x+=xStep) {
  62. glColor3fv(red);
  63. glVertex2f(x, y);
  64. glColor3fv(blue);
  65. glVertex2f(x, y+yStep);
  66. triCount += 2;
  67. }
  68. glEnd();
  69. triCount -= 2;
  70. }
  71. }
  72. }
  73. glFinish();
  74. t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
  75. if (t1-t0 < MinPeriod) {
  76. /* Next time draw more triangles to get longer elapsed time */
  77. Loops *= 2;
  78. return;
  79. }
  80. triRate = triCount / (t1-t0);
  81. pixelRate = triRate * Size;
  82. printf("Rate: %d tri in %gs = %g tri/s %d pixels/s\n",
  83. triCount, t1-t0, triRate, (int)pixelRate);
  84. glutSwapBuffers();
  85. }
  86. static void Reshape( int width, int height )
  87. {
  88. Width = width;
  89. Height = height;
  90. glViewport( 0, 0, width, height );
  91. glMatrixMode( GL_PROJECTION );
  92. glLoadIdentity();
  93. glOrtho(0.0, width, 0.0, height, -1.0, 1.0);
  94. glMatrixMode( GL_MODELVIEW );
  95. glLoadIdentity();
  96. }
  97. static void Key( unsigned char key, int x, int y )
  98. {
  99. (void) x;
  100. (void) y;
  101. switch (key) {
  102. case 27:
  103. exit(0);
  104. break;
  105. }
  106. glutPostRedisplay();
  107. }
  108. static void LoadTex(int comp, int filter)
  109. {
  110. GLubyte *pixels;
  111. int x, y;
  112. pixels = (GLubyte *) malloc(4*256*256);
  113. for (y = 0; y < 256; ++y)
  114. for (x = 0; x < 256; ++x) {
  115. pixels[(y*256+x)*4+0] = (int)(128.5 + 127.0 * cos(0.024544 * x));
  116. pixels[(y*256+x)*4+1] = 255;
  117. pixels[(y*256+x)*4+2] = (int)(128.5 + 127.0 * cos(0.024544 * y));
  118. pixels[(y*256+x)*4+3] = 255;
  119. }
  120. glEnable(GL_TEXTURE_2D);
  121. glTexImage2D(GL_TEXTURE_2D, 0, comp, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
  122. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
  123. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
  124. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  125. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  126. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  127. printf("Texture: GL_MODULATE, %d comps, %s\n", comp, filter == GL_NEAREST ? "GL_NEAREST" : "GL_LINEAR");
  128. }
  129. static void Init( int argc, char *argv[] )
  130. {
  131. GLint shade;
  132. GLint rBits, gBits, bBits;
  133. int filter = GL_NEAREST, comp = 3;
  134. int i;
  135. for (i=1; i<argc; i++) {
  136. if (strcmp(argv[i],"-dither")==0)
  137. glDisable(GL_DITHER);
  138. else if (strcmp(argv[i],"+dither")==0)
  139. glEnable(GL_DITHER);
  140. else if (strcmp(argv[i],"+smooth")==0)
  141. glShadeModel(GL_SMOOTH);
  142. else if (strcmp(argv[i],"+flat")==0)
  143. glShadeModel(GL_FLAT);
  144. else if (strcmp(argv[i],"+depth")==0)
  145. glEnable(GL_DEPTH_TEST);
  146. else if (strcmp(argv[i],"-depth")==0)
  147. glDisable(GL_DEPTH_TEST);
  148. else if (strcmp(argv[i],"-size")==0) {
  149. Size = atoi(argv[i+1]);
  150. i++;
  151. }
  152. else if (strcmp(argv[i],"-texture")==0)
  153. Texture = 0;
  154. else if (strcmp(argv[i],"+texture")==0)
  155. Texture = 1;
  156. else if (strcmp(argv[i],"-linear")==0)
  157. filter = GL_NEAREST;
  158. else if (strcmp(argv[i],"+linear")==0)
  159. filter = GL_LINEAR;
  160. else if (strcmp(argv[i],"-persp")==0)
  161. glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
  162. else if (strcmp(argv[i],"+persp")==0)
  163. glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  164. else if (strcmp(argv[i],"-comp")==0) {
  165. comp = atoi(argv[i+1]);
  166. i++;
  167. }
  168. else
  169. printf("Unknown option: %s\n", argv[i]);
  170. }
  171. glGetIntegerv(GL_SHADE_MODEL, &shade);
  172. printf("Dither: %s\n", glIsEnabled(GL_DITHER) ? "on" : "off");
  173. printf("ShadeModel: %s\n", (shade==GL_FLAT) ? "flat" : "smooth");
  174. printf("DepthTest: %s\n", glIsEnabled(GL_DEPTH_TEST) ? "on" : "off");
  175. printf("Size: %d pixels\n", Size);
  176. if (Texture)
  177. LoadTex(comp, filter);
  178. glGetIntegerv(GL_RED_BITS, &rBits);
  179. glGetIntegerv(GL_GREEN_BITS, &gBits);
  180. glGetIntegerv(GL_BLUE_BITS, &bBits);
  181. printf("RedBits: %d GreenBits: %d BlueBits: %d\n", rBits, gBits, bBits);
  182. }
  183. static void Help( const char *program )
  184. {
  185. printf("%s options:\n", program);
  186. printf(" +/-dither enable/disable dithering\n");
  187. printf(" +/-depth enable/disable depth test\n");
  188. printf(" +flat flat shading\n");
  189. printf(" +smooth smooth shading\n");
  190. printf(" -size pixels specify pixels/triangle\n");
  191. printf(" +/-texture enable/disable texture\n");
  192. printf(" -comp n texture format\n");
  193. printf(" +/-linear bilinear texture filter\n");
  194. printf(" +/-persp perspective correction hint\n");
  195. }
  196. int main( int argc, char *argv[] )
  197. {
  198. printf("For options: %s -help\n", argv[0]);
  199. glutInit( &argc, argv );
  200. glutInitWindowSize( (int) Width, (int) Height );
  201. glutInitWindowPosition( 0, 0 );
  202. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
  203. glutCreateWindow( argv[0] );
  204. if (argc==2 && strcmp(argv[1],"-help")==0) {
  205. Help(argv[0]);
  206. return 0;
  207. }
  208. Init( argc, argv );
  209. glutReshapeFunc( Reshape );
  210. glutKeyboardFunc( Key );
  211. glutDisplayFunc( Display );
  212. glutIdleFunc( Idle );
  213. glutMainLoop();
  214. return 0;
  215. }