Contents

Onscreen presentation

Show the output from a GPU’s rendering pass to the user in your app.

Overview

A texture contains visual data that you may want to display onscreen, such as a filtered image or a frame of animation in a game. To display a texture on a device’s screen, you need to create or acquire a drawable texture from Core Animation.

In Metal, a drawable is a texture that bridges the display subsystem within Core Animation to Metal. You can use a drawable as the output of a render pass and then present it to a display with its MTLDrawable protocol.

To display content on a device’s screen, add one of these to your Metal app:

With a CAMetalLayer instance, your app can get drawable instances by calling its nextDrawable() method. Each drawable conforms to the CAMetalDrawable protocol, which has a texture property that a render pass can use as its output. See Creating a custom Metal view for more information.

Alternatively, your app can use an MTKView and its currentDrawable property. This MetalKit class provides a default implementation of a Metal-aware view that uses an underlying CAMetalLayer instance. A MetalKit view provides a quick and easy way to present your app’s content, but gives you less control than using a CAMetalLayer directly. See Using Metal to draw a view’s contents for more information.

Whichever mechanism you choose, pay close attention to how your app handles drawables. Each drawable comes from a limited and reusable resource pool. A drawable may not always be available when your app requests one. When that happens, Core Animation blocks the calling thread until a drawable becomes available — usually at the display’s next refresh interval.

Topics

Presenting with core animation

Presenting with MetalKit

See Also

Presentation