X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=metrics.c;h=39ed5bacf2f9733010b5564893e76b9f7b0be1a1;hb=02c39fbdaa29d62a8e7b8d223f62ccd08d4782ee;hp=f4c0a2150f05b2092031a17907da231631b09bd4;hpb=c0c549440d852153d1777eca3fa962c1b70483b3;p=fips diff --git a/metrics.c b/metrics.c index f4c0a21..39ed5ba 100644 --- a/metrics.c +++ b/metrics.c @@ -24,8 +24,7 @@ #include -#define GL_GLEXT_PROTOTYPES -#include +#include "fips-dispatch-gl.h" #include "metrics.h" @@ -58,8 +57,11 @@ typedef struct context context_t current_context; +int frames; +int verbose; + unsigned -metrics_add_counter (void) +metrics_counter_new (void) { counter_t *counter; @@ -85,6 +87,18 @@ metrics_add_counter (void) return counter->id; } +void +metrics_counter_start (unsigned counter) +{ + glBeginQuery (GL_TIME_ELAPSED, counter); +} + +void +metrics_counter_stop (void) +{ + glEndQuery (GL_TIME_ELAPSED); +} + void metrics_set_current_program (unsigned program) { @@ -126,43 +140,43 @@ print_program_metrics (void) } } +/* Called at program exit */ +static void +metrics_exit (void) +{ + if (verbose) + printf ("fips: terminating\n"); +} + + void metrics_end_frame (void) { static int initialized = 0; - static int frames; static struct timeval tv_start, tv_now; if (! initialized) { - frames = 0; gettimeofday (&tv_start, NULL); + atexit (metrics_exit); + if (getenv ("FIPS_VERBOSE")) + verbose = 1; initialized = 1; } + if (verbose) + printf ("fips: frame %d complete\n", frames); frames++; - - if (frames % 60 == 0) { - double fps; - gettimeofday (&tv_now, NULL); - - fps = (double) frames / (tv_now.tv_sec - tv_start.tv_sec + - (tv_now.tv_usec - tv_start.tv_usec) / 1.0e6); - - printf("FPS: %.3f\n", fps); - - print_program_metrics (); - } + gettimeofday (&tv_now, NULL); /* Consume all counters that are ready. */ counter_t *counter = current_context.counter_head; while (counter) { - GLint available; - GLuint elapsed; + GLuint available, elapsed; - glGetQueryObjectiv (counter->id, GL_QUERY_RESULT_AVAILABLE, - &available); + glGetQueryObjectuiv (counter->id, GL_QUERY_RESULT_AVAILABLE, + &available); if (! available) break; @@ -179,4 +193,15 @@ metrics_end_frame (void) free (counter); counter = current_context.counter_head; } + + if (frames % 60 == 0) { + double fps; + + fps = (double) frames / (tv_now.tv_sec - tv_start.tv_sec + + (tv_now.tv_usec - tv_start.tv_usec) / 1.0e6); + + printf("FPS: %.3f\n", fps); + + print_program_metrics (); + } }