How to render each pixel of a bitmap texture to each native physical pixel of the screen on macOS?

我怕爱的太早我们不能终老 提交于 2019-12-31 04:00:50

问题


As modern macOS devices choose to use a scaled HiDPI resolution by default, bitmap images get blurred on screen. Is there a way to render a bitmap pixel by pixel to the true native physical pixels of the display screen? Any CoreGraphics, OpenGL, or metal API that would allow this without change the display mode of the screen?

If you are thinking of those convertXXXXToBacking and friends, stop. Here is the explanation for you. A typical 13 in MacBook pro now has native 2560x1600 pixel resolution. The default recommended screen resolution is 1440x900 after fresh macOS install. The user can change it to 1680x1050 via System Preferences. In either 1440x900 or 1680x1050 case, the backingScaleFactor is exactly 2. The typical rendering route would render anything first to the unphysical 2880x1800 or 3360x2100 resolution and the OS/GPU did the final resampling with an unknown method.


回答1:


Your best bet is probably Metal. MTKView's drawableSize claims that the default is the view's size "in native pixels". I'm not certain if that means device pixels or backing store pixels. If the latter, you could turn off autoResizeDrawable and set drawableSize directly.

To obtain the display's physical pixel count, you can use my answer here.

You can also try using Core Graphics with a CGImage of that size drawn to a rect of the screen size in backing store pixels. It's possible that all of the scaling will be internally cancelled out.




回答2:


If these are resource images, use asset catalogs to provide x2 and x3 resolution version of your images, icons, etc. Classes like NSImageView will automatically select the best version for the display resolution.

If you just have some random image and you want it draw at the resolution of the display, get the backingScaleFactor of the view's window. If it's 2.0 then drawing a 200 x 200 pixel image into a 100 x 100 coordinate point rectangle will draw it at 1:1 native resolution. Similarly, if the scale factor is 3.0, a 300 x 300 pixel image will draw into a 100 x 100 coordinate point rectangle.

Not surprisingly, Apple has an extensive guide on this subject: High Resolution Guidelines for OS X



来源:https://stackoverflow.com/questions/53551692/how-to-render-each-pixel-of-a-bitmap-texture-to-each-native-physical-pixel-of-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!