MTKTextureLoader
An object that creates textures from existing data in common image formats.
Declaration
class MTKTextureLoaderOverview
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
newTexture(URL:options:)newTexture(URL:options:completionHandler:)newTextures(URLs:options:error:)newTextures(URLs:options:completionHandler:)
Loading Textures from Asset Catalogs
newTexture(name:scaleFactor:bundle:options:)newTexture(name:scaleFactor:bundle:options:completionHandler:)newTextures(names:scaleFactor:bundle:options:completionHandler:)newTexture(name:scaleFactor:displayGamut:bundle:options:)newTexture(name:scaleFactor:displayGamut:bundle:options:completionHandler:)newTextures(names:scaleFactor:displayGamut:bundle:options:completionHandler:)