X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;ds=sidebyside;f=src%2Fclient%2Frenderingengine.cpp;h=22c8a8102fb2193b1a726598092b814553add091;hb=946f3030fc0728de15620896e08ed7e10696c11b;hp=e56367afee8c7150a8237b4758d548f6be7e7b83;hpb=d1a1c5cbf055e7eacbc4aeaa53174749d4c64d87;p=dragonfireclient.git diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index e56367afe..22c8a8102 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -45,27 +45,31 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include +#endif +#ifdef _WIN32 +#include +#include #endif -#ifdef __ANDROID__ +#if ENABLE_GLES #include "filesys.h" #endif RenderingEngine *RenderingEngine::s_singleton = nullptr; -static gui::GUISkin* createSkin(gui::IGUIEnvironment *environment, - gui::EGUI_SKIN_TYPE type, video::IVideoDriver *driver) +static gui::GUISkin *createSkin(gui::IGUIEnvironment *environment, + gui::EGUI_SKIN_TYPE type, video::IVideoDriver *driver) { - gui::GUISkin* skin = new gui::GUISkin(type, driver); + gui::GUISkin *skin = new gui::GUISkin(type, driver); - gui::IGUIFont* builtinfont = environment->getBuiltInFont(); - gui::IGUIFontBitmap* bitfont = 0; + gui::IGUIFont *builtinfont = environment->getBuiltInFont(); + gui::IGUIFontBitmap *bitfont = nullptr; if (builtinfont && builtinfont->getType() == gui::EGFT_BITMAP) bitfont = (gui::IGUIFontBitmap*)builtinfont; - gui::IGUISpriteBank* bank = 0; + gui::IGUISpriteBank *bank = 0; skin->setFont(builtinfont); if (bitfont) @@ -102,7 +106,7 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver) u32 i; for (i = 0; i != drivers.size(); i++) { if (!strcasecmp(driverstring.c_str(), - RenderingEngine::getVideoDriverName(drivers[i]))) { + RenderingEngine::getVideoDriverName(drivers[i]))) { driverType = drivers[i]; break; } @@ -126,11 +130,13 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver) params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu"); params.ZBufferBits = 24; #ifdef __ANDROID__ - // clang-format off params.PrivateData = porting::app_global; - params.OGLES2ShaderPath = std::string(porting::path_user + DIR_DELIM + "media" + - DIR_DELIM + "Shaders" + DIR_DELIM).c_str(); - // clang-format on +#endif +#if ENABLE_GLES + // there is no standardized path for these on desktop + std::string rel_path = std::string("client") + DIR_DELIM + + "shaders" + DIR_DELIM + "Irrlicht"; + params.OGLES2ShaderPath = (porting::path_share + DIR_DELIM + rel_path + DIR_DELIM).c_str(); #endif m_device = createDeviceEx(params); @@ -139,7 +145,7 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver) s_singleton = this; auto skin = createSkin(m_device->getGUIEnvironment(), - gui::EGST_WINDOWS_METALLIC, driver); + gui::EGST_WINDOWS_METALLIC, driver); m_device->getGUIEnvironment()->setSkin(skin); skin->drop(); } @@ -221,27 +227,17 @@ bool RenderingEngine::setupTopLevelWindow(const std::string &name) { // FIXME: It would make more sense for there to be a switch of some // sort here that would call the correct toplevel setup methods for - // the environment Minetest is running in but for now not deviating - // from the original pattern. + // the environment Minetest is running in. /* Setting Xorg properties for the top level window */ setupTopLevelXorgWindow(name); - /* Done with Xorg properties */ /* Setting general properties for the top level window */ verbosestream << "Client: Configuring general top level" << " window properties" << std::endl; - bool result = setWindowIcon(); - verbosestream << "Client: Finished configuring general top level" - << " window properties" - << std::endl; - /* Done with general properties */ - - // FIXME: setWindowIcon returns a bool result but it is unused. - // For now continue to return this result. return result; } @@ -257,7 +253,7 @@ void RenderingEngine::setupTopLevelXorgWindow(const std::string &name) return; } - verbosestream << "Client: Configuring Xorg specific top level" + verbosestream << "Client: Configuring X11-specific top level" << " window properties" << std::endl; @@ -304,8 +300,6 @@ void RenderingEngine::setupTopLevelXorgWindow(const std::string &name) Atom NET_WM_PID = XInternAtom(x11_dpl, "_NET_WM_PID", false); pid_t pid = getpid(); - infostream << "Client: PID is '" << static_cast(pid) << "'" - << std::endl; XChangeProperty(x11_dpl, x11_win, NET_WM_PID, XA_CARDINAL, 32, PropModeReplace, @@ -322,32 +316,13 @@ void RenderingEngine::setupTopLevelXorgWindow(const std::string &name) XChangeProperty (x11_dpl, x11_win, WM_CLIENT_LEADER, XA_WINDOW, 32, PropModeReplace, reinterpret_cast(&x11_win), 1); - - verbosestream << "Client: Finished configuring Xorg specific top level" - << " window properties" - << std::endl; #endif } - -bool RenderingEngine::setWindowIcon() +#ifdef _WIN32 +static bool getWindowHandle(irr::video::IVideoDriver *driver, HWND &hWnd) { -#if defined(XORG_USED) -#if RUN_IN_PLACE - return setXorgWindowIconFromPath( - porting::path_share + "/misc/" PROJECT_NAME "-xorg-icon-128.png"); -#else - // We have semi-support for reading in-place data if we are - // compiled with RUN_IN_PLACE. Don't break with this and - // also try the path_share location. - return setXorgWindowIconFromPath( - ICON_DIR "/hicolor/128x128/apps/" PROJECT_NAME ".png") || - setXorgWindowIconFromPath(porting::path_share + "/misc/" PROJECT_NAME - "-xorg-icon-128.png"); -#endif -#elif defined(_WIN32) const video::SExposedVideoData exposedData = driver->getExposedVideoData(); - HWND hWnd; // Window handle switch (driver->getDriverType()) { case video::EDT_DIRECT3D8: @@ -363,6 +338,29 @@ bool RenderingEngine::setWindowIcon() return false; } + return true; +} +#endif + +bool RenderingEngine::setWindowIcon() +{ +#if defined(XORG_USED) +#if RUN_IN_PLACE + return setXorgWindowIconFromPath( + porting::path_share + "/misc/dragonfire-xorg-icon-128.png"); +#else + // We have semi-support for reading in-place data if we are + // compiled with RUN_IN_PLACE. Don't break with this and + // also try the path_share location. + return setXorgWindowIconFromPath( + ICON_DIR "/hicolor/128x128/apps/dragonfire.png") || + setXorgWindowIconFromPath(porting::path_share + "/misc/dragonfire-xorg-icon-128.png"); +#endif +#elif defined(_WIN32) + HWND hWnd; // Window handle + if (!getWindowHandle(driver, hWnd)) + return false; + // Load the ICON from resource file const HICON hicon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(130) // The ID of the ICON defined in @@ -643,7 +641,7 @@ const char *RenderingEngine::getVideoDriverFriendlyName(irr::video::E_DRIVER_TYP } #ifndef __ANDROID__ -#ifdef XORG_USED +#if defined(XORG_USED) static float calcDisplayDensity() { @@ -678,12 +676,42 @@ float RenderingEngine::getDisplayDensity() return cached_display_density; } -#else // XORG_USED +#elif defined(_WIN32) + + +static float calcDisplayDensity(irr::video::IVideoDriver *driver) +{ + HWND hWnd; + if (getWindowHandle(driver, hWnd)) { + HDC hdc = GetDC(hWnd); + float dpi = GetDeviceCaps(hdc, LOGPIXELSX); + ReleaseDC(hWnd, hdc); + return dpi / 96.0f; + } + + /* return manually specified dpi */ + return g_settings->getFloat("screen_dpi") / 96.0f; +} + +float RenderingEngine::getDisplayDensity() +{ + static bool cached = false; + static float display_density; + if (!cached) { + display_density = calcDisplayDensity(get_video_driver()); + cached = true; + } + return display_density; +} + +#else + float RenderingEngine::getDisplayDensity() { return g_settings->getFloat("screen_dpi") / 96.0; } -#endif // XORG_USED + +#endif v2u32 RenderingEngine::getDisplaySize() {