forked from BabylonJS/BabylonNative
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeviceImpl_Unix.cpp
More file actions
41 lines (32 loc) · 1.28 KB
/
DeviceImpl_Unix.cpp
File metadata and controls
41 lines (32 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <Babylon/Graphics/Platform.h>
#include "DeviceImpl.h"
namespace Babylon::Graphics
{
void DeviceImpl::ConfigureBgfxPlatformData(bgfx::PlatformData& pd, WindowT window)
{
pd.nwh = reinterpret_cast<void*>(window);
}
void DeviceImpl::ConfigureBgfxRenderType(bgfx::PlatformData& /*pd*/, bgfx::RendererType::Enum& /*renderType*/)
{
}
float DeviceImpl::GetDevicePixelRatio(WindowT)
{
// TODO: We should persist a Display object instead of opening a new display.
// See https://github.com/BabylonJS/BabylonNative/issues/625
auto display = XOpenDisplay(nullptr);
auto screen = DefaultScreen(display);
auto width = DisplayWidthMM(display, screen);
auto pixelWidth = DisplayWidth(display, screen);
XCloseDisplay(display);
if (width > 0)
{
constexpr float MILLIMETERS_TO_INCHES = 0.03937f;
auto dpi = pixelWidth / (width * MILLIMETERS_TO_INCHES);
// X11 does not enforce a default dpi.
// Use 96 dpi as our baseline DPI to match the behavior of Windows, and the default behavior of Linux Desktop Environments such as Gnome and KDE.
// See: https://scanline.ca/dpi/
return dpi / 96.0f;
}
return 1;
}
}