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 retval =
"size[8,3]" ..
@ -76,17 +118,14 @@ local function showconfirm_reset(tabview)
end
local function gui_scale_to_scrollbar()
local current_value = tonumber(core.setting_get("gui_scaling"))
if (current_value == nil) or current_value < 0.25 then
return 0
end
if current_value <= 1.25 then
return ((current_value - 0.25)/ 1.0) * 700
end
if current_value <= 6 then
return ((current_value -1.25) * 100) + 700
end
@ -95,13 +134,11 @@ local function gui_scale_to_scrollbar()
end
local function scrollbar_to_gui_scale(value)
value = tonumber(value)
if (value <= 700) then
return ((value / 700) * 1.0) + 0.25
end
if (value <=1000) then
return ((value - 700) / 100) + 1.25
end
@ -111,51 +148,20 @@ end
local function formspec(tabview, name, tabdata)
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
local driver_formspec_string = ""
local driver_current_idx = 0
if i ~= 1 then
video_driver_string = video_driver_string .. ","
end
video_driver_string = video_driver_string .. video_drivers[i]
local video_driver = string.gsub(video_drivers[i], " ", "")
if current_video_driver:lower() == video_driver:lower() then
current_video_driver_idx = i
end
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
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
if current_video_driver == video_drivers[i].name:lower() then
driver_current_idx = i - 1
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 =
@ -182,7 +188,7 @@ end
.. getMipmapSettingIndex() .. "]" ..
"label[3.85,2.15;".. fgettext("Rendering:") .. "]"..
"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;" ..
fgettext("Restart minetest for driver change to take effect") .. "]" ..
"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"])
ddhandled = true
end
if fields["dd_video_driver"] then
local video_driver = string.gsub(fields["dd_video_driver"], " ", "")
core.setting_set("video_driver",string.lower(video_driver))
core.setting_set("video_driver",
video_driver_fname_to_name(fields["dd_video_driver"]))
ddhandled = true
end
if fields["dd_filters"] == "No Filter" then

View File

@ -90,7 +90,9 @@ core.sound_play(spec, looped) -> handle
core.sound_stop(handle)
core.get_video_drivers()
^ 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:
core.update_formspec(formspec)

View File

@ -1998,22 +1998,6 @@ void ClientLauncher::main_menu(MainMenuData *menudata)
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] = {
ELL_NONE,
ELL_ERROR,
@ -2038,19 +2022,20 @@ bool ClientLauncher::create_engine_device(int log_level)
// Determine driver
video::E_DRIVER_TYPE driverType = video::EDT_OPENGL;
std::string driverstring = g_settings->get("video_driver");
for (size_t i = 0; i < sizeof driverids / sizeof driverids[0]; i++) {
if (strcasecmp(driverstring.c_str(), driverids[i]) == 0) {
driverType = (video::E_DRIVER_TYPE) i;
std::vector<video::E_DRIVER_TYPE> drivers
= porting::getSupportedVideoDrivers();
u32 i;
for (i = 0; i != drivers.size(); i++) {
if (!strcasecmp(driverstring.c_str(),
porting::getVideoDriverName(drivers[i]))) {
driverType = drivers[i];
break;
}
if (strcasecmp("invalid", driverids[i]) == 0) {
errorstream << "WARNING: Invalid video_driver specified;"
<< " defaulting to opengl" << std::endl;
break;
}
if (i == drivers.size()) {
errorstream << "Invalid video_driver specified; "
"defaulting to opengl" << std::endl;
}
SIrrlichtCreationParameters params = SIrrlichtCreationParameters();

View File

@ -551,14 +551,18 @@ void initializePaths()
static irr::IrrlichtDevice *device;
void initIrrlicht(irr::IrrlichtDevice * _device) {
device = _device;
void initIrrlicht(irr::IrrlichtDevice *device_)
{
device = device_;
}
void setXorgClassHint(const video::SExposedVideoData &video_data,
const std::string &name)
{
#ifdef XORG_USED
if (video_data.OpenGLLinux.X11Display == NULL)
return;
XClassHint *classhint = XAllocClassHint();
classhint->res_name = (char *)name.c_str();
classhint->res_class = (char *)name.c_str();
@ -575,6 +579,68 @@ v2u32 getWindowSize()
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__
#ifdef XORG_USED
float getDisplayDensity()

View File

@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#endif
#include <string>
#include <vector>
#include "irrlicht.h"
#include "irrlichttypes.h" // u32
#include "irrlichttypes_extrabloated.h"
@ -369,6 +370,10 @@ float getDisplayDensity();
v2u32 getDisplaySize();
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
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)
{
static const char* drivernames[] = {
"NULL Driver",
"Software",
"Burningsvideo",
"Direct3D 8",
"Direct3D 9",
"OpenGL",
"OGLES1",
"OGLES2"
};
unsigned int index = 1;
lua_newtable(L);
int top = lua_gettop(L);
for (unsigned int i = irr::video::EDT_SOFTWARE;
i < MYMIN(irr::video::EDT_COUNT, (sizeof(drivernames)/sizeof(drivernames[0])));
i++) {
if (irr::IrrlichtDevice::isDriverSupported((irr::video::E_DRIVER_TYPE) i)) {
lua_pushnumber(L,index++);
lua_pushstring(L,drivernames[i]);
lua_settable(L, top);
}
std::vector<irr::video::E_DRIVER_TYPE> drivers
= porting::getSupportedVideoDrivers();
lua_newtable(L);
for (u32 i = 0; i != drivers.size(); i++) {
const char *name = porting::getVideoDriverName(drivers[i]);
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;