summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2009-08-07 14:43:06 -0700
committerEric Anholt <eric@anholt.net>2009-08-07 14:43:31 -0700
commit0abadf8012c486ef33fd4d62965ac6a575420119 (patch)
treef4d7025f8a322df0bcc9ad21a50dd086b44d6ebf
parent8756e79b2c884c5675dbc686c3d5a8e564e5a08f (diff)
Add a -benchmark mode.
-rw-r--r--glass.c44
1 files changed, 33 insertions, 11 deletions
diff --git a/glass.c b/glass.c
index 486b257..09f0fe4 100644
--- a/glass.c
+++ b/glass.c
@@ -116,7 +116,7 @@ float ring_bounding_sphere_radius;
static time_t start_tv_sec = 0;
static float start_time, cur_time, last_fps_time = 0;
-int no_multi_draw_arrays;
+int no_multi_draw_arrays = 0, benchmark = 0;
static int frames = 0, last_fps_frames = 0;
static SDL_Surface *sdl_surf = NULL;
static GLboolean done = GL_FALSE;
@@ -381,6 +381,19 @@ draw(void)
SDL_GL_SwapBuffers();
frames++;
+
+ if (benchmark && frames >= 5 * 60) {
+ float total_time;
+
+ glFinish();
+
+ total_time = get_time_in_secs() - start_time;
+ printf("%d frames in %.2f secs: %.1f fps\n",
+ frames,
+ total_time,
+ frames / total_time) ;
+ done = GL_TRUE;
+ }
}
static void
@@ -978,16 +991,23 @@ timer_callback(uint32_t interval, void *not_used)
static void
idle(void)
{
- cur_time = get_time_in_secs() - start_time;
+ static float bench_time = 0;
- if (cur_time > last_fps_time + 5) {
- printf("%d frames in %.2f secs: %.1f fps\n",
- frames - last_fps_frames,
- cur_time - last_fps_time,
- (frames - last_fps_frames) /
- (cur_time - last_fps_time));
- last_fps_time = cur_time;
- last_fps_frames = frames;
+ if (benchmark) {
+ cur_time = bench_time;
+ bench_time += 1.0 / 60.0;
+ } else {
+ cur_time = get_time_in_secs() - start_time;
+
+ if (cur_time > last_fps_time + 5) {
+ printf("%d frames in %.2f secs: %.1f fps\n",
+ frames - last_fps_frames,
+ cur_time - last_fps_time,
+ (frames - last_fps_frames) /
+ (cur_time - last_fps_time));
+ last_fps_time = cur_time;
+ last_fps_frames = frames;
+ }
}
}
@@ -1014,7 +1034,7 @@ key(SDLKey sym)
static void usage(char *program)
{
- fprintf(stderr, "usage: %s [-nomultidraw]\n", program);
+ fprintf(stderr, "usage: %s [-nomultidraw] [-benchmark]\n", program);
exit(1);
}
@@ -1089,6 +1109,8 @@ int main(int argc, char **argv)
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-nomultidraw") == 0)
no_multi_draw_arrays = 1;
+ if (strcmp(argv[i], "-benchmark") == 0)
+ benchmark = 1;
else
usage(argv[0]);
}