Contents

MTKTextureLoader

An object that creates textures from existing data in common image formats.

Declaration

class MTKTextureLoader

Overview

Use the MTKTextureLoader class to create a Metal texture from existing image data.

This class supports common file formats, like PNG, JPEG, and TIFF. It also loads 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 create textures synchronously or asynchronously using MTKTextureLoader methods that return MTLTexture instances. Pass options to these methods that customize the image-loading and texture-creation process.

First create an MTKTextureLoader instance, passing the device that it uses to create textures. Then use one of the texture loader’s methods to create a texture. The code example below synchronously creates a texture from data at a URL, using the default options:

If you use custom data formats, or change the image data at runtime, use MTLTexture methods instead. For more information, see Creating and sampling textures.

Topics

Creating a Texture Loader

Loading Textures from URLs

Loading Textures from Asset Catalogs

Loading Textures from Core Graphics Images

Loading Textures from In-Memory Data Representations

Loading Textures from Model I/O Representations

Specifying Loading Options

Completing a Texture Loading Operation

Handling Errors