Reorganize supported video driver query mechanisms

master
kwolekr 2015-01-18 13:14:25 -05:00
parent 44e4f5ab6e
commit 976d0b2caa
6 changed files with 160 additions and 98 deletions

View File

@ -17,6 +17,48 @@
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
local filters = {
{"No Filter,Bilinear Filter,Trilinear Filter"},
{"", "bilinear_filter", "trilinear_filter"},
}
local mipmap = {
{"No Mipmap,Mipmap,Mipmap + Aniso. Filter"},
{"", "mip_map", "anisotropic_filter"},
}
local function getFilterSettingIndex()
if (core.setting_get(filters[2][3]) == "true") then
return 3
end
if (core.setting_get(filters[2][3]) == "false" and core.setting_get(filters[2][2]) == "true") then
return 2
end
return 1
end
local function getMipmapSettingIndex()
if (core.setting_get(mipmap[2][3]) == "true") then
return 3
end
if (core.setting_get(mipmap[2][3]) == "false" and core.setting_get(mipmap[2][2]) == "true") then
return 2
end
return 1
end
local function video_driver_fname_to_name(selected_driver)
local video_drivers = core.get_video_drivers()
for i=1, #video_drivers do
if selected_driver == video_drivers[i].friendly_name then
return video_drivers[i].name:lower()
end
end
return ""
end
local function dlg_confirm_reset_formspec(data) local function dlg_confirm_reset_formspec(data)
local retval = local retval =
"size[8,3]" .. "size[8,3]" ..
@ -76,17 +118,14 @@ local function showconfirm_reset(tabview)
end end
local function gui_scale_to_scrollbar() local function gui_scale_to_scrollbar()
local current_value = tonumber(core.setting_get("gui_scaling")) local current_value = tonumber(core.setting_get("gui_scaling"))
if (current_value == nil) or current_value < 0.25 then if (current_value == nil) or current_value < 0.25 then
return 0 return 0
end end
if current_value <= 1.25 then if current_value <= 1.25 then
return ((current_value - 0.25)/ 1.0) * 700 return ((current_value - 0.25)/ 1.0) * 700
end end
if current_value <= 6 then if current_value <= 6 then
return ((current_value -1.25) * 100) + 700 return ((current_value -1.25) * 100) + 700
end end
@ -95,13 +134,11 @@ local function gui_scale_to_scrollbar()
end end
local function scrollbar_to_gui_scale(value) local function scrollbar_to_gui_scale(value)
value = tonumber(value) value = tonumber(value)
if (value <= 700) then if (value <= 700) then
return ((value / 700) * 1.0) + 0.25 return ((value / 700) * 1.0) + 0.25
end end
if (value <=1000) then if (value <=1000) then
return ((value - 700) / 100) + 1.25 return ((value - 700) / 100) + 1.25
end end
@ -111,53 +148,22 @@ end
local function formspec(tabview, name, tabdata) local function formspec(tabview, name, tabdata)
local video_drivers = core.get_video_drivers() local video_drivers = core.get_video_drivers()
local current_video_driver = core.setting_get("video_driver"):lower()
local video_driver_string = ""
local current_video_driver_idx = 0
local current_video_driver = core.setting_get("video_driver")
for i=1, #video_drivers, 1 do
if i ~= 1 then local driver_formspec_string = ""
video_driver_string = video_driver_string .. "," local driver_current_idx = 0
for i=2, #video_drivers do
driver_formspec_string = driver_formspec_string .. video_drivers[i].friendly_name
if i ~= #video_drivers then
driver_formspec_string = driver_formspec_string .. ","
end end
video_driver_string = video_driver_string .. video_drivers[i]
local video_driver = string.gsub(video_drivers[i], " ", "") if current_video_driver == video_drivers[i].name:lower() then
if current_video_driver:lower() == video_driver:lower() then driver_current_idx = i - 1
current_video_driver_idx = i
end end
end end
local filters = {
{"No Filter,Bilinear Filter,Trilinear Filter"},
{"", "bilinear_filter", "trilinear_filter"},
}
local mipmap = {
{"No Mipmap,Mipmap,Mipmap + Aniso. Filter"},
{"", "mip_map", "anisotropic_filter"},
}
local function getFilterSettingIndex()
if (core.setting_get(filters[2][3]) == "true") then
return 3
end
if (core.setting_get(filters[2][3]) == "false" and core.setting_get(filters[2][2]) == "true") then
return 2
end
return 1
end
local function getMipmapSettingIndex()
if (core.setting_get(mipmap[2][3]) == "true") then
return 3
end
if (core.setting_get(mipmap[2][3]) == "false" and core.setting_get(mipmap[2][2]) == "true") then
return 2
end
return 1
end
local tab_string = local tab_string =
"box[0,0;3.5,3.9;#999999]" .. "box[0,0;3.5,3.9;#999999]" ..
"checkbox[0.25,0;cb_smooth_lighting;".. fgettext("Smooth Lighting") "checkbox[0.25,0;cb_smooth_lighting;".. fgettext("Smooth Lighting")
@ -182,7 +188,7 @@ end
.. getMipmapSettingIndex() .. "]" .. .. getMipmapSettingIndex() .. "]" ..
"label[3.85,2.15;".. fgettext("Rendering:") .. "]".. "label[3.85,2.15;".. fgettext("Rendering:") .. "]"..
"dropdown[3.85,2.6;3.85;dd_video_driver;" "dropdown[3.85,2.6;3.85;dd_video_driver;"
.. video_driver_string .. ";" .. current_video_driver_idx .. "]" .. .. driver_formspec_string .. ";" .. driver_current_idx .. "]" ..
"tooltip[dd_video_driver;" .. "tooltip[dd_video_driver;" ..
fgettext("Restart minetest for driver change to take effect") .. "]" .. fgettext("Restart minetest for driver change to take effect") .. "]" ..
"box[7.75,0;4,4;#999999]" .. "box[7.75,0;4,4;#999999]" ..
@ -335,9 +341,10 @@ local function handle_settings_buttons(this, fields, tabname, tabdata)
core.setting_set("touchscreen_threshold",fields["dd_touchthreshold"]) core.setting_set("touchscreen_threshold",fields["dd_touchthreshold"])
ddhandled = true ddhandled = true
end end
if fields["dd_video_driver"] then if fields["dd_video_driver"] then
local video_driver = string.gsub(fields["dd_video_driver"], " ", "") core.setting_set("video_driver",
core.setting_set("video_driver",string.lower(video_driver)) video_driver_fname_to_name(fields["dd_video_driver"]))
ddhandled = true ddhandled = true
end end
if fields["dd_filters"] == "No Filter" then if fields["dd_filters"] == "No Filter" then
@ -379,4 +386,4 @@ tab_settings = {
caption = fgettext("Settings"), caption = fgettext("Settings"),
cbf_formspec = formspec, cbf_formspec = formspec,
cbf_button_handler = handle_settings_buttons cbf_button_handler = handle_settings_buttons
} }

View File

@ -90,7 +90,9 @@ core.sound_play(spec, looped) -> handle
core.sound_stop(handle) core.sound_stop(handle)
core.get_video_drivers() core.get_video_drivers()
^ get list of video drivers supported by engine (not all modes are guaranteed to work) ^ get list of video drivers supported by engine (not all modes are guaranteed to work)
^ returns list of available video drivers e.g. { "OpenGL", "Software" } ^ returns list of available video drivers' settings name and 'friendly' display name
^ e.g. { {name="opengl", friendly_name="OpenGL"}, {name="software", friendly_name="Software Renderer"} }
^ first element of returned list is guaranteed to be the NULL driver
Formspec: Formspec:
core.update_formspec(formspec) core.update_formspec(formspec)

View File

@ -1998,22 +1998,6 @@ void ClientLauncher::main_menu(MainMenuData *menudata)
bool ClientLauncher::create_engine_device(int log_level) bool ClientLauncher::create_engine_device(int log_level)
{ {
static const char *driverids[] = {
"null",
"software",
"burningsvideo",
"direct3d8",
"direct3d9",
"opengl"
#ifdef _IRR_COMPILE_WITH_OGLES1_
,"ogles1"
#endif
#ifdef _IRR_COMPILE_WITH_OGLES2_
,"ogles2"
#endif
,"invalid"
};
static const irr::ELOG_LEVEL irr_log_level[5] = { static const irr::ELOG_LEVEL irr_log_level[5] = {
ELL_NONE, ELL_NONE,
ELL_ERROR, ELL_ERROR,
@ -2038,20 +2022,21 @@ bool ClientLauncher::create_engine_device(int log_level)
// Determine driver // Determine driver
video::E_DRIVER_TYPE driverType = video::EDT_OPENGL; video::E_DRIVER_TYPE driverType = video::EDT_OPENGL;
std::string driverstring = g_settings->get("video_driver"); std::string driverstring = g_settings->get("video_driver");
for (size_t i = 0; i < sizeof driverids / sizeof driverids[0]; i++) { std::vector<video::E_DRIVER_TYPE> drivers
if (strcasecmp(driverstring.c_str(), driverids[i]) == 0) { = porting::getSupportedVideoDrivers();
driverType = (video::E_DRIVER_TYPE) i; u32 i;
break; for (i = 0; i != drivers.size(); i++) {
} if (!strcasecmp(driverstring.c_str(),
porting::getVideoDriverName(drivers[i]))) {
if (strcasecmp("invalid", driverids[i]) == 0) { driverType = drivers[i];
errorstream << "WARNING: Invalid video_driver specified;"
<< " defaulting to opengl" << std::endl;
break; break;
} }
} }
if (i == drivers.size()) {
errorstream << "Invalid video_driver specified; "
"defaulting to opengl" << std::endl;
}
SIrrlichtCreationParameters params = SIrrlichtCreationParameters(); SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
params.DriverType = driverType; params.DriverType = driverType;

View File

@ -549,16 +549,20 @@ void initializePaths()
#endif // RUN_IN_PLACE #endif // RUN_IN_PLACE
} }
static irr::IrrlichtDevice* device; static irr::IrrlichtDevice *device;
void initIrrlicht(irr::IrrlichtDevice * _device) { void initIrrlicht(irr::IrrlichtDevice *device_)
device = _device; {
device = device_;
} }
void setXorgClassHint(const video::SExposedVideoData &video_data, void setXorgClassHint(const video::SExposedVideoData &video_data,
const std::string &name) const std::string &name)
{ {
#ifdef XORG_USED #ifdef XORG_USED
if (video_data.OpenGLLinux.X11Display == NULL)
return;
XClassHint *classhint = XAllocClassHint(); XClassHint *classhint = XAllocClassHint();
classhint->res_name = (char *)name.c_str(); classhint->res_name = (char *)name.c_str();
classhint->res_class = (char *)name.c_str(); classhint->res_class = (char *)name.c_str();
@ -575,6 +579,68 @@ v2u32 getWindowSize()
return device->getVideoDriver()->getScreenSize(); return device->getVideoDriver()->getScreenSize();
} }
std::vector<core::vector3d<u32> > getVideoModes()
{
std::vector<core::vector3d<u32> > mlist;
video::IVideoModeList *modelist = device->getVideoModeList();
u32 num_modes = modelist->getVideoModeCount();
for (u32 i = 0; i != num_modes; i++) {
core::dimension2d<u32> mode_res = modelist->getVideoModeResolution(i);
s32 mode_depth = modelist->getVideoModeDepth(i);
mlist.push_back(core::vector3d<u32>(mode_res.Width, mode_res.Height, mode_depth));
}
return mlist;
}
std::vector<irr::video::E_DRIVER_TYPE> getSupportedVideoDrivers()
{
std::vector<irr::video::E_DRIVER_TYPE> drivers;
for (int i = 0; i != irr::video::EDT_COUNT; i++) {
if (irr::IrrlichtDevice::isDriverSupported((irr::video::E_DRIVER_TYPE)i))
drivers.push_back((irr::video::E_DRIVER_TYPE)i);
}
return drivers;
}
const char *getVideoDriverName(irr::video::E_DRIVER_TYPE type)
{
static const char *driver_ids[] = {
"null",
"software",
"burningsvideo",
"direct3d8",
"direct3d9",
"opengl",
"ogles1",
"ogles2",
};
return driver_ids[type];
}
const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type)
{
static const char *driver_names[] = {
"NULL Driver",
"Software Renderer",
"Burning's Video",
"Direct3D 8",
"Direct3D 9",
"OpenGL",
"OpenGL ES1",
"OpenGL ES2",
};
return driver_names[type];
}
#ifndef __ANDROID__ #ifndef __ANDROID__
#ifdef XORG_USED #ifdef XORG_USED
float getDisplayDensity() float getDisplayDensity()

View File

@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#endif #endif
#include <string> #include <string>
#include <vector>
#include "irrlicht.h" #include "irrlicht.h"
#include "irrlichttypes.h" // u32 #include "irrlichttypes.h" // u32
#include "irrlichttypes_extrabloated.h" #include "irrlichttypes_extrabloated.h"
@ -369,6 +370,10 @@ float getDisplayDensity();
v2u32 getDisplaySize(); v2u32 getDisplaySize();
v2u32 getWindowSize(); v2u32 getWindowSize();
std::vector<irr::video::E_DRIVER_TYPE> getSupportedVideoDrivers();
const char *getVideoDriverName(irr::video::E_DRIVER_TYPE type);
const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type);
#endif #endif
inline const char * getPlatformName() inline const char * getPlatformName()

View File

@ -1025,28 +1025,25 @@ int ModApiMainMenu::l_download_file(lua_State *L)
/******************************************************************************/ /******************************************************************************/
int ModApiMainMenu::l_get_video_drivers(lua_State *L) int ModApiMainMenu::l_get_video_drivers(lua_State *L)
{ {
static const char* drivernames[] = {
"NULL Driver",
"Software",
"Burningsvideo",
"Direct3D 8",
"Direct3D 9",
"OpenGL",
"OGLES1",
"OGLES2"
};
unsigned int index = 1; unsigned int index = 1;
lua_newtable(L); lua_newtable(L);
int top = lua_gettop(L); int top = lua_gettop(L);
for (unsigned int i = irr::video::EDT_SOFTWARE; std::vector<irr::video::E_DRIVER_TYPE> drivers
i < MYMIN(irr::video::EDT_COUNT, (sizeof(drivernames)/sizeof(drivernames[0]))); = porting::getSupportedVideoDrivers();
i++) {
if (irr::IrrlichtDevice::isDriverSupported((irr::video::E_DRIVER_TYPE) i)) { lua_newtable(L);
lua_pushnumber(L,index++); for (u32 i = 0; i != drivers.size(); i++) {
lua_pushstring(L,drivernames[i]); const char *name = porting::getVideoDriverName(drivers[i]);
lua_settable(L, top); const char *fname = porting::getVideoDriverFriendlyName(drivers[i]);
}
lua_newtable(L);
lua_pushstring(L, name);
lua_setfield(L, -2, "name");
lua_pushstring(L, fname);
lua_setfield(L, -2, "friendly_name");
lua_rawseti(L, -2, i + 1);
} }
return 1; return 1;