<!--
{
  "availability" : [
    "iOS: 5.0.0 - 12.0.0",
    "iPadOS: 5.0.0 - 12.0.0",
    "macOS: 10.8.0 - 10.14.0",
    "tvOS: 9.0.0 - 12.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "GLKit",
  "identifier" : "/documentation/GLKit/GLKTextureLoader",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "GLKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GLKTextureLoader"
  },
  "title" : "GLKTextureLoader"
}
-->

# GLKTextureLoader

A utility class that simplifies loading OpenGL or OpenGL ES texture datas from a variety of image file formats.

```
class GLKTextureLoader
```

## Overview

The [`GLKTextureLoader`](/documentation/GLKit/GLKTextureLoader) class can load two-dimensional or cubemap textures in most image formats supported by the Image I/O framework. In iOS, it can also load textures compressed in the PVRTC format. It can load the data synchronously or asynchronously.

To load textures synchronously, make a context with the desired sharegroup the current context, and then call one or more of the class methods. The returned texture info object includes details about the loaded texture.

To load textures asynchronously, your initialization code allocates and initializes a new [`GLKTextureLoader`](/documentation/GLKit/GLKTextureLoader) object using the sharegroup object that should be the destination for new textures. Then, to load a texture, your app calls one of the texture loader’s instance methods, passing in a completion handler block to be called when the texture has been loaded.

The following OpenGL properties are set for a newly created, non-mipmapped texture:

- `GL_TEXTURE_MIN_FILTER`:`GL_LINEAR`
- `GL_TEXTURE_MAG_FILTER`:`GL_LINEAR`
- `GL_TEXTURE_WRAP_S`:`GL_CLAMP_TO_EDGE`
- `GL_TEXTURE_WRAP_T`:`GL_CLAMP_TO_EDGE`

The following OpenGL properties are set for a newly created, mipmapped texture:

- `GL_TEXTURE_MIN_FILTER`:`GL_LINEAR_MIPMAP_LINEAR`
- `GL_TEXTURE_MAG_FILTER`:`GL_LINEAR`
- `GL_TEXTURE_WRAP_S`:`GL_CLAMP_TO_EDGE`
- `GL_TEXTURE_WRAP_T`:`GL_CLAMP_TO_EDGE`

The `GLKTextureLoader` and `GLKTextureInfo` classes do not manage the OpenGL texture for you. Once the texture is returned to your app, you are responsible for it. This means that after your app is finished using an OpenGL texture, it must explicitly deallocate it by calling the `glDeleteTextures` function.

## Topics

### Initialization

[`init(sharegroup:)`](/documentation/GLKit/GLKTextureLoader/init(sharegroup:))

Initializes a new texture loader object.

[`init(share:)`](/documentation/GLKit/GLKTextureLoader/init(share:))

Initializes a new texture loader object.

### Loading Textures from Files

[`texture(withContentsOfFile:options:)`](/documentation/GLKit/GLKTextureLoader/texture(withContentsOfFile:options:))

Loads a 2D texture image from a file and creates a new texture from the data.

[`texture(withContentsOfFile:options:queue:completionHandler:)`](/documentation/GLKit/GLKTextureLoader/texture(withContentsOfFile:options:queue:completionHandler:))

Asynchronously loads a 2D texture image from a file and creates a new texture from the data.

### Loading a Texture From a URL

[`texture(withContentsOf:options:)`](/documentation/GLKit/GLKTextureLoader/texture(withContentsOf:options:)-708ft)

Loads a 2D texture image from a URL and creates a new texture from the data.

[`texture(withContentsOf:options:queue:completionHandler:)`](/documentation/GLKit/GLKTextureLoader/texture(withContentsOf:options:queue:completionHandler:)-55187)

Asynchronously loads a 2D texture image from a URL and creates a new texture from the data.

### Creating Textures from In-Memory Representations

[`texture(withContentsOf:options:)`](/documentation/GLKit/GLKTextureLoader/texture(withContentsOf:options:)-2ljxb)

Loads a 2D texture image from a memory range and creates a new texture from the data.

[`texture(withContentsOf:options:queue:completionHandler:)`](/documentation/GLKit/GLKTextureLoader/texture(withContentsOf:options:queue:completionHandler:)-6n0cf)

Asynchronously loads a 2D texture image from a memory range and creates a new texture from the data.

### Creating Textures from CGImages

[`texture(with:options:)`](/documentation/GLKit/GLKTextureLoader/texture(with:options:))

Loads a 2D texture image from a Quartz image and creates a new texture from the data.

[`texture(with:options:queue:completionHandler:)`](/documentation/GLKit/GLKTextureLoader/texture(with:options:queue:completionHandler:))

Asynchronously loads a 2D texture image from a Quartz image and creates a new texture from the data.

### Loading Cube Maps from Files

[`cubeMap(withContentsOfFile:options:)`](/documentation/GLKit/GLKTextureLoader/cubeMap(withContentsOfFile:options:))

Loads a cube map texture image from a single file and creates a new texture from the data.

[`cubeMap(withContentsOfFile:options:queue:completionHandler:)`](/documentation/GLKit/GLKTextureLoader/cubeMap(withContentsOfFile:options:queue:completionHandler:))

Asynchronously loads a cube map texture image from a single file and creates a new texture from the data.

[`cubeMap(withContentsOfFiles:options:)`](/documentation/GLKit/GLKTextureLoader/cubeMap(withContentsOfFiles:options:))

Loads a cube map texture image from a series of files and creates a new texture from the data.

[`cubeMap(withContentsOfFiles:options:queue:completionHandler:)`](/documentation/GLKit/GLKTextureLoader/cubeMap(withContentsOfFiles:options:queue:completionHandler:))

Asynchronously loads a cube map texture image from a series of files and creates a new texture from the data.

### Loading Cube Maps from URLs

[`cubeMap(withContentsOf:options:)`](/documentation/GLKit/GLKTextureLoader/cubeMap(withContentsOf:options:))

Loads a cube map texture image from a single URL and creates a new texture from the data.

[`cubeMap(withContentsOf:options:queue:completionHandler:)`](/documentation/GLKit/GLKTextureLoader/cubeMap(withContentsOf:options:queue:completionHandler:))

Asynchronously loads a cube map texture image from a single URL and creates a new texture from the data.

### Constants

[`GLKTextureLoaderCallback`](/documentation/GLKit/GLKTextureLoaderCallback)

Signature for the block executed after an asynchronous texture loading operation completes.

[Texture Loading Options](/documentation/GLKit/texture-loading-options)

Keys to specify in a `textureOperations` dictionary.

[Texture Error Handling](/documentation/GLKit/texture-error-handling)

Strings used when handling error messages returned from a texture loading method.

[`GLKTextureLoaderError.Code`](/documentation/GLKit/GLKTextureLoaderError-swift.struct/Code)

Values to be returned when a texture loader encounters an error.

### Instance Methods

[`texture(withName:scaleFactor:bundle:options:queue:completionHandler:)`](/documentation/GLKit/GLKTextureLoader/texture(withName:scaleFactor:bundle:options:queue:completionHandler:))

### Type Methods

[`texture(withName:scaleFactor:bundle:options:)`](/documentation/GLKit/GLKTextureLoader/texture(withName:scaleFactor:bundle:options:))



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)