From c26e122485a7180edf434c0c1211713ff377d6d7 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 5 Mar 2023 15:55:00 +0100 Subject: [PATCH] Move video_driver default selection to runtime --- builtin/mainmenu/tab_settings.lua | 2 +- builtin/settingtypes.txt | 2 +- doc/menu_lua_api.txt | 5 ++- src/client/renderingengine.cpp | 39 ++++++++++++--------- src/client/shadows/dynamicshadowsrender.cpp | 2 +- src/defaultsettings.cpp | 6 +--- src/script/lua_api/l_mainmenu.cpp | 10 +++++- src/script/lua_api/l_mainmenu.h | 2 ++ 8 files changed, 41 insertions(+), 27 deletions(-) diff --git a/builtin/mainmenu/tab_settings.lua b/builtin/mainmenu/tab_settings.lua index ec2d7b1f5..404286acf 100644 --- a/builtin/mainmenu/tab_settings.lua +++ b/builtin/mainmenu/tab_settings.lua @@ -171,7 +171,7 @@ local function formspec(tabview, name, tabdata) .. getSettingIndex.Antialiasing() .. "]" .. "box[8,0;3.75,4.5;#999999]" - local video_driver = core.settings:get("video_driver") + local video_driver = core.get_active_driver() local shaders_enabled = core.settings:get_bool("enable_shaders") if video_driver == "opengl" then tab_string = tab_string .. diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 054c37bd2..9d4de64d9 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -1664,7 +1664,7 @@ shader_path (Shader path) path # Note: A restart is required after changing this! # OpenGL is the default for desktop, and OGLES2 for Android. # Shaders are supported by OpenGL and OGLES2 (experimental). -video_driver (Video driver) enum opengl opengl,ogles1,ogles2 +video_driver (Video driver) enum opengl,ogles1,ogles2, # Distance in nodes at which transparency depth sorting is enabled # Use this to limit the performance impact of transparency depth sorting diff --git a/doc/menu_lua_api.txt b/doc/menu_lua_api.txt index d65e9c83f..e4c5cd359 100644 --- a/doc/menu_lua_api.txt +++ b/doc/menu_lua_api.txt @@ -203,7 +203,10 @@ GUI will be added to fieldname value is set to formname itself * if `is_file_select` is `true`, a file and not a folder will be selected * returns nil or selected file/folder -* `core.get_active_renderer()`: Ex: "OpenGL 4.6". +* `core.get_active_driver()`: + * technical name of active video driver, e.g. "opengl" +* `core.get_active_renderer()`: + * name of current renderer, e.g. "OpenGL 4.6" * `core.get_window_info()`: Same as server-side `get_player_window_information` API. -- Note that none of these things are constant, they are likely to change diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index e12833c21..1392b5567 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -99,22 +99,27 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver) u16 fsaa = g_settings->getU16("fsaa"); // Determine driver - video::E_DRIVER_TYPE driverType = video::EDT_OPENGL; + video::E_DRIVER_TYPE driverType; const std::string &driverstring = g_settings->get("video_driver"); std::vector drivers = RenderingEngine::getSupportedVideoDrivers(); u32 i; for (i = 0; i != drivers.size(); i++) { - if (!strcasecmp(driverstring.c_str(), - RenderingEngine::getVideoDriverInfo(drivers[i]).name.c_str())) { + auto &driverinfo = RenderingEngine::getVideoDriverInfo(drivers[i]); + if (!strcasecmp(driverstring.c_str(), driverinfo.name.c_str())) { driverType = drivers[i]; break; } } if (i == drivers.size()) { - errorstream << "Invalid video_driver specified; " - "defaulting to opengl" - << std::endl; + driverType = drivers.at(0); + auto &name = RenderingEngine::getVideoDriverInfo(driverType).name; + if (driverstring.empty()) { + infostream << "Defaulting to video_driver = " << name << std::endl; + } else { + errorstream << "Invalid video_driver specified; defaulting to " + << name << std::endl; + } } SIrrlichtCreationParameters params = SIrrlichtCreationParameters(); @@ -517,20 +522,20 @@ void RenderingEngine::draw_menu_scene(gui::IGUIEnvironment *guienv, get_video_driver()->endScene(); } -std::vector RenderingEngine::getSupportedVideoDrivers() +std::vector RenderingEngine::getSupportedVideoDrivers() { - // Only check these drivers. - // We do not support software and D3D in any capacity. - static const irr::video::E_DRIVER_TYPE glDrivers[4] = { - irr::video::EDT_NULL, - irr::video::EDT_OPENGL, - irr::video::EDT_OGLES1, - irr::video::EDT_OGLES2, + // Only check these drivers. We do not support software and D3D in any capacity. + // Order by preference (best first) + static const video::E_DRIVER_TYPE glDrivers[] = { + video::EDT_OPENGL, + video::EDT_OGLES2, + video::EDT_OGLES1, + video::EDT_NULL, }; - std::vector drivers; + std::vector drivers; - for (int i = 0; i < 4; i++) { - if (irr::IrrlichtDevice::isDriverSupported(glDrivers[i])) + for (u32 i = 0; i < ARRLEN(glDrivers); i++) { + if (IrrlichtDevice::isDriverSupported(glDrivers[i])) drivers.push_back(glDrivers[i]); } diff --git a/src/client/shadows/dynamicshadowsrender.cpp b/src/client/shadows/dynamicshadowsrender.cpp index ebdd1d2af..740edfe21 100644 --- a/src/client/shadows/dynamicshadowsrender.cpp +++ b/src/client/shadows/dynamicshadowsrender.cpp @@ -700,7 +700,7 @@ ShadowRenderer *createShadowRenderer(IrrlichtDevice *device, Client *client) { // disable if unsupported if (g_settings->getBool("enable_dynamic_shadows") && ( - g_settings->get("video_driver") != "opengl" || + device->getVideoDriver()->getDriverType() != video::EDT_OPENGL || !g_settings->getBool("enable_shaders"))) { g_settings->setBool("enable_dynamic_shadows", false); } diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 29449d9d0..ed9363a72 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -207,11 +207,7 @@ void set_default_settings() settings->setDefault("lighting_boost_spread", "0.2"); settings->setDefault("texture_path", ""); settings->setDefault("shader_path", ""); -#if ENABLE_GLES - settings->setDefault("video_driver", "ogles2"); -#else - settings->setDefault("video_driver", "opengl"); -#endif + settings->setDefault("video_driver", ""); settings->setDefault("cinematic", "false"); settings->setDefault("camera_smoothing", "0"); settings->setDefault("cinematic_camera_smoothing", "0.7"); diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index e19156e22..f55f0e52a 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -894,7 +894,7 @@ int ModApiMainMenu::l_download_file(lua_State *L) /******************************************************************************/ int ModApiMainMenu::l_get_video_drivers(lua_State *L) { - std::vector drivers = RenderingEngine::getSupportedVideoDrivers(); + auto drivers = RenderingEngine::getSupportedVideoDrivers(); lua_newtable(L); for (u32 i = 0; i != drivers.size(); i++) { @@ -953,6 +953,13 @@ int ModApiMainMenu::l_get_window_info(lua_State *L) } /******************************************************************************/ +int ModApiMainMenu::l_get_active_driver(lua_State *L) +{ + auto drivertype = RenderingEngine::get_video_driver()->getDriverType(); + lua_pushstring(L, RenderingEngine::getVideoDriverInfo(drivertype).name.c_str()); + return 1; +} + int ModApiMainMenu::l_get_active_renderer(lua_State *L) { @@ -1102,6 +1109,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top) API_FCT(gettext); API_FCT(get_video_drivers); API_FCT(get_window_info); + API_FCT(get_active_driver); API_FCT(get_active_renderer); API_FCT(get_min_supp_proto); API_FCT(get_max_supp_proto); diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h index bb5c93cd5..538beaaa9 100644 --- a/src/script/lua_api/l_mainmenu.h +++ b/src/script/lua_api/l_mainmenu.h @@ -106,6 +106,8 @@ private: static int l_get_window_info(lua_State *L); + static int l_get_active_driver(lua_State *L); + static int l_get_active_renderer(lua_State *L); //filesystem