Mtkview aligned to screen pixels on macOS

Upon doing a frame capture, to my surprise, I saw that the render target was twice the size of the actual display.


I traced the issue to my display settings - a super small font scaling - therefore the desktop Is being rendered at about twice the display resolution. Fair enough...


For performance reasons, I’d rather my app render one texel per pixel. And I can’t find the API that will help me convert the View coordinates to actual display pixels.


Im quite certain it’s possible since Xcode displays the captured frame texture at the proper pixel aligned size... (4x larger than the window of the app)


Any help or hints would be appreciated. 🙂

Replies

You should check the properties autoResizeDrawable and drawableSize of MTKView. You can then compute the ratio between the drawableSize to the view frame size.