c9a4e2630f87d940f90592f9fb2c527eef8b8d79
1 /* $Id: clearspd.c,v 1.5 2002/10/31 12:38:32 keithw Exp $ */
4 * Simple GLUT program to measure glClear() and glutSwapBuffers() speed.
5 * Brian Paul February 15, 1997 This file in public domain.
16 static float MinPeriod
= 2.0; /* 2 seconds */
17 static int ColorMode
= GLUT_RGB
;
18 static int Width
= 400.0;
19 static int Height
= 400.0;
20 static int Loops
= 100;
21 static float ClearColor
= 0.0;
22 static GLbitfield BufferMask
= GL_COLOR_BUFFER_BIT
;
23 static GLboolean SwapFlag
= GL_FALSE
;
27 static void Idle( void )
33 static void Display( void )
40 glClearColor( ClearColor
, ClearColor
, ClearColor
, 0.0 );
46 t0
= glutGet(GLUT_ELAPSED_TIME
) * 0.001;
47 for (i
=0;i
<Loops
;i
++) {
48 glClear( BufferMask
);
52 t1
= glutGet(GLUT_ELAPSED_TIME
) * 0.001;
55 t0
= glutGet(GLUT_ELAPSED_TIME
) * 0.001;
56 for (i
=0;i
<Loops
;i
++) {
57 glClear( BufferMask
);
60 t1
= glutGet(GLUT_ELAPSED_TIME
) * 0.001;
64 /* NOTE: If clearspd doesn't map it's window immediately on
65 * starting, swaps will be istantaneous, so this will send Loops
66 * towards infinity. When a window is finally mapped, it may be
67 * minutes before the first call to glutSwapBuffers, making it look
68 * like there's a driver bug.
70 if (t1
-t0
< MinPeriod
) {
71 /* Next time do more clears to get longer elapsed time */
76 clearRate
= Loops
/ (t1
-t0
);
77 pixelRate
= clearRate
* Width
* Height
;
79 printf("Rate: %d clears+swaps in %gs = %g clears+swaps/s %g pixels/s\n",
80 Loops
, t1
-t0
, clearRate
, pixelRate
);
83 printf("Rate: %d clears in %gs = %g clears/s %g pixels/s\n",
84 Loops
, t1
-t0
, clearRate
, pixelRate
);
89 static void Reshape( int width
, int height
)
93 glViewport( 0, 0, width
, height
);
94 glMatrixMode( GL_PROJECTION
);
96 glOrtho(0.0, width
, 0.0, height
, -1.0, 1.0);
97 glMatrixMode( GL_MODELVIEW
);
102 static void Key( unsigned char key
, int x
, int y
)
115 static void Init( int argc
, char *argv
[] )
118 for (i
=1; i
<argc
; i
++) {
119 if (strcmp(argv
[i
],"+rgb")==0)
120 ColorMode
= GLUT_RGB
;
121 else if (strcmp(argv
[i
],"+ci")==0)
122 ColorMode
= GLUT_INDEX
;
123 else if (strcmp(argv
[i
],"-color")==0)
125 else if (strcmp(argv
[i
],"+depth")==0)
126 BufferMask
|= GL_DEPTH_BUFFER_BIT
;
127 else if (strcmp(argv
[i
],"+alpha")==0)
128 ColorMode
= GLUT_RGB
| GLUT_ALPHA
;
129 else if (strcmp(argv
[i
],"+stencil")==0)
130 BufferMask
|= GL_STENCIL_BUFFER_BIT
;
131 else if (strcmp(argv
[i
],"+accum")==0)
132 BufferMask
|= GL_ACCUM_BUFFER_BIT
;
133 else if (strcmp(argv
[i
],"-width")==0) {
134 Width
= atoi(argv
[i
+1]);
137 else if (strcmp(argv
[i
],"-height")==0) {
138 Height
= atoi(argv
[i
+1]);
141 else if (strcmp(argv
[i
],"+swap")==0) {
144 else if (strcmp(argv
[i
],"-swap")==0) {
148 printf("Unknown option: %s\n", argv
[i
]);
151 if (ColorMode
& GLUT_ALPHA
)
152 printf("Mode: RGB + Alpha\n");
153 else if (ColorMode
==GLUT_RGB
)
154 printf("Mode: RGB\n");
156 printf("Mode: Color Index\n");
157 printf("SwapBuffers: %s\n", SwapFlag
? "yes" : "no" );
158 printf("Size: %d x %d\n", Width
, Height
);
160 if (BufferMask
& GL_COLOR_BUFFER_BIT
) printf("color ");
161 if (BufferMask
& GL_DEPTH_BUFFER_BIT
) printf("depth ");
162 if (BufferMask
& GL_STENCIL_BUFFER_BIT
) printf("stencil ");
163 if (BufferMask
& GL_ACCUM_BUFFER_BIT
) printf("accum ");
168 static void Help( const char *program
)
170 printf("%s options:\n", program
);
171 printf(" +rgb RGB mode\n");
172 printf(" +ci color index mode\n");
173 printf(" -color don't clear color buffer\n");
174 printf(" +alpha clear alpha buffer\n");
175 printf(" +depth clear depth buffer\n");
176 printf(" +stencil clear stencil buffer\n");
177 printf(" +accum clear accum buffer\n");
178 printf(" +swap also do SwapBuffers\n");
179 printf(" -swap don't do SwapBuffers\n");
183 int main( int argc
, char *argv
[] )
187 printf("For options: %s -help\n", argv
[0]);
191 glutInit( &argc
, argv
);
192 glutInitWindowSize( (int) Width
, (int) Height
);
193 glutInitWindowPosition( 0, 0 );
195 mode
= ColorMode
| GLUT_DOUBLE
;
196 if (BufferMask
& GL_STENCIL_BUFFER_BIT
)
197 mode
|= GLUT_STENCIL
;
198 if (BufferMask
& GL_ACCUM_BUFFER_BIT
)
200 if (BufferMask
& GL_DEPTH_BUFFER_BIT
)
203 glutInitDisplayMode(mode
);
205 glutCreateWindow( argv
[0] );
207 if (argc
==2 && strcmp(argv
[1],"-help")==0) {
212 glutReshapeFunc( Reshape
);
213 glutKeyboardFunc( Key
);
214 glutDisplayFunc( Display
);
215 glutIdleFunc( Idle
);