3
* Simple GLUT program to measure glClear() and glutSwapBuffers() speed.
4
* Brian Paul February 15, 1997 This file in public domain.
15
static float MinPeriod = 2.0; /* 2 seconds */
16
static int ColorMode = GLUT_RGB;
17
static int Width = 400.0;
18
static int Height = 400.0;
19
static int Loops = 100;
20
static float ClearColor = 0.0;
21
static GLbitfield BufferMask = GL_COLOR_BUFFER_BIT;
22
static GLboolean SwapFlag = GL_FALSE;
26
static void Idle( void )
32
static void Display( void )
39
glClearColor( ClearColor, ClearColor, ClearColor, 0.0 );
45
t0 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
46
for (i=0;i<Loops;i++) {
47
glClear( BufferMask );
51
t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
54
t0 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
55
for (i=0;i<Loops;i++) {
56
glClear( BufferMask );
59
t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
63
/* NOTE: If clearspd doesn't map it's window immediately on
64
* starting, swaps will be istantaneous, so this will send Loops
65
* towards infinity. When a window is finally mapped, it may be
66
* minutes before the first call to glutSwapBuffers, making it look
67
* like there's a driver bug.
69
if (t1-t0 < MinPeriod) {
70
/* Next time do more clears to get longer elapsed time */
75
clearRate = Loops / (t1-t0);
76
pixelRate = clearRate * Width * Height;
78
printf("Rate: %d clears+swaps in %gs = %g clears+swaps/s %g pixels/s\n",
79
Loops, t1-t0, clearRate, pixelRate );
82
printf("Rate: %d clears in %gs = %g clears/s %g pixels/s\n",
83
Loops, t1-t0, clearRate, pixelRate);
88
static void Reshape( int width, int height )
92
glViewport( 0, 0, width, height );
93
glMatrixMode( GL_PROJECTION );
95
glOrtho(0.0, width, 0.0, height, -1.0, 1.0);
96
glMatrixMode( GL_MODELVIEW );
101
static void Key( unsigned char key, int x, int y )
114
static void Init( int argc, char *argv[] )
117
for (i=1; i<argc; i++) {
118
if (strcmp(argv[i],"+rgb")==0)
119
ColorMode = GLUT_RGB;
120
else if (strcmp(argv[i],"+ci")==0)
121
ColorMode = GLUT_INDEX;
122
else if (strcmp(argv[i],"-color")==0)
124
else if (strcmp(argv[i],"+depth")==0)
125
BufferMask |= GL_DEPTH_BUFFER_BIT;
126
else if (strcmp(argv[i],"+alpha")==0)
127
ColorMode = GLUT_RGB | GLUT_ALPHA;
128
else if (strcmp(argv[i],"+stencil")==0)
129
BufferMask |= GL_STENCIL_BUFFER_BIT;
130
else if (strcmp(argv[i],"+accum")==0)
131
BufferMask |= GL_ACCUM_BUFFER_BIT;
132
else if (strcmp(argv[i],"-width")==0) {
133
Width = atoi(argv[i+1]);
136
else if (strcmp(argv[i],"-height")==0) {
137
Height = atoi(argv[i+1]);
140
else if (strcmp(argv[i],"+swap")==0) {
143
else if (strcmp(argv[i],"-swap")==0) {
147
printf("Unknown option: %s\n", argv[i]);
150
if (ColorMode & GLUT_ALPHA)
151
printf("Mode: RGB + Alpha\n");
152
else if (ColorMode==GLUT_RGB)
153
printf("Mode: RGB\n");
155
printf("Mode: Color Index\n");
156
printf("SwapBuffers: %s\n", SwapFlag ? "yes" : "no" );
157
printf("Size: %d x %d\n", Width, Height);
159
if (BufferMask & GL_COLOR_BUFFER_BIT) printf("color ");
160
if (BufferMask & GL_DEPTH_BUFFER_BIT) printf("depth ");
161
if (BufferMask & GL_STENCIL_BUFFER_BIT) printf("stencil ");
162
if (BufferMask & GL_ACCUM_BUFFER_BIT) printf("accum ");
167
static void Help( const char *program )
169
printf("%s options:\n", program);
170
printf(" +rgb RGB mode\n");
171
printf(" +ci color index mode\n");
172
printf(" -color don't clear color buffer\n");
173
printf(" +alpha clear alpha buffer\n");
174
printf(" +depth clear depth buffer\n");
175
printf(" +stencil clear stencil buffer\n");
176
printf(" +accum clear accum buffer\n");
177
printf(" +swap also do SwapBuffers\n");
178
printf(" -swap don't do SwapBuffers\n");
182
int main( int argc, char *argv[] )
186
printf("For options: %s -help\n", argv[0]);
190
glutInitWindowSize( (int) Width, (int) Height );
191
glutInit( &argc, argv );
193
mode = ColorMode | GLUT_DOUBLE;
194
if (BufferMask & GL_STENCIL_BUFFER_BIT)
195
mode |= GLUT_STENCIL;
196
if (BufferMask & GL_ACCUM_BUFFER_BIT)
198
if (BufferMask & GL_DEPTH_BUFFER_BIT)
201
glutInitDisplayMode(mode);
203
glutCreateWindow( argv[0] );
205
if (argc==2 && strcmp(argv[1],"-help")==0) {
210
glutReshapeFunc( Reshape );
211
glutKeyboardFunc( Key );
212
glutDisplayFunc( Display );
213
glutIdleFunc( Idle );