Add code to switch render driver at runtime

This commit is contained in:
Benau 2021-04-23 21:21:39 +08:00
parent 6a24b5cb0e
commit 47011140a5
3 changed files with 34 additions and 10 deletions

View File

@ -692,6 +692,10 @@ namespace UserConfigParams
PARAM_DEFAULT( FloatUserConfigParam(3, "font_size",
&m_video_group, "The size of fonts. 0 is the smallest and 6 is the biggest") );
PARAM_PREFIX StringUserConfigParam m_render_driver
PARAM_DEFAULT( StringUserConfigParam("gl", "render_driver",
&m_video_group, "Render video driver to use, at the moment gl or directx9 is supported.") );
// ---- Recording
PARAM_PREFIX GroupUserConfigParam m_recording_group
PARAM_DEFAULT(GroupUserConfigParam("Recording",

View File

@ -388,6 +388,31 @@ void IrrDriver::initDevice()
{
SIrrlichtCreationParameters params;
video::E_DRIVER_TYPE driver_created = video::EDT_NULL;
if (std::string(UserConfigParams::m_render_driver) == "gl")
{
#if defined(USE_GLES2)
driver_created = video::EDT_OGLES2;
#else
driver_created = video::EDT_OPENGL;
#endif
}
else if (std::string(UserConfigParams::m_render_driver) == "directx9")
{
driver_created = video::EDT_DIRECT3D9;
}
else
{
Log::warn("IrrDriver", "Unknown driver %s, revert to gl",
UserConfigParams::m_render_driver.c_str());
UserConfigParams::m_render_driver.revertToDefaults();
#if defined(USE_GLES2)
driver_created = video::EDT_OGLES2;
#else
driver_created = video::EDT_OPENGL;
#endif
}
#ifndef __SWITCH__
// If --no-graphics option was used, the null device can still be used.
if (!GUIEngine::isNoGraphics())
@ -481,11 +506,7 @@ void IrrDriver::initDevice()
Log::verbose("irr_driver", "Trying to create device with "
"%i bits\n", bits);
#if defined(USE_GLES2)
params.DriverType = video::EDT_OGLES2;
#else
params.DriverType = video::EDT_OPENGL;
#endif
params.DriverType = driver_created;
params.PrivateData = NULL;
params.Stencilbuffer = false;
params.Bits = bits;
@ -543,11 +564,7 @@ void IrrDriver::initDevice()
{
UserConfigParams::m_width = MIN_SUPPORTED_WIDTH;
UserConfigParams::m_height = MIN_SUPPORTED_HEIGHT;
#if defined(USE_GLES2)
m_device = createDevice(video::EDT_OGLES2,
#else
m_device = createDevice(video::EDT_OPENGL,
#endif
m_device = createDevice(driver_created,
core::dimension2du(UserConfigParams::m_width,
UserConfigParams::m_height ),
32, //bits per pixel

View File

@ -684,6 +684,7 @@ void cmdLineHelp()
" Takes precedence over trilinear or bilinear\n"
" texture filtering.\n"
" --shadows=n Set resolution of shadows (0 to disable).\n"
" --render-driver=n Render driver to use (gl or directx9).\n"
" --apitrace This will disable buffer storage and\n"
" writing gpu query strings to opengl, which\n"
" can be seen later in apitrace.\n"
@ -836,6 +837,8 @@ int handleCmdLinePreliminary()
stk_config->load(file_manager->getAsset(s));
Log::info("main", "STK config will be read from %s.",s.c_str());
}
if(CommandLine::has("--render-driver", &s))
UserConfigParams::m_render_driver = s;
if(CommandLine::has("--trackdir", &s))
TrackManager::addTrackSearchDir(s);
if(CommandLine::has("--kartdir", &s))