summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-11-09 16:53:05 -0800
committerVito Caputo <vcaputo@pengaru.com>2023-11-09 16:53:05 -0800
commitc223fca7a19190d8f662f3576947478ba4d2da57 (patch)
treef15e3ade5e4936ddabb1d3100c72aa3712cfb788
parent4d19ec621fccb73677ff9dc04f7a235155f6327d (diff)
sdl_fb: introduce vsync={on,off} setting
Defaults to on, controls inclusion of SDL_RENDERER_PRESENTVSYNC in the flags passed to SDL_CreateRenderer(). Useful for obesrving how high FPS can be with the overhead of the GPU upload, unlike --video=mem which tells you how fast FPS can be entirely headless.
-rw-r--r--src/sdl_fb.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/sdl_fb.c b/src/sdl_fb.c
index 184e679..64ea593 100644
--- a/src/sdl_fb.c
+++ b/src/sdl_fb.c
@@ -12,7 +12,8 @@
typedef struct sdl_fb_setup_t {
til_setup_t til_setup;
- int fullscreen;
+ int fullscreen:1;
+ int vsync:1;
unsigned width, height;
} sdl_fb_setup_t;
@@ -27,6 +28,7 @@ typedef struct sdl_fb_t {
const char *title;
unsigned width, height;
Uint32 window_flags;
+ Uint32 renderer_flags;
SDL_Window *window;
SDL_Renderer *renderer;
@@ -73,6 +75,9 @@ static int sdl_fb_init(const char *title, const til_setup_t *setup, void **res_c
c->window_flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
}
+ if (s->vsync)
+ c->renderer_flags = SDL_RENDERER_PRESENTVSYNC;
+
c->title = strdup(title);
if (!c->title) {
free(c);
@@ -134,7 +139,7 @@ static int sdl_fb_acquire(til_fb_t *fb, void *context, void *page)
if (!c->window)
return -1;
- c->renderer = SDL_CreateRenderer(c->window, -1, SDL_RENDERER_PRESENTVSYNC);
+ c->renderer = SDL_CreateRenderer(c->window, -1, c->renderer_flags);
if (!c->renderer)
return -1;
@@ -280,6 +285,7 @@ static int sdl_fb_setup(const til_settings_t *settings, til_setting_t **res_sett
NULL
};
til_setting_t *fullscreen;
+ til_setting_t *vsync;
til_setting_t *size;
int r;
@@ -298,6 +304,21 @@ static int sdl_fb_setup(const til_settings_t *settings, til_setting_t **res_sett
if (r)
return r;
+ r = til_settings_get_and_describe_setting(settings,
+ &(til_setting_spec_t){
+ .name = "SDL synchronize present with refresh rate",
+ .key = "vsync",
+ .regex = NULL,
+ .preferred = bool_values[1],
+ .values = bool_values,
+ .annotations = NULL
+ },
+ &vsync,
+ res_setting,
+ res_desc);
+ if (r)
+ return r;
+
if (!strcasecmp(fullscreen->value, "off")) {
r = til_settings_get_and_describe_setting(settings,
&(til_setting_spec_t){
@@ -349,6 +370,9 @@ static int sdl_fb_setup(const til_settings_t *settings, til_setting_t **res_sett
if (!strcasecmp(fullscreen->value, "on"))
setup->fullscreen = 1;
+ if (!strcasecmp(vsync->value, "on"))
+ setup->vsync = 1;
+
if (size && sscanf(size->value, "%u%*[xX]%u", &setup->width, &setup->height) != 2)
return til_setup_free_with_failed_setting_ret_err(&setup->til_setup, size, res_setting, -EINVAL);
© All Rights Reserved