Clone of mesa.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

trispd.c 7.0KB

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