We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4796

Summary: [Feature] Additional SDL_Metal_* APIs
Product: SDL Reporter: Caleb Cornett <spydog>
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: amaranth72, icculus
Version: 2.0.10Keywords: target-2.0.14
Hardware: All   
OS: macOS 10.14   
Attachments: Diff with the API implementations

Description Caleb Cornett 2019-09-08 05:13:11 UTC
Created attachment 3959 [details]
Diff with the API implementations

A few weeks ago, Alex added a partial Metal API to SDL2: https://hg.libsdl.org/SDL/rev/b87ba0fad17e

I noticed it was missing a few features that would help Metal become a first-class citizen in SDL, so I went ahead and wrote them! Here are the new APIs:

1. SDL_WINDOW_METAL flag for SDL_CreateWindow(). This allows the programmer to specify that they intend to create a window for use with SDL_MetalView. The flag is used to ensure correct usage of the API and to prevent accidentally defaulting to OpenGL on iOS.

2. SDL_Metal_GetLayer(). This function takes a SDL_MetalView and returns a pointer to the view's backing CAMetalLayer. This simplifies things considerably, since in the current version of the SDL_Metal API the programmer is required to bridge-cast a SDL_MetalView handle to an NSView or UIView (depending on the platform) and then extract the layer from there. SDL_Metal_GetLayer automatically handles all of that, making the operation simple and cross-platform.

3. SDL_Metal_GetDrawableSize(). This function already exists in the current SDL_Metal API (and is used behind-the-scenes for SDL_Vulkan_GetDrawableSize on Apple platforms) but was not publicly exposed. My patch exposes this function for public use. It works just like you'd expect.

Tested on macOS 10.14 and iOS 12.4.
Comment 1 Alex Szpakowski 2019-09-10 12:25:30 UTC
I mostly didn't add GetLayer and GetDrawableSize APIs because I didn't think they'd be too useful (the layer can be obtained from the view, and the drawable size is a property on the layer already). That said, the changes look fine to me. Sam/Ryan: thoughts?
Comment 2 Ryan C. Gordon 2020-04-10 04:38:15 UTC
This looks good. I merged it up to the latest and it's now https://hg.libsdl.org/SDL/rev/aca267270368, thanks!

--ryan.