X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=hacks%2Fglx%2Ffps.c;h=237ef1fef6daf9bab1a6d5d79e6e9af977727e7d;hb=96a411663168b0ba5432b407a83be55f3df0c802;hp=2b91bbfeb40f734e23e1980ee2c1a9546261e4e7;hpb=3f9592851ce4ed76a9979bfdd6ec7dc5c457e183;p=xscreensaver diff --git a/hacks/glx/fps.c b/hacks/glx/fps.c index 2b91bbfe..237ef1fe 100644 --- a/hacks/glx/fps.c +++ b/hacks/glx/fps.c @@ -34,6 +34,7 @@ static int fps_text_y = 10; static int fps_ascent, fps_descent; static GLuint font_dlist; static Bool fps_clear_p = False; +static char fps_string[1024]; static void fps_init (ModeInfo *mi) @@ -153,7 +154,7 @@ fps_print_string (ModeInfo *mi, GLfloat x, GLfloat y, const char *string) L2++; glCallLists (strlen(L2), GL_UNSIGNED_BYTE, L2); glRasterPos2f (x, y + (fps_ascent + fps_descent)); - glCallLists (L2 - string, GL_UNSIGNED_BYTE, string); + glCallLists (L2 - string - 1, GL_UNSIGNED_BYTE, string); } else { @@ -178,21 +179,21 @@ fps_print_string (ModeInfo *mi, GLfloat x, GLfloat y, const char *string) } -void -do_fps (ModeInfo *mi) +GLfloat +fps_1 (ModeInfo *mi) { static Bool initted_p = False; - static int last_ifps = 0; + static int last_ifps = -1; + static GLfloat last_fps = -1; static int frame_count = 0; - static struct timeval prev = { 0, }; - static struct timeval now = { 0, }; - static char msg [1024] = { 0, }; + static struct timeval prev = { 0, 0 }; + static struct timeval now = { 0, 0 }; if (!initted_p) { initted_p = True; fps_init (mi); - strcpy (msg, "FPS: (accumulating...)"); + strcpy (fps_string, "FPS: (accumulating...)"); } /* Every N frames (where N is approximately one second's worth of frames) @@ -223,8 +224,9 @@ do_fps (ModeInfo *mi) prev = now; frame_count = 0; last_ifps = fps; + last_fps = fps; - sprintf (msg, "FPS: %.02f", fps); + sprintf (fps_string, "FPS: %.02f", fps); if (mi->pause != 0) { @@ -234,7 +236,8 @@ do_fps (ModeInfo *mi) buf[strlen(buf)-1] = 0; if (buf[strlen(buf)-1] == '.') buf[strlen(buf)-1] = 0; - sprintf(msg + strlen(msg), " (including %s sec/frame delay)", + sprintf(fps_string + strlen(fps_string), + " (including %s sec/frame delay)", buf); } @@ -247,19 +250,31 @@ do_fps (ModeInfo *mi) else if (p >= 2048) p >>= 10, s = "K"; # endif - strcat (msg, "\nPolys: "); + strcat (fps_string, "\nPolys: "); if (p >= 1000000) - sprintf (msg + strlen(msg), "%d,%03d,%03d%s", + sprintf (fps_string + strlen(fps_string), "%lu,%03lu,%03lu%s", (p / 1000000), ((p / 1000) % 1000), (p % 1000), s); else if (p >= 1000) - sprintf (msg + strlen(msg), "%d,%03d%s", + sprintf (fps_string + strlen(fps_string), "%lu,%03lu%s", (p / 1000), (p % 1000), s); else - sprintf (msg + strlen(msg), "%d%s", p, s); + sprintf (fps_string + strlen(fps_string), "%lu%s", p, s); } } - /* Print the string every frame (or else nothing will show up.) - */ - fps_print_string (mi, fps_text_x, fps_text_y, msg); + return last_fps; +} + +void +fps_2 (ModeInfo *mi) +{ + fps_print_string (mi, fps_text_x, fps_text_y, fps_string); +} + + +void +do_fps (ModeInfo *mi) +{ + fps_1 (mi); /* Lazily compute current FPS value, about once a second. */ + fps_2 (mi); /* Print the string every frame (else nothing shows up.) */ }