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.

Replies

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?
  • this sample has two functions in AAPLRenderer:

    1. - (nonnull instancetype)initWithMetalKitView:(nonnull MTKView *)mtkView setting MTLCommandQueue, MTLTexture, MTLRenderPassDescriptor, MTLRenderPipelineState (offline & screen)

    2. - (void)drawInMTKView:(nonnull MTKView *)view creates object to render with vertices

    but what if I just want to render texture offline to save it as image? why then I need to use function [AAPLRenderer drawInMTKView:] which creates renderable object. as I thought I may create renderable object outside of function [AAPLRenderer drawInMTKView:]

    Can you please show example with offline render to texture without rendering in MTKView?

Add a Comment

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