1 /* $Id: clearspd.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
4 * Simple GLUT program to measure glClear() and glutSwapBuffers() speed.
5 * Brian Paul February 15, 1997 This file in public domain.
10 * Revision 1.1 1999/08/19 00:55:40 jtg
13 * Revision 3.3 1999/03/28 18:18:33 brianp
16 * Revision 3.2 1999/03/18 08:16:34 joukj
18 * cmpstr needs string.h to included to avoid warnings
20 * Revision 3.1 1998/06/29 02:38:30 brianp
21 * removed unneeded includes
23 * Revision 3.0 1998/02/14 18:42:29 brianp
36 static float MinPeriod
= 2.0; /* 2 seconds */
37 static int ColorMode
= GLUT_RGB
;
38 static int Width
= 400.0;
39 static int Height
= 400.0;
40 static int Loops
= 100;
41 static float ClearColor
= 0.0;
42 static GLbitfield BufferMask
= GL_COLOR_BUFFER_BIT
;
43 static GLboolean SwapFlag
= GL_FALSE
;
47 static void Idle( void )
53 static void Display( void )
60 glClearColor( ClearColor
, ClearColor
, ClearColor
, 0.0 );
66 t0
= glutGet(GLUT_ELAPSED_TIME
) * 0.001;
67 for (i
=0;i
<Loops
;i
++) {
68 glClear( BufferMask
);
71 t1
= glutGet(GLUT_ELAPSED_TIME
) * 0.001;
74 t0
= glutGet(GLUT_ELAPSED_TIME
) * 0.001;
75 for (i
=0;i
<Loops
;i
++) {
76 glClear( BufferMask
);
78 t1
= glutGet(GLUT_ELAPSED_TIME
) * 0.001;
82 if (t1
-t0
< MinPeriod
) {
83 /* Next time do more clears to get longer elapsed time */
88 clearRate
= Loops
/ (t1
-t0
);
89 pixelRate
= clearRate
* Width
* Height
;
91 printf("Rate: %d clears+swaps in %gs = %g clears+swaps/s %d pixels/s\n",
92 Loops
, t1
-t0
, clearRate
, (int)pixelRate
);
95 printf("Rate: %d clears in %gs = %g clears/s %d pixels/s\n",
96 Loops
, t1
-t0
, clearRate
, (int)pixelRate
);
101 static void Reshape( int width
, int height
)
105 glViewport( 0, 0, width
, height
);
106 glMatrixMode( GL_PROJECTION
);
108 glOrtho(0.0, width
, 0.0, height
, -1.0, 1.0);
109 glMatrixMode( GL_MODELVIEW
);
114 static void Key( unsigned char key
, int x
, int y
)
127 static void Init( int argc
, char *argv
[] )
130 for (i
=1; i
<argc
; i
++) {
131 if (strcmp(argv
[i
],"+rgb")==0)
132 ColorMode
= GLUT_RGB
;
133 else if (strcmp(argv
[i
],"+ci")==0)
134 ColorMode
= GLUT_INDEX
;
135 else if (strcmp(argv
[i
],"-color")==0)
137 else if (strcmp(argv
[i
],"+depth")==0)
138 BufferMask
|= GL_DEPTH_BUFFER_BIT
;
139 else if (strcmp(argv
[i
],"+alpha")==0)
140 ColorMode
= GLUT_RGB
| GLUT_ALPHA
;
141 else if (strcmp(argv
[i
],"+stencil")==0)
142 BufferMask
|= GL_STENCIL_BUFFER_BIT
;
143 else if (strcmp(argv
[i
],"+accum")==0)
144 BufferMask
|= GL_ACCUM_BUFFER_BIT
;
145 else if (strcmp(argv
[i
],"-width")==0) {
146 Width
= atoi(argv
[i
+1]);
149 else if (strcmp(argv
[i
],"-height")==0) {
150 Height
= atoi(argv
[i
+1]);
153 else if (strcmp(argv
[i
],"+swap")==0) {
156 else if (strcmp(argv
[i
],"-swap")==0) {
160 printf("Unknown option: %s\n", argv
[i
]);
163 if (ColorMode
& GLUT_ALPHA
)
164 printf("Mode: RGB + Alpha\n");
165 else if (ColorMode
==GLUT_RGB
)
166 printf("Mode: RGB\n");
168 printf("Mode: Color Index\n");
169 printf("SwapBuffers: %s\n", SwapFlag
? "yes" : "no" );
170 printf("Size: %d x %d\n", Width
, Height
);
172 if (BufferMask
& GL_COLOR_BUFFER_BIT
) printf("color ");
173 if (BufferMask
& GL_DEPTH_BUFFER_BIT
) printf("depth ");
174 if (BufferMask
& GL_STENCIL_BUFFER_BIT
) printf("stencil ");
175 if (BufferMask
& GL_ACCUM_BUFFER_BIT
) printf("accum ");
180 static void Help( const char *program
)
182 printf("%s options:\n", program
);
183 printf(" +rgb RGB mode\n");
184 printf(" +ci color index mode\n");
185 printf(" -color don't clear color buffer\n");
186 printf(" +alpha clear alpha buffer\n");
187 printf(" +depth clear depth buffer\n");
188 printf(" +stencil clear stencil buffer\n");
189 printf(" +accum clear accum buffer\n");
190 printf(" +swap also do SwapBuffers\n");
191 printf(" -swap don't do SwapBuffers\n");
195 int main( int argc
, char *argv
[] )
197 printf("For options: %s -help\n", argv
[0]);
201 glutInit( &argc
, argv
);
202 glutInitWindowSize( (int) Width
, (int) Height
);
203 glutInitWindowPosition( 0, 0 );
205 glutInitDisplayMode( ColorMode
| GLUT_DOUBLE
| GLUT_DEPTH
| GLUT_STENCIL
| GLUT_ACCUM
);
207 glutCreateWindow( argv
[0] );
209 if (argc
==2 && strcmp(argv
[1],"-help")==0) {
214 glutReshapeFunc( Reshape
);
215 glutKeyboardFunc( Key
);
216 glutDisplayFunc( Display
);
217 glutIdleFunc( Idle
);