Obtain textures to draw into from drawable objects.
When a texture contains visual data, you might want to display its contents onscreen; for example, you might want to render and display a frame of animation in a game, or show an image after applying a filter to it. When you create a texture using a standard method, you can use it only in Metal. Because the underlying display subsystem isn't connected to the texture, it can't display the texture. To display a texture onscreen, you need the display subsystem to create it for you, and you can achieve that by using Metal and Core Animation together.
In Metal, objects that contain displayable content are called drawables. The underlying protocol,
MTLDrawable, provides the interface you use to tell the display subsystem to present a drawable's contents.
MTLDrawable doesn't specify how you create the drawable's contents or even the process used to present those contents onscreen; those details are determined by higher levels of the display subsystem.
Currently, using Core Animation is the only way to get drawable objects. A
CAMetal object is a Core Animation layer that uses Metal drawable objects to specify its contents. These drawable objects conform to
MTLDrawable for presentation, and another protocol,
CAMetal, that provides properties to retrieve the drawable's texture. You render or write to this texture and then tell the drawable to present it, at which point Core Animation updates the layer's contents, which are then animated and composited normally.
Displaying Your Graphics Onscreen
To create a Metal app that displays graphics onscreen, use one of these options:
MTKView has an underlying
CAMetal object, so both choices provide similar workflows, but with different levels of detail and control. Use
CAMetal directly if you need behavior that you can’t create using an
Regardless of which mechanism you choose, pay close attention to how your app handles drawables. They exist within a limited and reusable resource pool, and a drawable may or may not be available when you request one. If none are available, Core Animation blocks your calling thread until a new drawable becomes available—usually at the next display refresh interval.