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.

texleak.c 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * 'Texture leak' test
  3. *
  4. * Allocates and uses an additional texture of the maximum supported size for
  5. * each frame. This tests the system's ability to cope with using increasing
  6. * amounts of texture memory.
  7. *
  8. * Michel Dänzer July 2009 This program is in the public domain.
  9. */
  10. #include <math.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <sys/time.h>
  15. #include <unistd.h>
  16. #include <GL/glew.h>
  17. #include <GL/glut.h>
  18. GLint size;
  19. GLvoid *image;
  20. static GLuint numTexObj;
  21. static GLuint *texObj;
  22. static void Idle( void )
  23. {
  24. glutPostRedisplay();
  25. }
  26. static void DrawObject(void)
  27. {
  28. static const GLfloat tex_coords[] = { 0.0, 0.0, 1.0, 1.0, 0.0 };
  29. static const GLfloat vtx_coords[] = { -1.0, -1.0, 1.0, 1.0, -1.0 };
  30. GLint i, j;
  31. glEnable(GL_TEXTURE_2D);
  32. for (i = 0; i < numTexObj; i++) {
  33. glBindTexture(GL_TEXTURE_2D, texObj[i]);
  34. glBegin(GL_QUADS);
  35. for (j = 0; j < 4; j++ ) {
  36. glTexCoord2f(tex_coords[j], tex_coords[j+1]);
  37. glVertex2f( vtx_coords[j], vtx_coords[j+1] );
  38. }
  39. glEnd();
  40. }
  41. }
  42. static void Display( void )
  43. {
  44. struct timeval start, end;
  45. texObj = realloc(texObj, ++numTexObj * sizeof(*texObj));
  46. /* allocate a texture object */
  47. glGenTextures(1, texObj + (numTexObj - 1));
  48. glBindTexture(GL_TEXTURE_2D, texObj[numTexObj - 1]);
  49. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  50. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  51. memset(image, (16 * numTexObj) & 0xff, 4 * size * size);
  52. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size, size, 0,
  53. GL_RGBA, GL_UNSIGNED_BYTE, image);
  54. gettimeofday(&start, NULL);
  55. glClear( GL_COLOR_BUFFER_BIT );
  56. glPushMatrix();
  57. glScalef(5.0, 5.0, 5.0);
  58. DrawObject();
  59. glPopMatrix();
  60. glutSwapBuffers();
  61. glFinish();
  62. gettimeofday(&end, NULL);
  63. printf("Rendering frame took %lu ms using %u MB of textures\n",
  64. end.tv_sec * 1000 + end.tv_usec / 1000 - start.tv_sec * 1000 -
  65. start.tv_usec / 1000, numTexObj * 4 * size / 1024 * size / 1024);
  66. sleep(1);
  67. }
  68. static void Reshape( int width, int height )
  69. {
  70. glViewport( 0, 0, width, height );
  71. glMatrixMode( GL_PROJECTION );
  72. glLoadIdentity();
  73. glOrtho( -6.0, 6.0, -6.0, 6.0, 10.0, 100.0 );
  74. glMatrixMode( GL_MODELVIEW );
  75. glLoadIdentity();
  76. glTranslatef( 0.0, 0.0, -70.0 );
  77. }
  78. static void Init( int argc, char *argv[] )
  79. {
  80. glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size);
  81. printf("%d x %d max texture size\n", size, size);
  82. image = malloc(4 * size * size);
  83. if (!image) {
  84. fprintf(stderr, "Failed to allocate %u bytes of memory\n", 4 * size * size);
  85. exit(1);
  86. }
  87. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  88. glShadeModel(GL_FLAT);
  89. glClearColor(0.3, 0.3, 0.4, 1.0);
  90. Idle();
  91. }
  92. int main( int argc, char *argv[] )
  93. {
  94. glutInit( &argc, argv );
  95. glutInitWindowSize( 300, 300 );
  96. glutInitWindowPosition( 0, 0 );
  97. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
  98. glutCreateWindow(argv[0] );
  99. glewInit();
  100. Init( argc, argv );
  101. glutReshapeFunc( Reshape );
  102. glutDisplayFunc( Display );
  103. glutIdleFunc(Idle);
  104. glutMainLoop();
  105. return 0;
  106. }