Offscreen rendering examples

Hi,


I have serious difficulties with offscreen rendering in Metal or macOS. I can't find any example/demo project with solely offscreen rendering without any MTKView on 2nd pass. Just rendering to a texture with copying to a bitmap in system memory.


My code works strange, it returns a black picture on first run and starts to render frames only if I call rendering on timer event or on a button click. If I call rendering in a loop, it always returns a black picture.


I have no problem with usual rendering with MTKView.

We have this sample which renders to an offscreen texture. It does use a MetalKit view to display the offscreen texture in a second pass, but if you comment out the second block in -[AAPLRenderer drawInMTKView:], Metal still draws to the offscreen texture (you just won't be able to see it since the texture is never rendered to the screen).

It sounds like you're trying to render to the offscreen texture and then transfer the resulting contents to a bitmap in system memory. I'm wondering if the rendering is completing properly, but there are problems with the transfer to system memory. How are you doing this transfer? Are you sure the rendering has completed on the GPU before you begin transferring data to system memory?

I have placed a little Xcode project on github that renders to an off screen texture to do mouse picking.

Offscreen rendering examples
 
 
Q