]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/client/renderingengine.cpp
Merge branch 'master' of https://github.com/minetest/minetest
[dragonfireclient.git] / src / client / renderingengine.cpp
index 8b7bbf328e30ad783ee3f45c2b4c2f50dc193813..22c8a8102fb2193b1a726598092b814553add091 100644 (file)
@@ -45,7 +45,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/Xatom.h>
+#endif
 
+#ifdef _WIN32
+#include <windows.h>
+#include <winuser.h>
 #endif
 
 #if ENABLE_GLES
@@ -126,12 +130,9 @@ 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
-#elif ENABLE_GLES
+#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";
@@ -318,25 +319,10 @@ void RenderingEngine::setupTopLevelXorgWindow(const std::string &name)
 #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:
@@ -352,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
@@ -632,7 +641,7 @@ const char *RenderingEngine::getVideoDriverFriendlyName(irr::video::E_DRIVER_TYP
 }
 
 #ifndef __ANDROID__
-#ifdef XORG_USED
+#if defined(XORG_USED)
 
 static float calcDisplayDensity()
 {
@@ -667,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()
 {