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.
8 * Michel Dänzer July 2009 This program is in the public domain.
24 static GLuint numTexObj
;
25 static GLuint
*texObj
;
28 static void Idle( void )
34 static void DrawObject(void)
36 static const GLfloat tex_coords
[] = { 0.0, 0.0, 1.0, 1.0, 0.0 };
37 static const GLfloat vtx_coords
[] = { -1.0, -1.0, 1.0, 1.0, -1.0 };
40 glEnable(GL_TEXTURE_2D
);
42 for (i
= 0; i
< numTexObj
; i
++) {
43 glBindTexture(GL_TEXTURE_2D
, texObj
[i
]);
45 for (j
= 0; j
< 4; j
++ ) {
46 glTexCoord2f(tex_coords
[j
], tex_coords
[j
+1]);
47 glVertex2f( vtx_coords
[j
], vtx_coords
[j
+1] );
54 static void Display( void )
56 struct timeval start
, end
;
58 texObj
= realloc(texObj
, ++numTexObj
* sizeof(*texObj
));
60 /* allocate a texture object */
61 glGenTextures(1, texObj
+ (numTexObj
- 1));
63 glBindTexture(GL_TEXTURE_2D
, texObj
[numTexObj
- 1]);
64 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
65 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
66 memset(image
, (16 * numTexObj
) & 0xff, 4 * size
* size
);
67 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, size
, size
, 0,
68 GL_RGBA
, GL_UNSIGNED_BYTE
, image
);
70 gettimeofday(&start
, NULL
);
72 glClear( GL_COLOR_BUFFER_BIT
);
75 glScalef(5.0, 5.0, 5.0);
82 gettimeofday(&end
, NULL
);
83 printf("Rendering frame took %lu ms using %u MB of textures\n",
84 end
.tv_sec
* 1000 + end
.tv_usec
/ 1000 - start
.tv_sec
* 1000 -
85 start
.tv_usec
/ 1000, numTexObj
* 4 * size
/ 1024 * size
/ 1024);
91 static void Reshape( int width
, int height
)
93 glViewport( 0, 0, width
, height
);
94 glMatrixMode( GL_PROJECTION
);
96 glOrtho( -6.0, 6.0, -6.0, 6.0, 10.0, 100.0 );
97 glMatrixMode( GL_MODELVIEW
);
99 glTranslatef( 0.0, 0.0, -70.0 );
103 static void Init( int argc
, char *argv
[] )
105 glGetIntegerv(GL_MAX_TEXTURE_SIZE
, &size
);
106 printf("%d x %d max texture size\n", size
, size
);
108 image
= malloc(4 * size
* size
);
110 fprintf(stderr
, "Failed to allocate %u bytes of memory\n", 4 * size
* size
);
114 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
116 glShadeModel(GL_FLAT
);
117 glClearColor(0.3, 0.3, 0.4, 1.0);
123 int main( int argc
, char *argv
[] )
125 glutInit( &argc
, argv
);
126 glutInitWindowSize( 300, 300 );
127 glutInitWindowPosition( 0, 0 );
128 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
129 glutCreateWindow(argv
[0] );
134 glutReshapeFunc( Reshape
);
135 glutDisplayFunc( Display
);