Interoperability of SpriteKit and Metal for offscreen rendering

Hello,

I am wordering wether or not it's possible to use a texture that has been rendered offscreen by SpriteKit as an overlay or as a simple texture in Metal, or if the same would be possible with a texture rendered offscreen in Metal as a background in SpriteKit. So far I haven't found anything that would have pointed me in the right direction. I know that both ways are working somehow and quite simple with SpriteKit and SceneKit but I need to use Metal instead of SceneKit.

Thanks

Replies

Is there really no way to render to a texture target in SpriteKit?

Or to use a Metal texture as a source texture to display in SpriteKit?

I don't know of a straightforward way to get a rendered SpriteKit scene into Metal. You could render the scene into an

SKTexture
, then create an
MTLTexture
using an
MTKTextureLoader
and the
cgImage
property of the
SKTexture
, but that involves multiple copies and allocations, which is suboptimal. I'd encourage you to file an enhancement radar at http://bugreport.apple.com describing exactly what you're trying to do. There may be a more efficient way for the API to expose a Metal texture you can use for further rendering without incurring a copy.

Ok, I could only find hints for the possibility to copy from one texture-api-format to the next too.

Thanks for the advice, I'll ask there. And thanks for your reply!

Tonight before reading this thread, I happened to follow the process wcm mentioned and wonder if there is a more efficient way. Did you find any other advice and file the enhancement radar? If so, what is the radar? Thanks so much.

I just submitted an enhancement report #28713434

Thank you for filing this.

I submitted similar enhancement request : 28738980

I'm thinking that the new SKRenderer class would fill this void -- not that there is sample code or usable docs available for it despite it being demoed over a year ago at WWDC2017.