Rework SDL2 render driver selection.

The "direct3d" DX9 driver is no longer skipped by default.
There is a new --renderer=VALUE option to attempt to use the named
SDL2 render driver if present and compatible.
This commit is contained in:
Michael Martin
2020-07-11 15:34:21 -07:00
parent 36050dc2fa
commit 49a6612fea
6 changed files with 37 additions and 22 deletions
+2 -1
View File
@@ -63,7 +63,8 @@ extern int GfxFlags;
// The following functions are driver-defined // The following functions are driver-defined
void TFB_PreInit (void); void TFB_PreInit (void);
int TFB_InitGraphics (int driver, int flags, int width, int height); int TFB_InitGraphics (int driver, int flags, const char *renderer,
int width, int height);
int TFB_ReInitGraphics (int driver, int flags, int width, int height); int TFB_ReInitGraphics (int driver, int flags, int width, int height);
void TFB_UninitGraphics (void); void TFB_UninitGraphics (void);
void TFB_ProcessEvents (void); void TFB_ProcessEvents (void);
+7 -5
View File
@@ -237,7 +237,7 @@ TFB_Pure_ConfigureVideo (int driver, int flags, int width, int height, int toggl
} }
int int
TFB_Pure_InitGraphics (int driver, int flags, int width, int height) TFB_Pure_InitGraphics (int driver, int flags, const char *renderer, int width, int height)
{ {
char VideoName[256]; char VideoName[256];
@@ -245,10 +245,12 @@ TFB_Pure_InitGraphics (int driver, int flags, int width, int height)
SDL_VideoDriverName (VideoName, sizeof (VideoName)); SDL_VideoDriverName (VideoName, sizeof (VideoName));
log_add (log_Info, "SDL driver used: %s", VideoName); log_add (log_Info, "SDL driver used: %s", VideoName);
// Set the environment variable SDL_VIDEODRIVER to override (void) renderer;
// For Linux: x11 (default), dga, fbcon, directfb, svgalib, // The "renderer" argument is ignored by SDL1. To control how SDL1
// ggi, aalib // gets its pixmap, set the environment variable SDL_VIDEODRIVER.
// For Windows: directx (default), windib // For Linux: x11 (default), dga, fbcon, directfb, svgalib,
// ggi, aalib
// For Windows: directx (default), windib
log_add (log_Info, "SDL initialized."); log_add (log_Info, "SDL initialized.");
log_add (log_Info, "Initializing Screen."); log_add (log_Info, "Initializing Screen.");
+1 -1
View File
@@ -21,7 +21,7 @@
#include "libs/graphics/sdl/sdl_common.h" #include "libs/graphics/sdl/sdl_common.h"
int TFB_Pure_InitGraphics (int driver, int flags, int width, int height); int TFB_Pure_InitGraphics (int driver, int flags, const char *renderer, int width, int height);
void TFB_Pure_UninitGraphics (void); void TFB_Pure_UninitGraphics (void);
int TFB_Pure_ConfigureVideo (int driver, int flags, int width, int height, int togglefullscreen); int TFB_Pure_ConfigureVideo (int driver, int flags, int width, int height, int togglefullscreen);
void Scale_PerfTest (void); void Scale_PerfTest (void);
+12 -10
View File
@@ -34,6 +34,7 @@ static TFB_SDL2_SCREENINFO SDL2_Screens[TFB_GFX_NUMSCREENS];
static SDL_Window *window = NULL; static SDL_Window *window = NULL;
static SDL_Renderer *renderer = NULL; static SDL_Renderer *renderer = NULL;
static const char *rendererBackend = NULL;
static int ScreenFilterMode; static int ScreenFilterMode;
@@ -99,26 +100,26 @@ static int
FindBestRenderDriver (void) FindBestRenderDriver (void)
{ {
int i, n; int i, n;
if (!rendererBackend) {
/* If the user has no preference, just let SDL2 choose */
return -1;
}
n = SDL_GetNumRenderDrivers (); n = SDL_GetNumRenderDrivers ();
log_add (log_Info, "Searching for render driver \"%s\".", rendererBackend);
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
SDL_RendererInfo info; SDL_RendererInfo info;
if (SDL_GetRenderDriverInfo (i, &info) < 0) { if (SDL_GetRenderDriverInfo (i, &info) < 0) {
continue; continue;
} }
if (!strcmp(info.name, "direct3d")) { if (!strcmp(info.name, rendererBackend)) {
/* The 32-bit Windows 8+ Intel Integrated Graphics
* driver has a common bug that causes the D3D9
* display to crash with a divide-by-zero error.
* If we have any alternatives, we will ask for
* them instead. */
continue;
}
if (info.flags & SDL_RENDERER_ACCELERATED) {
return i; return i;
} }
log_add (log_Info, "Skipping render driver \"%s\"", info.name);
} }
/* We did not find any accelerated drivers that weren't D3D9. /* We did not find any accelerated drivers that weren't D3D9.
* Return -1 to ask SDL2 to do its best. */ * Return -1 to ask SDL2 to do its best. */
log_add (log_Info, "Render driver \"%s\" not available, using system default", rendererBackend);
return -1; return -1;
} }
@@ -265,7 +266,7 @@ TFB_Pure_ConfigureVideo (int driver, int flags, int width, int height, int toggl
} }
int int
TFB_Pure_InitGraphics (int driver, int flags, int width, int height) TFB_Pure_InitGraphics (int driver, int flags, const char *renderer, int width, int height)
{ {
log_add (log_Info, "Initializing SDL."); log_add (log_Info, "Initializing SDL.");
log_add (log_Info, "SDL initialized."); log_add (log_Info, "SDL initialized.");
@@ -273,6 +274,7 @@ TFB_Pure_InitGraphics (int driver, int flags, int width, int height)
ScreenWidth = 320; ScreenWidth = 320;
ScreenHeight = 240; ScreenHeight = 240;
rendererBackend = renderer;
if (TFB_Pure_ConfigureVideo (driver, flags, width, height, 0)) if (TFB_Pure_ConfigureVideo (driver, flags, width, height, 0))
{ {
+3 -3
View File
@@ -51,7 +51,7 @@ volatile int QuitPosted = 0;
volatile int GameActive = 1; // Track the SDL_ACTIVEEVENT state SDL_APPACTIVE volatile int GameActive = 1; // Track the SDL_ACTIVEEVENT state SDL_APPACTIVE
int int
TFB_InitGraphics (int driver, int flags, int width, int height) TFB_InitGraphics (int driver, int flags, const char *renderer, int width, int height)
{ {
int result, i; int result, i;
char caption[200]; char caption[200];
@@ -72,12 +72,12 @@ TFB_InitGraphics (int driver, int flags, int width, int height)
driver = TFB_GFXDRIVER_SDL_PURE; driver = TFB_GFXDRIVER_SDL_PURE;
log_add (log_Warning, "OpenGL support not compiled in," log_add (log_Warning, "OpenGL support not compiled in,"
" so using pure SDL driver"); " so using pure SDL driver");
result = TFB_Pure_InitGraphics (driver, flags, width, height); result = TFB_Pure_InitGraphics (driver, flags, renderer, width, height);
#endif #endif
} }
else else
{ {
result = TFB_Pure_InitGraphics (driver, flags, width, height); result = TFB_Pure_InitGraphics (driver, flags, renderer, width, height);
} }
#if SDL_MAJOR_VERSION == 1 #if SDL_MAJOR_VERSION == 1
+12 -2
View File
@@ -101,6 +101,8 @@ struct options_struct
const char *addonDir; const char *addonDir;
const char **addons; const char **addons;
int numAddons; int numAddons;
const char *graphicsBackend;
// Commandline and user config options // Commandline and user config options
DECL_CONFIG_OPTION(bool, opengl); DECL_CONFIG_OPTION(bool, opengl);
@@ -236,6 +238,7 @@ main (int argc, char *argv[])
/* .addonDir = */ NULL, /* .addonDir = */ NULL,
/* .addons = */ NULL, /* .addons = */ NULL,
/* .numAddons = */ 0, /* .numAddons = */ 0,
/* .graphicsBackend = */ NULL,
INIT_CONFIG_OPTION( opengl, false ), INIT_CONFIG_OPTION( opengl, false ),
INIT_CONFIG_OPTION2( resolution, 640, 480 ), INIT_CONFIG_OPTION2( resolution, 640, 480 ),
@@ -419,8 +422,8 @@ main (int argc, char *argv[])
gfxFlags |= TFB_GFXFLAGS_SCANLINES; gfxFlags |= TFB_GFXFLAGS_SCANLINES;
if (options.showFps.value) if (options.showFps.value)
gfxFlags |= TFB_GFXFLAGS_SHOWFPS; gfxFlags |= TFB_GFXFLAGS_SHOWFPS;
TFB_InitGraphics (gfxDriver, gfxFlags, options.resolution.width, TFB_InitGraphics (gfxDriver, gfxFlags, options.graphicsBackend,
options.resolution.height); options.resolution.width, options.resolution.height);
if (options.gamma.set && setGammaCorrection (options.gamma.value)) if (options.gamma.set && setGammaCorrection (options.gamma.value))
optGamma = options.gamma.value; optGamma = options.gamma.value;
else else
@@ -709,6 +712,7 @@ enum
ADDONDIR_OPT, ADDONDIR_OPT,
ACCEL_OPT, ACCEL_OPT,
SAFEMODE_OPT, SAFEMODE_OPT,
RENDERER_OPT,
#ifdef NETPLAY #ifdef NETPLAY
NETHOST1_OPT, NETHOST1_OPT,
NETPORT1_OPT, NETPORT1_OPT,
@@ -756,6 +760,7 @@ static struct option longOptions[] =
{"addondir", 1, NULL, ADDONDIR_OPT}, {"addondir", 1, NULL, ADDONDIR_OPT},
{"accel", 1, NULL, ACCEL_OPT}, {"accel", 1, NULL, ACCEL_OPT},
{"safe", 0, NULL, SAFEMODE_OPT}, {"safe", 0, NULL, SAFEMODE_OPT},
{"renderer", 1, NULL, RENDERER_OPT},
#ifdef NETPLAY #ifdef NETPLAY
{"nethost1", 1, NULL, NETHOST1_OPT}, {"nethost1", 1, NULL, NETHOST1_OPT},
{"netport1", 1, NULL, NETPORT1_OPT}, {"netport1", 1, NULL, NETPORT1_OPT},
@@ -1050,6 +1055,9 @@ parseOptions (int argc, char *argv[], struct options_struct *options)
case SAFEMODE_OPT: case SAFEMODE_OPT:
setBoolOption (&options->safeMode, true); setBoolOption (&options->safeMode, true);
break; break;
case RENDERER_OPT:
options->graphicsBackend = optarg;
break;
#ifdef NETPLAY #ifdef NETPLAY
case NETHOST1_OPT: case NETHOST1_OPT:
netplayOptions.peer[0].isServer = false; netplayOptions.peer[0].isServer = false;
@@ -1208,6 +1216,8 @@ usage (FILE *out, const struct options_struct *defaults)
"may be specified multiple times)"); "may be specified multiple times)");
log_add (log_User, " --addondir=ADDONDIR (directory where addons " log_add (log_User, " --addondir=ADDONDIR (directory where addons "
"reside)"); "reside)");
log_add (log_User, " --renderer=name (Select named rendering engine "
"if possible)");
log_add (log_User, " --sound=DRIVER (openal, mixsdl, none; default " log_add (log_User, " --sound=DRIVER (openal, mixsdl, none; default "
"mixsdl)"); "mixsdl)");
log_add (log_User, " --stereosfx (enables positional sound effects, " log_add (log_User, " --stereosfx (enables positional sound effects, "