[client] renderer: add ability to toggle the FPS display

Before, if you want to see the FPS, you need to close the client and
restart it with the -k switch to see the FPS. This is annoying.

This PR introduces a new keybind, ScrollLock+D, which, when pressed,
toggles the display of the FPS.

This is implemented for both EGL and OpenGL backends.
This commit is contained in:
Quantum
2021-01-31 22:09:03 -05:00
committed by Geoffrey McRae
parent b45f7a6733
commit 89b73512ad
10 changed files with 57 additions and 9 deletions

View File

@@ -499,6 +499,12 @@ void egl_on_help(void * opaque, const char * message)
egl_help_set_text(this->help, message);
}
void egl_on_show_fps(void * opaque, bool showFPS)
{
struct Inst * this = (struct Inst *)opaque;
egl_fps_set_display(this->fps, showFPS);
}
bool egl_render_startup(void * opaque)
{
struct Inst * this = (struct Inst *)opaque;
@@ -738,9 +744,6 @@ bool egl_render(void * opaque, LG_RendererRotate rotate)
void egl_update_fps(void * opaque, const float avgUPS, const float avgFPS)
{
struct Inst * this = (struct Inst *)opaque;
if (!this->params.showFPS)
return;
egl_fps_update(this->fps, avgUPS, avgFPS);
}
@@ -760,6 +763,7 @@ struct LG_Renderer LGR_EGL =
.on_frame = egl_on_frame,
.on_alert = egl_on_alert,
.on_help = egl_on_help,
.on_show_fps = egl_on_show_fps,
.render_startup = egl_render_startup,
.render = egl_render,
.update_fps = egl_update_fps

View File

@@ -42,6 +42,7 @@ struct EGL_FPS
EGL_Shader * shaderBG;
EGL_Model * model;
bool display;
bool ready;
int iwidth, iheight;
float width, height;
@@ -132,8 +133,16 @@ void egl_fps_free(EGL_FPS ** fps)
*fps = NULL;
}
void egl_fps_set_display(EGL_FPS * fps, bool display)
{
fps->display = display;
}
void egl_fps_update(EGL_FPS * fps, const float avgFPS, const float renderFPS)
{
if (!fps->display)
return;
char str[128];
snprintf(str, sizeof(str), "UPS: %8.4f, FPS: %8.4f", avgFPS, renderFPS);
@@ -174,7 +183,7 @@ void egl_fps_update(EGL_FPS * fps, const float avgFPS, const float renderFPS)
void egl_fps_render(EGL_FPS * fps, const float scaleX, const float scaleY)
{
if (!fps->ready)
if (!fps->display || !fps->ready)
return;
glEnable(GL_BLEND);

View File

@@ -28,5 +28,6 @@ typedef struct EGL_FPS EGL_FPS;
bool egl_fps_init(EGL_FPS ** fps, const LG_Font * font, LG_FontObj fontObj);
void egl_fps_free(EGL_FPS ** fps);
void egl_fps_set_display(EGL_FPS * fps, bool display);
void egl_fps_update(EGL_FPS * fps, const float avgUPS, const float avgFPS);
void egl_fps_render(EGL_FPS * fps, const float scaleX, const float scaleY);

View File

@@ -148,6 +148,7 @@ struct Inst
uint64_t waitFadeTime;
bool waitDone;
bool showFPS;
bool fpsTexture;
SDL_Rect fpsRect;
@@ -466,6 +467,12 @@ void opengl_on_help(void * opaque, const char * message)
// TODO: Implement this.
}
void opengl_on_show_fps(void * opaque, bool showFPS)
{
struct Inst * this = (struct Inst *)opaque;
this->showFPS = showFPS;
}
void bitmap_to_texture(LG_FontBitmap * bitmap, GLuint texture)
{
glBindTexture(GL_TEXTURE_2D , texture );
@@ -583,7 +590,7 @@ bool opengl_render(void * opaque, LG_RendererRotate rotate)
render_wait(this);
}
if (this->fpsTexture)
if (this->showFPS && this->fpsTexture)
glCallList(this->fpsList);
struct Alert * alert;
@@ -668,7 +675,7 @@ bool opengl_render(void * opaque, LG_RendererRotate rotate)
void opengl_update_fps(void * opaque, const float avgUPS, const float avgFPS)
{
struct Inst * this = (struct Inst *)opaque;
if (!this->params.showFPS)
if (!this->showFPS)
return;
char str[128];
@@ -829,6 +836,7 @@ const LG_Renderer LGR_OpenGL =
.on_frame = opengl_on_frame,
.on_alert = opengl_on_alert,
.on_help = opengl_on_help,
.on_show_fps = opengl_on_show_fps,
.render_startup = opengl_render_startup,
.render = opengl_render,
.update_fps = opengl_update_fps