如何在macOS上将位图纹理的每个像素渲染到屏幕的每个本地物理像素? [英] How to render each pixel of a bitmap texture to each native physical pixel of the screen on macOS?

查看:141
本文介绍了如何在macOS上将位图纹理的每个像素渲染到屏幕的每个本地物理像素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于现代macOS设备默认选择使用缩放的HiDPI分辨率,因此位图图像在屏幕上变得模糊.有没有一种方法可以将位图逐像素渲染为显示屏的真实本机物理像素?是否有任何CoreGraphics,OpenGL或金属API允许这样做而无需更改屏幕的显示模式?

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?

如果您正在考虑这些convertXXXXToBacking和朋友,请停下来.这是给你的解释. MacBook Pro中的典型13现在具有2560x1600像素的原始分辨率.全新安装macOS后,默认的建议屏幕分辨率为1440x900.用户可以通过系统偏好设置将其更改为1680x1050.在1440x900或1680x1050的情况下,backingScaleFactor恰好为2.典型的渲染路线将首先渲染任何物体,使其达到非物理的2880x1800或3360x2100分辨率,并且OS/GPU使用未知的方法进行了最后的重采样.

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.

推荐答案

您最好的选择可能是Metal. MTKViewdrawableSize声称默认值为视图的大小(以本机像素"为单位).我不确定这是否意味着设备像素或后备存储像素.如果是后者,则可以关闭autoResizeDrawable并直接设置drawableSize.

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.

您还可以尝试使用大小为CGImage的Core Graphics绘制到后备存储像素中的屏幕大小的矩形上.所有缩放比例可能会在内部被抵消.

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.

这篇关于如何在macOS上将位图纹理的每个像素渲染到屏幕的每个本地物理像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆