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.

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