e06a28e08f2e1665250fd9d6d31a7df5ae3773ce
1 /* $Id: clearspd.c,v 1.3 2000/12/07 21:50:39 brianp 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.3 2000/12/07 21:50:39 brianp
11 * call glFinish() before getting t1 time
13 * Revision 1.2 2000/04/10 16:25:15 brianp
14 * fixed visual selection and reporting results
16 * Revision 1.1.1.1 1999/08/19 00:55:40 jtg
19 * Revision 3.3 1999/03/28 18:18:33 brianp
22 * Revision 3.2 1999/03/18 08:16:34 joukj
24 * cmpstr needs string.h to included to avoid warnings
26 * Revision 3.1 1998/06/29 02:38:30 brianp
27 * removed unneeded includes
29 * Revision 3.0 1998/02/14 18:42:29 brianp
42 static float MinPeriod
= 2.0; /* 2 seconds */
43 static int ColorMode
= GLUT_RGB
;
44 static int Width
= 400.0;
45 static int Height
= 400.0;
46 static int Loops
= 100;
47 static float ClearColor
= 0.0;
48 static GLbitfield BufferMask
= GL_COLOR_BUFFER_BIT
;
49 static GLboolean SwapFlag
= GL_FALSE
;
53 static void Idle( void )
59 static void Display( void )
66 glClearColor( ClearColor
, ClearColor
, ClearColor
, 0.0 );
72 t0
= glutGet(GLUT_ELAPSED_TIME
) * 0.001;
73 for (i
=0;i
<Loops
;i
++) {
74 glClear( BufferMask
);
78 t1
= glutGet(GLUT_ELAPSED_TIME
) * 0.001;
81 t0
= glutGet(GLUT_ELAPSED_TIME
) * 0.001;
82 for (i
=0;i
<Loops
;i
++) {
83 glClear( BufferMask
);
86 t1
= glutGet(GLUT_ELAPSED_TIME
) * 0.001;
90 if (t1
-t0
< MinPeriod
) {
91 /* Next time do more clears to get longer elapsed time */
96 clearRate
= Loops
/ (t1
-t0
);
97 pixelRate
= clearRate
* Width
* Height
;
99 printf("Rate: %d clears+swaps in %gs = %g clears+swaps/s %g pixels/s\n",
100 Loops
, t1
-t0
, clearRate
, pixelRate
);
103 printf("Rate: %d clears in %gs = %g clears/s %g pixels/s\n",
104 Loops
, t1
-t0
, clearRate
, pixelRate
);
109 static void Reshape( int width
, int height
)
113 glViewport( 0, 0, width
, height
);
114 glMatrixMode( GL_PROJECTION
);
116 glOrtho(0.0, width
, 0.0, height
, -1.0, 1.0);
117 glMatrixMode( GL_MODELVIEW
);
122 static void Key( unsigned char key
, int x
, int y
)
135 static void Init( int argc
, char *argv
[] )
138 for (i
=1; i
<argc
; i
++) {
139 if (strcmp(argv
[i
],"+rgb")==0)
140 ColorMode
= GLUT_RGB
;
141 else if (strcmp(argv
[i
],"+ci")==0)
142 ColorMode
= GLUT_INDEX
;
143 else if (strcmp(argv
[i
],"-color")==0)
145 else if (strcmp(argv
[i
],"+depth")==0)
146 BufferMask
|= GL_DEPTH_BUFFER_BIT
;
147 else if (strcmp(argv
[i
],"+alpha")==0)
148 ColorMode
= GLUT_RGB
| GLUT_ALPHA
;
149 else if (strcmp(argv
[i
],"+stencil")==0)
150 BufferMask
|= GL_STENCIL_BUFFER_BIT
;
151 else if (strcmp(argv
[i
],"+accum")==0)
152 BufferMask
|= GL_ACCUM_BUFFER_BIT
;
153 else if (strcmp(argv
[i
],"-width")==0) {
154 Width
= atoi(argv
[i
+1]);
157 else if (strcmp(argv
[i
],"-height")==0) {
158 Height
= atoi(argv
[i
+1]);
161 else if (strcmp(argv
[i
],"+swap")==0) {
164 else if (strcmp(argv
[i
],"-swap")==0) {
168 printf("Unknown option: %s\n", argv
[i
]);
171 if (ColorMode
& GLUT_ALPHA
)
172 printf("Mode: RGB + Alpha\n");
173 else if (ColorMode
==GLUT_RGB
)
174 printf("Mode: RGB\n");
176 printf("Mode: Color Index\n");
177 printf("SwapBuffers: %s\n", SwapFlag
? "yes" : "no" );
178 printf("Size: %d x %d\n", Width
, Height
);
180 if (BufferMask
& GL_COLOR_BUFFER_BIT
) printf("color ");
181 if (BufferMask
& GL_DEPTH_BUFFER_BIT
) printf("depth ");
182 if (BufferMask
& GL_STENCIL_BUFFER_BIT
) printf("stencil ");
183 if (BufferMask
& GL_ACCUM_BUFFER_BIT
) printf("accum ");
188 static void Help( const char *program
)
190 printf("%s options:\n", program
);
191 printf(" +rgb RGB mode\n");
192 printf(" +ci color index mode\n");
193 printf(" -color don't clear color buffer\n");
194 printf(" +alpha clear alpha buffer\n");
195 printf(" +depth clear depth buffer\n");
196 printf(" +stencil clear stencil buffer\n");
197 printf(" +accum clear accum buffer\n");
198 printf(" +swap also do SwapBuffers\n");
199 printf(" -swap don't do SwapBuffers\n");
203 int main( int argc
, char *argv
[] )
207 printf("For options: %s -help\n", argv
[0]);
211 glutInit( &argc
, argv
);
212 glutInitWindowSize( (int) Width
, (int) Height
);
213 glutInitWindowPosition( 0, 0 );
215 mode
= ColorMode
| GLUT_DOUBLE
;
216 if (BufferMask
& GL_STENCIL_BUFFER_BIT
)
217 mode
|= GLUT_STENCIL
;
218 if (BufferMask
& GL_ACCUM_BUFFER_BIT
)
220 if (BufferMask
& GL_DEPTH_BUFFER_BIT
)
223 glutInitDisplayMode(mode
);
225 glutCreateWindow( argv
[0] );
227 if (argc
==2 && strcmp(argv
[1],"-help")==0) {
232 glutReshapeFunc( Reshape
);
233 glutKeyboardFunc( Key
);
234 glutDisplayFunc( Display
);
235 glutIdleFunc( Idle
);