I found that on macOS that after creating a window, and then creating a metal renderer, that GetRenderOutputSize returns zero for w and h, unless a call is made to SDL_SetWindowSize with the same window size as created.
Doesn’t work:
create window
create renderer
get renderer output size
Does work:
create window
create renderer
set renderer target to null
set renderer draw colour to black
render clear
render present
set window size to same as created
get renderer output size
I’ve not tested to see which of steps 3-6 are necessary, but it’s not enough to just call set window size before steps 3-6.
Also, the renderer device doesn’t appear to get resized when you drag the macOS window to resize it, instead I have to destroy and create the renderer to make it the new size.
Finally, on iOS, the same workaround is necessary as above, but the issue doesn’t show in the same way, instead it appears that renderer output size returns sane values, but it crashes down inside the metal code somewhere to do with vertexes. The workaround fixes the issue though.
Finally finally, I’m using a slightly modified version of SDL2.0.8, so I wanted to check to see if anyone has encountered similar before putting together a sample project. I don’t think my changes are responsible for the above though, it’s just a few functions to create textures out of existing METAL textures returned from the VLC video player library so I can hardware accelerate VLC directly onto SDL textures.
The above issues occur before I get that far into my app.
Thanks for that - it half-fixes it. The problem is that in retina mode it is creating a metal layer that is not the correct high resolution one.
With my workaround, it was creating a metal layer double the size, as required in retina mode.
Also, it doesn’t address the fact that resizing a window doesn’t resize the metal layer - so you have to keep deleting and re-creating the renderer.
I did apply that fix in isolation however, I’ve not tried whatever else has been changed since 2.0.8. This is because as mentioned I have a branch with various other changes too so it’s not a 5 minute job to merge latest changes into my branch, so I tend to wait for the next stable release, but if you think there are other fixes that might solve the above issues then maybe I would.
I cloned the unreleased 2.0.9 code today, and switched my high-DPI OpenGL-backed project to the new Metal backend. It worked fine but it wasn’t high DPI anymore, and locking/unlocking streaming textures isn’t supported.
Here’s what the DPI looks like if you draw a diagonal line:
I believe I’ve fixed the high dpi and resizing issues as of https://hg.libsdl.org/SDL/rev/758d4e1222a7 . Let me know if it works for you, if you get a chance to try that change.