-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathDeviceImpl_iOS.mm
More file actions
59 lines (51 loc) · 1.62 KB
/
DeviceImpl_iOS.mm
File metadata and controls
59 lines (51 loc) · 1.62 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <cmath>
#include <Babylon/Graphics/Platform.h>
#include "DeviceImpl.h"
#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h>
namespace
{
bool IsValidScale(float scale)
{
return !std::isinf(scale) && scale > 0;
}
}
namespace Babylon::Graphics
{
void DeviceImpl::ConfigureBgfxPlatformData(bgfx::PlatformData& pd, WindowT window)
{
pd.nwh = window;
}
void DeviceImpl::ConfigureBgfxRenderType(bgfx::PlatformData& /*pd*/, bgfx::RendererType::Enum& /*renderType*/)
{
}
float DeviceImpl::GetDevicePixelRatio(WindowT window)
{
// contentsScale can return 0 if it hasn't been set yet.
float scale = static_cast<float>(((CAMetalLayer*)window).contentsScale);
if (IsValidScale(scale))
{
return scale;
}
// Prefer getting the scale from the active window scene's trait collection.
if (@available(iOS 17.0, *))
{
for (UIScene* scene in UIApplication.sharedApplication.connectedScenes)
{
if ([scene isKindOfClass:[UIWindowScene class]])
{
scale = static_cast<float>(((UIWindowScene*)scene).traitCollection.displayScale);
if (IsValidScale(scale))
{
return scale;
}
}
}
}
// Fallback for older iOS versions or if no active scene was found.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
return UIScreen.mainScreen.scale;
#pragma clang diagnostic pop
}
}