diff --git a/gfx/gfx_common.c b/gfx/gfx_common.c index 3ff3b217b6..dd6e195675 100644 --- a/gfx/gfx_common.c +++ b/gfx/gfx_common.c @@ -79,11 +79,12 @@ static float tv_to_fps(const struct timeval *tv, const struct timeval *new_tv, i return frames/time; } -static unsigned gl_frames = 0; +static unsigned gl_frames; -static bool gfx_get_fps(char *buf, size_t size) +static bool gfx_get_fps(char *buf, size_t size, bool always_write) { static struct timeval tv; + static float last_fps; struct timeval new_tv; bool ret = false; @@ -99,15 +100,23 @@ static bool gfx_get_fps(char *buf, size_t size) struct timeval tmp_tv = tv; tv = new_tv; - float fps = tv_to_fps(&tmp_tv, &new_tv, 180); + last_fps = tv_to_fps(&tmp_tv, &new_tv, 180); #ifdef RARCH_CONSOLE - snprintf(buf, size, "FPS: %6.1f || Frames: %d", fps, gl_frames); + snprintf(buf, size, "FPS: %6.1f || Frames: %d", last_fps, gl_frames); #else - snprintf(buf, size, "%s || FPS: %6.1f || Frames: %d", g_extern.title_buf, fps, gl_frames); + snprintf(buf, size, "%s || FPS: %6.1f || Frames: %d", g_extern.title_buf, last_fps, gl_frames); #endif ret = true; } + else if (always_write) + { +#ifdef RARCH_CONSOLE + snprintf(buf, size, "FPS: %6.1f || Frames: %d", last_fps, gl_frames); +#else + snprintf(buf, size, "%s || FPS: %6.1f || Frames: %d", g_extern.title_buf, last_fps, gl_frames); +#endif + } return ret; } @@ -119,12 +128,18 @@ void gfx_window_title_reset(void) bool gfx_window_title(char *buf, size_t size) { - bool ret = gfx_get_fps(buf, size); + bool ret = gfx_get_fps(buf, size, false); gl_frames++; return ret; } +void gfx_fps_title(char *buf, size_t size) +{ + gfx_get_fps(buf, size, true); + gl_frames++; +} + #if defined(_WIN32) && !defined(_XBOX) #include #include "../dynamic.h" diff --git a/gfx/gfx_common.h b/gfx/gfx_common.h index 21028e5ab2..b3532e57a9 100644 --- a/gfx/gfx_common.h +++ b/gfx/gfx_common.h @@ -27,9 +27,13 @@ extern "C" { #include "../config.h" #endif +// Returns true if FPS value was updated. bool gfx_window_title(char *buf, size_t size); void gfx_window_title_reset(void); +// Like gfx_window_title, but always updates FPS value. +void gfx_fps_title(char *buf, size_t size); + #ifdef _WIN32 void gfx_set_dwm(void); #endif diff --git a/gfx/gl.c b/gfx/gl.c index ad58eef927..cba461f4bd 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -1121,8 +1121,8 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei bool fps_enable = g_extern.console.rmenu.state.msg_fps.enable; if (fps_enable) { - static char fps_txt[128]; - gfx_window_title(fps_txt, sizeof(fps_txt)); + char fps_txt[128]; + gfx_fps_title(fps_txt, sizeof(fps_txt)); gl_render_msg_place(gl, g_settings.video.msg_pos_x, 0.56f, 1.04f, WHITE, fps_txt); } #endif