[client] add -g option to force a specific renderer

This commit is contained in:
Geoffrey McRae 2017-12-17 23:15:18 +11:00
parent 065b8c1eab
commit 313a4122bc

View File

@ -90,6 +90,8 @@ struct AppParams
bool hideMouse; bool hideMouse;
bool ignoreQuit; bool ignoreQuit;
bool forceRenderer;
unsigned int forceRendererIndex;
RendererOpts rendererOpts[LG_RENDERER_COUNT]; RendererOpts rendererOpts[LG_RENDERER_COUNT];
}; };
@ -113,7 +115,8 @@ struct AppParams params =
.spicePort = 5900, .spicePort = 5900,
.scaleMouseInput = true, .scaleMouseInput = true,
.hideMouse = true, .hideMouse = true,
.ignoreQuit = false .ignoreQuit = false,
.forceRenderer = false
}; };
inline void updatePositionInfo() inline void updatePositionInfo()
@ -663,6 +666,37 @@ void intHandler(int signal)
} }
} }
static bool try_renderer(const int index, const LG_RendererParams lgrParams, Uint32 * sdlFlags)
{
const LG_Renderer *r = LG_Renderers[index];
RendererOpts *opts = &params.rendererOpts[index];
if (!IS_LG_RENDERER_VALID(r))
{
DEBUG_ERROR("FIXME: Renderer %d is invalid, skipping", index);
return false;
}
// create the renderer
state.lgrData = NULL;
if (!r->create(&state.lgrData, lgrParams))
return false;
// set it's options
for(unsigned int i = 0; i < opts->argc; ++i)
opts->argv[i].opt->handler(state.lgrData, opts->argv[i].value);
// initialize the renderer
if (!r->initialize(state.lgrData, sdlFlags))
{
r->deinitialize(state.lgrData);
return false;
}
DEBUG_INFO("Using Renderer: %s", r->get_name());
return true;
}
int run() int run()
{ {
DEBUG_INFO("Looking Glass (" BUILD_VERSION ")"); DEBUG_INFO("Looking Glass (" BUILD_VERSION ")");
@ -726,39 +760,31 @@ int run()
lgrParams.showFPS = params.showFPS; lgrParams.showFPS = params.showFPS;
Uint32 sdlFlags; Uint32 sdlFlags;
if (params.forceRenderer)
{
DEBUG_INFO("Trying forced renderer");
sdlFlags = 0;
if (!try_renderer(params.forceRendererIndex, lgrParams, &sdlFlags))
{
DEBUG_ERROR("Forced renderer failed to iniailize");
return -1;
}
state.lgr = LG_Renderers[params.forceRendererIndex];
}
else
{
// probe for a a suitable renderer // probe for a a suitable renderer
for(unsigned int i = 0; i < LG_RENDERER_COUNT; ++i) for(unsigned int i = 0; i < LG_RENDERER_COUNT; ++i)
{ {
const LG_Renderer *r = LG_Renderers[i];
RendererOpts *opts = &params.rendererOpts[i];
if (!IS_LG_RENDERER_VALID(r))
{
DEBUG_ERROR("FIXME: Renderer %d is invalid, skipping", i);
continue;
}
// create the renderer
state.lgrData = NULL;
if (!r->create(&state.lgrData, lgrParams))
continue;
// set it's options
for(unsigned int i = 0; i < opts->argc; ++i)
opts->argv[i].opt->handler(state.lgrData, opts->argv[i].value);
// initialize the renderer
sdlFlags = 0; sdlFlags = 0;
if (!r->initialize(state.lgrData, &sdlFlags)) if (try_renderer(i, lgrParams, &sdlFlags))
{ {
r->deinitialize(state.lgrData); state.lgr = LG_Renderers[i];
continue; DEBUG_INFO("Using: %s", state.lgr->get_name());
}
state.lgr = r;
DEBUG_INFO("Initialized %s", r->get_name());
break; break;
} }
}
}
if (!state.lgr) if (!state.lgr)
{ {
@ -950,6 +976,7 @@ void doHelp(char * app)
" -M Don't hide the host cursor\n" " -M Don't hide the host cursor\n"
"\n" "\n"
" -k Enable FPS display\n" " -k Enable FPS display\n"
" -g NAME Force the use of a specific renderer\n"
" -o FLAG Specify a renderer option (ie: opengl:vsync=0)\n" " -o FLAG Specify a renderer option (ie: opengl:vsync=0)\n"
" Alternatively specify \"list\" to list all renderers and their options\n" " Alternatively specify \"list\" to list all renderers and their options\n"
"\n" "\n"
@ -1005,7 +1032,7 @@ void doLicense()
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
int c; int c;
while((c = getopt(argc, argv, "hf:sc:p:jMvko:anrdFx:y:w:b:Ql")) != -1) while((c = getopt(argc, argv, "hf:sc:p:jMvkg:o:anrdFx:y:w:b:Ql")) != -1)
switch(c) switch(c)
{ {
case '?': case '?':
@ -1042,6 +1069,29 @@ int main(int argc, char * argv[])
params.showFPS = true; params.showFPS = true;
break; break;
case 'g':
{
bool ok = false;
for(unsigned int i = 0; i < LG_RENDERER_COUNT; ++i)
if (strcasecmp(LG_Renderers[i]->get_name(), optarg) == 0)
{
params.forceRenderer = true;
params.forceRendererIndex = i;
ok = true;
break;
}
if (!ok)
{
fprintf(stderr, "No such renderer: %s\n", optarg);
fprintf(stderr, "Use '-o list' obtain a list of options\n");
doHelp(argv[0]);
return -1;
}
break;
}
case 'o': case 'o':
{ {
if (strcasecmp(optarg, "list") == 0) if (strcasecmp(optarg, "list") == 0)