diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 37 | ||||
-rw-r--r-- | src/porting.cpp | 72 | ||||
-rw-r--r-- | src/porting.h | 5 | ||||
-rw-r--r-- | src/script/lua_api/l_mainmenu.cpp | 33 |
4 files changed, 100 insertions, 47 deletions
diff --git a/src/main.cpp b/src/main.cpp index 8c4cab4e4..173050fed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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,20 +2022,21 @@ 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; - break; - } - - if (strcasecmp("invalid", driverids[i]) == 0) { - errorstream << "WARNING: Invalid video_driver specified;" - << " defaulting to opengl" << std::endl; + 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 (i == drivers.size()) { + errorstream << "Invalid video_driver specified; " + "defaulting to opengl" << std::endl; + } SIrrlichtCreationParameters params = SIrrlichtCreationParameters(); params.DriverType = driverType; diff --git a/src/porting.cpp b/src/porting.cpp index 885b36e21..584d2e2a2 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -549,16 +549,20 @@ void initializePaths() #endif // RUN_IN_PLACE } -static irr::IrrlichtDevice* device; +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() diff --git a/src/porting.h b/src/porting.h index a184af8b8..e6574494a 100644 --- a/src/porting.h +++ b/src/porting.h @@ -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() diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 572b8efc8..c8389d889 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -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; |