From 5546f5c90462fad1325c0ab2efde5e7e34f1a9e7 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 17 Sep 2024 11:57:34 +0200 Subject: [PATCH] vdisp/sdl2: accept (and prefere) renderer name Accept renderer option given by a name in addeition to the index (which is still supported but no longer preferred/advertised). --- src/video_display/sdl2.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/video_display/sdl2.c b/src/video_display/sdl2.c index 9602ae724..a6e24dd1b 100644 --- a/src/video_display/sdl2.c +++ b/src/video_display/sdl2.c @@ -368,11 +368,12 @@ show_help(const char *driver) " " "(syntax: " TBOLD( "[x][{+-}[{+-}]]") ")\n"); - color_printf(TBOLD("\t ") " - renderer index: "); + color_printf(TBOLD("\t ") " - renderer, one of:"); for (int i = 0; i < SDL_GetNumRenderDrivers(); ++i) { SDL_RendererInfo renderer_info; if (SDL_GetRenderDriverInfo(i, &renderer_info) == 0) { - color_printf("%s" TBOLD("%d") " - " TBOLD("%s"), (i == 0 ? "" : ", "), i, renderer_info.name); + color_printf("%s" TBOLD("%s"), (i == 0 ? " " : ", "), + renderer_info.name); } } printf("\n"); @@ -617,7 +618,16 @@ get_renderer_idx(const char *renderer) return (int) number; } - MSG(ERROR, "Invalid renderer index %s\n", renderer); + for (int i = 0; i < renderer_cnt; ++i) { + SDL_RendererInfo renderer_info; + if (SDL_GetRenderDriverInfo(i, &renderer_info) == 0) { + if (strcmp(renderer, renderer_info.name) == 0) { + return i; + } + } + } + + MSG(ERROR, "Unknown renderer name: %s\n", renderer); return -2; }