An object that decodes common image formats into Metal textures for use in your app.
- iOS 9.0+
- macOS 10.11+
- Mac Catalyst 13.0+
- tvOS 9.0+
MTKTexture to create a Metal texture with preexisting data as its contents. This class can read common file formats like PNG, JPEG, and TIFF. It can also load image data from KTX and PVR files, asset catalogs, Core Graphics images, and other sources. It infers the output texture format and pixel format from the image data. You can specify options to alter the image loading and texture creation process.
You can create textures synchronously or asynchronously.
MTKTexture methods return
MTLTexture objects. You are responsible for maintaining strong references to the textures after you create them.
MTKTexture object using the device object that it should use to create textures, then call one of the texture loader's methods to create a texture. The code listing below synchronously creates a texture from data stored at a URL, using the default options:
You'd typically use
MTKTexture to create a texture when you need basic texture loading behavior. If you have custom data formats, or need to change the texture's contents at runtime, use methods on
MTLTexture instead. For more information, see Creating and Sampling Textures.