Skip to content

Commit 996ea60

Browse files
sapiersapier
sapier
authored and
sapier
committedAug 22, 2014
Add video driver selection to settings menu (based uppon idea from webdesigner97)
1 parent 26f4a5c commit 996ea60

File tree

5 files changed

+92
-27
lines changed

5 files changed

+92
-27
lines changed
 

‎builtin/mainmenu/tab_settings.lua

+27-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,24 @@ local function scrollbar_to_gui_scale(value)
110110
end
111111

112112
local function formspec(tabview, name, tabdata)
113+
local video_drivers = core.get_video_drivers()
114+
115+
local video_driver_string = ""
116+
local current_video_driver_idx = 0
117+
local current_video_driver = core.setting_get("video_driver")
118+
for i=1, #video_drivers, 1 do
119+
120+
if i ~= 1 then
121+
video_driver_string = video_driver_string .. ","
122+
end
123+
video_driver_string = video_driver_string .. video_drivers[i]
124+
125+
if current_video_driver:lower() == video_drivers[i]:lower() then
126+
current_video_driver_idx = i
127+
end
128+
end
129+
130+
113131
local tab_string =
114132
"vertlabel[0,-0.25;" .. fgettext("SETTINGS") .. "]" ..
115133
"box[0.75,0;3.25,4;#999999]" ..
@@ -125,6 +143,10 @@ local function formspec(tabview, name, tabdata)
125143
.. dump(core.setting_getbool("preload_item_visuals")) .. "]"..
126144
"checkbox[1,2.5;cb_particles;".. fgettext("Enable Particles") .. ";"
127145
.. dump(core.setting_getbool("enable_particles")) .. "]"..
146+
"dropdown[1,3.25;3;dd_video_driver;"
147+
.. video_driver_string .. ";" .. current_video_driver_idx .. "]" ..
148+
"tooltip[dd_video_driver;" ..
149+
fgettext("Restart minetest for driver change to take effect") .. "]" ..
128150
"box[4.25,0;3.25,2.5;#999999]" ..
129151
"checkbox[4.5,0;cb_mipmapping;".. fgettext("Mip-Mapping") .. ";"
130152
.. dump(core.setting_getbool("mip_map")) .. "]"..
@@ -284,16 +306,20 @@ local function handle_settings_buttons(this, fields, tabname, tabdata)
284306
return true
285307
end
286308
if fields["btn_reset_singleplayer"] then
287-
print("sp reset")
288309
showconfirm_reset(this)
289310
return true
290311
end
312+
291313
--Note dropdowns have to be handled LAST!
292314
local ddhandled = false
293315
if fields["dd_touchthreshold"] then
294316
core.setting_set("touchscreen_threshold",fields["dd_touchthreshold"])
295317
ddhandled = true
296318
end
319+
if fields["dd_video_driver"] then
320+
core.setting_set("video_driver",fields["dd_video_driver"])
321+
ddhandled = true
322+
end
297323

298324
return ddhandled
299325
end

‎doc/menu_lua_api.txt

+3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ core.sound_play(spec, looped) -> handle
8888
^ spec = SimpleSoundSpec (see lua-api.txt)
8989
^ looped = bool
9090
core.sound_stop(handle)
91+
core.get_video_drivers()
92+
^ get list of video drivers supported by engine (not all modes are guaranteed to work)
93+
^ returns list of available video drivers e.g. { "OpenGL", "Software" }
9194

9295
Formspec:
9396
core.update_formspec(formspec)

‎src/main.cpp

+28-26
Original file line numberDiff line numberDiff line change
@@ -1365,41 +1365,43 @@ int main(int argc, char *argv[])
13651365
u16 fsaa = g_settings->getU16("fsaa");
13661366

13671367
// Determine driver
1368-
1369-
video::E_DRIVER_TYPE driverType;
1370-
1371-
std::string driverstring = g_settings->get("video_driver");
1372-
1373-
if (driverstring == "null")
1374-
driverType = video::EDT_NULL;
1375-
else if (driverstring == "software")
1376-
driverType = video::EDT_SOFTWARE;
1377-
else if (driverstring == "burningsvideo")
1378-
driverType = video::EDT_BURNINGSVIDEO;
1379-
else if (driverstring == "direct3d8")
1380-
driverType = video::EDT_DIRECT3D8;
1381-
else if (driverstring == "direct3d9")
1382-
driverType = video::EDT_DIRECT3D9;
1383-
else if (driverstring == "opengl")
1384-
driverType = video::EDT_OPENGL;
1368+
video::E_DRIVER_TYPE driverType = video::EDT_OPENGL;
1369+
static const char* driverids[] = {
1370+
"null",
1371+
"software",
1372+
"burningsvideo",
1373+
"direct3d8",
1374+
"direct3d9",
1375+
"opengl"
13851376
#ifdef _IRR_COMPILE_WITH_OGLES1_
1386-
else if (driverstring == "ogles1")
1387-
driverType = video::EDT_OGLES1;
1377+
,"ogles1"
13881378
#endif
13891379
#ifdef _IRR_COMPILE_WITH_OGLES2_
1390-
else if (driverstring == "ogles2")
1391-
driverType = video::EDT_OGLES2;
1380+
,"ogles2"
13921381
#endif
1393-
else {
1394-
errorstream << "WARNING: Invalid video_driver specified; defaulting "
1395-
<< "to opengl" << std::endl;
1396-
driverType = video::EDT_OPENGL;
1382+
,"invalid"
1383+
};
1384+
1385+
std::string driverstring = g_settings->get("video_driver");
1386+
for (unsigned int i = 0;
1387+
i < (sizeof(driverids)/sizeof(driverids[0]));
1388+
i++)
1389+
{
1390+
if (strcasecmp(driverstring.c_str(), driverids[i]) == 0) {
1391+
driverType = (video::E_DRIVER_TYPE) i;
1392+
break;
1393+
}
1394+
1395+
if (strcasecmp("invalid", driverids[i]) == 0) {
1396+
errorstream << "WARNING: Invalid video_driver specified; defaulting "
1397+
<< "to opengl" << std::endl;
1398+
break;
1399+
}
13971400
}
13981401

13991402
/*
14001403
List video modes if requested
14011404
*/
1402-
14031405
MyEventReceiver* receiver = new MyEventReceiver();
14041406

14051407
if (cmd_args.getFlag("videomodes")) {

‎src/script/lua_api/l_mainmenu.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3434
#include "sound.h"
3535
#include "settings.h"
3636
#include "main.h" // for g_settings
37+
#include "EDriverTypes.h"
3738

3839
#include <IFileArchive.h>
3940
#include <IFileSystem.h>
@@ -1001,6 +1002,36 @@ int ModApiMainMenu::l_download_file(lua_State *L)
10011002
return 1;
10021003
}
10031004

1005+
/******************************************************************************/
1006+
int ModApiMainMenu::l_get_video_drivers(lua_State *L)
1007+
{
1008+
static const char* drivernames[] = {
1009+
"NULL Driver",
1010+
"Software",
1011+
"Burningsvideo",
1012+
"Direct3D 8",
1013+
"Direct3D 9",
1014+
"OpenGL",
1015+
"OGLES1",
1016+
"OGLES2"
1017+
};
1018+
unsigned int index = 1;
1019+
lua_newtable(L);
1020+
int top = lua_gettop(L);
1021+
1022+
for (unsigned int i = irr::video::EDT_SOFTWARE;
1023+
i < MYMIN(irr::video::EDT_COUNT, (sizeof(drivernames)/sizeof(drivernames[0])));
1024+
i++) {
1025+
if (irr::IrrlichtDevice::isDriverSupported((irr::video::E_DRIVER_TYPE) i)) {
1026+
lua_pushnumber(L,index++);
1027+
lua_pushstring(L,drivernames[i]);
1028+
lua_settable(L, top);
1029+
}
1030+
}
1031+
1032+
return 1;
1033+
}
1034+
10041035
/******************************************************************************/
10051036
int ModApiMainMenu::l_gettext(lua_State *L)
10061037
{
@@ -1094,6 +1125,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
10941125
API_FCT(sound_play);
10951126
API_FCT(sound_stop);
10961127
API_FCT(gettext);
1128+
API_FCT(get_video_drivers);
10971129
API_FCT(get_screen_info);
10981130
API_FCT(do_async_callback);
10991131
}

‎src/script/lua_api/l_mainmenu.h

+2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ class ModApiMainMenu : public ModApiBase {
133133

134134
static int l_download_file(lua_State *L);
135135

136+
static int l_get_video_drivers(lua_State *L);
137+
136138
// async
137139
static int l_do_async_callback(lua_State *L);
138140

0 commit comments

Comments
 (0)
Please sign in to comment.