Skip to content

Commit

Permalink
vdisp/sdl2: accept (and prefere) renderer name
Browse files Browse the repository at this point in the history
Accept renderer option given by a name in addeition to the index (which
is still supported but no longer preferred/advertised).
  • Loading branch information
MartinPulec committed Sep 17, 2024
1 parent eacf6bf commit 5546f5c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/video_display/sdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,12 @@ show_help(const char *driver)
" "
"(syntax: " TBOLD(
"[<W>x<H>][{+-}<X>[{+-}<Y>]]") ")\n");
color_printf(TBOLD("\t <ridx>") " - renderer index: ");
color_printf(TBOLD("\t <renderer>") " - 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");
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 5546f5c

Please sign in to comment.