Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support DPI #482

Closed
ryantrem opened this issue Nov 5, 2020 · 5 comments · Fixed by #582
Closed

Support DPI #482

ryantrem opened this issue Nov 5, 2020 · 5 comments · Fixed by #582
Assignees
Labels
enhancement New feature or request

Comments

@ryantrem
Copy link
Member

ryantrem commented Nov 5, 2020

Babylon.js has some support for scaling the display in different ways, based on the adaptToDeviceRatio Engine constructor parameter, Engine.setHardwardScalingLevel, and window.devicePixelRatio. I believe Babylon Native does not currently support any of this, and that currently we always specify view size in device pixels. I think that also means on mobile devices we are probably rendering at very high resolutions, perhaps higher than necessary with an associated resource cost. We should think about how to support this as it could have a huge impact on mobile performance.

@Drigax Drigax added the enhancement New feature or request label Nov 18, 2020
@Drigax
Copy link
Contributor

Drigax commented Nov 18, 2020

I think this is something worth investing in, especially for the potential performance gains as we would potentially be able to upscale from lower rendered resolutions. I'll start looking into this

@Drigax Drigax self-assigned this Nov 18, 2020
@Drigax
Copy link
Contributor

Drigax commented Jan 5, 2021

I added some rudimentary support for NativeEngine.setHardwareScalingLevel via this branch. One thing of note is that in BabylonJS hardware scaling is a reciprocal function, so that behavior needed to be preserved.: https://github.com/Drigax/BabylonNative/tree/add-engine-hardware-scaling-level

This is also dependent on a change to BabylonJS which properly calls these new NativeEngine members.

I'll open a PR Thursday when I return and begin looking into implementing a polyfill for window.devicePixelRatio

@Drigax
Copy link
Contributor

Drigax commented Jan 12, 2021

Looking at MSDN:
https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio

The devicePixelRatio of Window interface returns the ratio of the resolution in physical pixels to the resolution in CSS pixels for the current display device. This value could also be interpreted as the ratio of pixel sizes: the size of one CSS pixel to the size of one physical pixel. In simpler terms, this tells the browser how many of the screen's actual pixels should be used to draw a single CSS pixel.

This gives me the impression that window.devicePixelRatio can be implemented native-side as another scalar applied to calculate the resolution of the BGFX window. I'll most likely implment this similarily to how I'm currently implementing Engine.hardwareScalingLevel

@ryantrem
Copy link
Member Author

I think we can deduce devicePixelRatio on iOS/Android with:
iOS: UIScreen.mainScreen.nativeScale
Android: DisplayMetrics.density
I'm not 100% sure this is right, so we'll need to test it out.

@Drigax
Copy link
Contributor

Drigax commented Mar 9, 2021

#582

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants