GLKTextureLoader Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/GLKit.framework |
| Availability | Available in iOS 5.0 and later. |
| Declared in | GLKTextureLoader.h |
Overview
The GLKTextureLoader class simplifies the effort required to load your texture data. The GLKTextureLoader class can load two-dimensional or cubemap textures in most common image formats. 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 information includes details about the loaded texture.
To load textures asynchronously, your initialization code allocates and initializes a new 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_LINEARGL_TEXTURE_MAG_FILTER:GL_LINEARGL_TEXTURE_WRAP_S:GL_CLAMP_TO_EDGEGL_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_LINEARGL_TEXTURE_MAG_FILTER:GL_LINEARGL_TEXTURE_WRAP_S:GL_CLAMP_TO_EDGEGL_TEXTURE_WRAP_T:GL_CLAMP_TO_EDGE
Tasks
Initialization
Loading Textures from Files
-
+ textureWithContentsOfFile:options:error: -
– textureWithContentsOfFile:options:queue:completionHandler:
Loading a Texture From a URL
-
+ textureWithContentsOfURL:options:error: -
– textureWithContentsOfURL:options:queue:completionHandler:
Creating Textures from In-Memory Representations
-
+ textureWithContentsOfData:options:error: -
– textureWithContentsOfData:options:queue:completionHandler:
Creating Textures from CGImages
Loading Cube Maps from Files
-
+ cubeMapWithContentsOfFile:options:error: -
– cubeMapWithContentsOfFile:options:queue:completionHandler: -
+ cubeMapWithContentsOfFiles:options:error: -
– cubeMapWithContentsOfFiles:options:queue:completionHandler:
Loading Cube Maps from URLs
Class Methods
cubeMapWithContentsOfFile:options:error:
Loads a cube map texture image from a single file and creates a new texture from the data.
Parameters
- fileName
A path to the file to load.
- textureOperations
A dictionary that describes any additional steps you want the texture loader to take when loading the texture. See
“Texture Loading Options”.- outError
If an error occurs, upon return contains an
NSErrorobject that describes the problem.If you are not interested in this information, pass
NULL.
Return Value
A texture info object that describes the loaded texture or nil if an error occurred.
Discussion
The file is assumed to be a single image that includes the six faces of the cube map. The image’s height must be six times the width, and the images should be arranged in the following order from top to bottom: north, south, east, west, top, bottom. Alternatively, the image can have a width that is six times the height, and arranged from left to right, but this takes additional processing to load.
This class method loads the texture into the sharegroup attached to the current context for the thread this method is called on.
Availability
- Available in iOS 5.0 and later.
Declared In
GLKTextureLoader.hcubeMapWithContentsOfFiles:options:error:
Loads a cube map texture image from a series of files and creates a new texture from the data.
Parameters
- filePaths
An array of
NSURLorNSStringobjects that provide the paths to the six files that make up the cube map.- textureOperations
A dictionary that describes any additional steps you want the texture loader to take when loading the texture. See
“Texture Loading Options”.- outError
If an error occurs, upon return contains an
NSErrorobject that describes the problem.If you are not interested in this information, pass
NULL.
Return Value
A texture info object that describes the loaded texture or nil if an error occurred.
Discussion
The array of file paths must include six entries for the six faces of the cube map. The URLs should be arranged in the following order: Right(+x), Left(-x), Top(+y), Bottom(-y), Front(+z), Back(-z). This coordinate system is left-handed if you think of yourself within the cube. The coordinate system is right-handed if you think of yourself outside of the cube.
This class method loads the texture into the sharegroup attached to the current context for the thread this method is called on.
Availability
- Available in iOS 5.0 and later.
Declared In
GLKTextureLoader.hcubeMapWithContentsOfURL:options:error:
Loads a cube map texture image from a single URL and creates a new texture from the data.
Parameters
- filePath
A path to the image to load.
- textureOperations
A dictionary that describes any additional steps you want the texture loader to take when loading the texture. See
“Texture Loading Options”.- outError
If an error occurs, upon return contains an
NSErrorobject that describes the problem.If you are not interested in this information, pass
NULL.
Return Value
A texture info object that describes the loaded texture or nil if an error occurred.
Discussion
The file is assumed to be a single image that includes the six faces of the cube map. The image’s height must be six times the width, and the images should be arranged in the following order from top to bottom: Right(+x), Left(-x), Top(+y), Bottom(-y), Front(+z), Back(-z). This coordinate system is left-handed if you think of yourself within the cube. The coordinate system is right-handed if you think of yourself outside of the cube.
Alternatively, the image can have a width that is six times the height, and arranged from left to right, but this takes additional processing to load.
This class method loads the texture into the sharegroup attached to the current context for the thread this method is called on.
Availability
- Available in iOS 5.0 and later.
Declared In
GLKTextureLoader.htextureWithCGImage:options:error:
Loads a 2D texture image from a Quartz image and creates a new texture from the data.
Parameters
- cgImage
The Quartz image to be turned into a texture.
- textureOperations
A dictionary that describes any additional steps you want the texture loader to take when loading the texture. See
“Texture Loading Options”.- outError
If an error occurs, upon return contains an
NSErrorobject that describes the problem.If you are not interested in this information, pass
NULL.
Return Value
A texture info object that describes the loaded texture or nil if an error occurred.
Discussion
This class method loads the texture into the sharegroup attached to the current context for the thread this method is called on.
If the image was created using the CGBitmapImageContextCreate function, it must use one of the pixel formats described in Table 1. CGImages loaded from files typically are already in one of these formats.
Color Space | Pixel format and bitmap information constant |
|---|---|
Null | 8 bpp, 8 bpc, |
Gray | 8 bpp, 8 bpc, |
Gray | 8 bpp, 8 bpc, |
RGB | 32 bpp, 8 bpc, |
RGB | 32 bpp, 8 bpc, |
Availability
- Available in iOS 5.0 and later.
Declared In
GLKTextureLoader.htextureWithContentsOfData:options:error:
Loads a 2D texture image from a memory range and creates a new texture from the data.
Parameters
- data
The memory range to load as a texture.
- textureOperations
A dictionary that describes any additional steps you want the texture loader to take when loading the texture. See
“Texture Loading Options”.- outError
If an error occurs, upon return contains an
NSErrorobject that describes the problem.If you are not interested in this information, pass
NULL.
Return Value
A texture info object that describes the loaded texture or nil if an error occurred.
Discussion
This class method loads the texture into the sharegroup attached to the current context for the thread this method is called on.
Availability
- Available in iOS 5.0 and later.
Declared In
GLKTextureLoader.htextureWithContentsOfFile:options:error:
Loads a 2D texture image from a file and creates a new texture from the data.
Parameters
- fileName
A path to the file to load.
- textureOperations
A dictionary that describes any additional steps you want the texture loader to take when loading the texture. See
“Texture Loading Options”.- outError
If an error occurs, upon return contains an
NSErrorobject that describes the problem.If you are not interested in this information, pass
NULL.
Return Value
A texture info object that describes the loaded texture or nil if an error occurred.
Discussion
This class method loads the texture into the sharegroup attached to the current context for the thread this method is called on.
Availability
- Available in iOS 5.0 and later.
Declared In
GLKTextureLoader.htextureWithContentsOfURL:options:error:
Loads a 2D texture image from a URL and creates a new texture from the data.
Parameters
- filePath
A URL to the file to load.
- textureOperations
A dictionary that describes any additional steps you want the texture loader to take when loading the texture. See
“Texture Loading Options”.- outError
If an error occurs, upon return contains an
NSErrorobject that describes the problem.If you are not interested in this information, pass
NULL.
Return Value
A texture info object that describes the loaded texture or nil if an error occurred.
Discussion
This class method loads the texture into the sharegroup attached to the current context for the thread this method is called on.
Availability
- Available in iOS 5.0 and later.
Declared In
GLKTextureLoader.hInstance Methods
cubeMapWithContentsOfFile:options:queue:completionHandler:
Asynchronously loads a cube map texture image from a single file and creates a new texture from the data.
Parameters
- fileName
A path to the file to load.
- textureOperations
A dictionary that describes any additional steps you want the texture loader to take when loading the texture. See
“Texture Loading Options”.- queue
A dispatch queue that your block is called on when the task completes. If
NULLis passed, the block is called on the main dispatch queue.- block
A block to be called when the task completes.
The block receives the following parameters:
- GLTextureName
The texture name for the newly created texture. If an error occurred, this value is
0.- error
If the operation was successful, this value is nil; otherwise, this parameter holds an object that describes the problem that occurred.
Discussion
This method is identical to cubeMapWithContentsOfFile:options:error:, except that it loads the texture asynchronously. When this method is called, it creates a new background task to handle the request and then returns control to your app. Later, when the task is complete, GLKit calls your completion handler on the queue you provided.
Availability
- Available in iOS 5.0 and later.
Declared In
GLKTextureLoader.hcubeMapWithContentsOfFiles:options:queue:completionHandler:
Asynchronously loads a cube map texture image from a series of files and creates a new texture from the data.
Parameters
- filePaths
An array of paths to the six files that make up the cube map.
- textureOperations
A dictionary that describes any additional steps you want the texture loader to take when loading the texture. See
“Texture Loading Options”.- queue
A dispatch queue that your block is called on when the task completes. If
NULLis passed, the block is called on the main dispatch queue.- block
A block to be called when the task completes.
The block receives the following parameters:
- GLTextureName
The texture name for the newly created texture. If an error occurred, this value is
0.- error
If the operation was successful, this value is nil; otherwise, this parameter holds an object that describes the problem that occurred.
Discussion
This method is identical to cubeMapWithContentsOfURL:options:error:, except that it loads the texture asynchronously. When this method is called, it creates a new background task to handle the request and then returns control to your app. Later, when the task is complete, GLKit calls your completion handler on the queue you provided.
Availability
- Available in iOS 5.0 and later.
Declared In
GLKTextureLoader.hcubeMapWithContentsOfURL:options:queue:completionHandler:
Asynchronously loads a cube map texture image from a single URL and creates a new texture from the data.
Parameters
- filePath
A path to the image to load.
- textureOperations
A dictionary that describes any additional steps you want the texture loader to take when loading the texture. See
“Texture Loading Options”.- queue
A dispatch queue that your block is called on when the task completes. If
NULLis passed, the block is called on the main dispatch queue.- block
A block to be called when the task completes.
The block receives the following parameters:
- GLTextureName
The texture name for the newly created texture. If an error occurred, this value is
0.- error
If the operation was successful, this value is nil; otherwise, this parameter holds an object that describes the problem that occurred.
Discussion
This method is identical to cubeMapWithContentsOfURL:options:error:, except that it loads the texture asynchronously. When this method is called, it creates a new background task to handle the request and then returns control to your app. Later, when the task is complete, GLKit calls your completion handler on the queue you provided.
Availability
- Available in iOS 5.0 and later.
Declared In
GLKTextureLoader.hinitWithSharegroup:
Initializes a new texture loader object.
Parameters
- sharegroup
The sharegroup used to store new textures.
Return Value
A newly initialized texture loader.
Discussion
You only create a texture loader object when your app needs to load textures asynchronously.
Availability
- Available in iOS 5.0 and later.
Declared In
GLKTextureLoader.htextureWithCGImage:options:queue:completionHandler:
Asynchronously loads a 2D texture image from a Quartz image and creates a new texture from the data.
Parameters
- cgImage
The Quartz image to be turned into a texture.
- textureOperations
A dictionary that describes any additional steps you want the texture loader to take when loading the texture. See
“Texture Loading Options”.- queue
A dispatch queue that your block is called on when the task completes. If
NULLis passed, the block is called on the main dispatch queue.- block
A block to be called when the task completes.
The block receives the following parameters:
- GLTextureName
The texture name for the newly created texture. If an error occurred, this value is
0.- error
If the operation was successful, this value is nil; otherwise, this parameter holds an object that describes the problem that occurred.
Discussion
This method is identical to textureWithCGImage:options:error:, except that it loads the texture asynchronously. When this method is called, it creates a new background task to handle the request and then returns control to your app. Later, when the task is complete, GLKit calls your completion handler on the queue you provided.
Availability
- Available in iOS 5.0 and later.
See Also
Declared In
GLKTextureLoader.htextureWithContentsOfData:options:queue:completionHandler:
Asynchronously loads a 2D texture image from a memory range and creates a new texture from the data.
Parameters
- data
The memory range to load as a texture.
- textureOperations
A dictionary that describes any additional steps you want the texture loader to take when loading the texture. See
“Texture Loading Options”.- queue
A dispatch queue that your block is called on when the task completes. If
NULLis passed, the block is called on the main dispatch queue.- block
A block to be called when the task completes.
The block receives the following parameters:
- GLTextureName
The texture name for the newly created texture. If an error occurred, this value is
0.- error
If the operation was successful, this value is nil; otherwise, this parameter holds an object that describes the problem that occurred.
Discussion
This method is identical to textureWithContentsOfData:options:error:, except that it loads the texture asynchronously. When this method is called, it creates a new background task to handle the request and then returns control to your app. Later, when the task is complete, GLKit calls your completion handler on the queue you provided.
Availability
- Available in iOS 5.0 and later.
Declared In
GLKTextureLoader.htextureWithContentsOfFile:options:queue:completionHandler:
Asynchronously loads a 2D texture image from a file and creates a new texture from the data.
Parameters
- fileName
A path to the file to load.
- textureOperations
A dictionary that describes any additional steps you want the texture loader to take when loading the texture. See
“Texture Loading Options”.- queue
A dispatch queue that your block is called on when the task completes. If
NULLis passed, the block is called on the main dispatch queue.- block
A block to be called when the task completes.
The block receives the following parameters:
- GLTextureName
The texture name for the newly created texture. If an error occurred, this value is
0.- error
If the operation was successful, this value is nil; otherwise, this parameter holds an object that describes the problem that occurred.
Discussion
This method is identical to textureWithContentsOfFile:options:error:, except that it loads the texture asynchronously. When this method is called, it creates a new background task to handle the request and then returns control to your app. Later, when the task is complete, GLKit calls your completion handler on the queue you provided.
Availability
- Available in iOS 5.0 and later.
Declared In
GLKTextureLoader.htextureWithContentsOfURL:options:queue:completionHandler:
Asynchronously loads a 2D texture image from a URL and creates a new texture from the data.
Parameters
- filePath
A URL to the file to load.
- textureOperations
A dictionary that describes any additional steps you want the texture loader to take when loading the texture. See
“Texture Loading Options”.- queue
A dispatch queue that your block is called on when the task completes. If
NULLis passed, the block is called on the main dispatch queue.- block
A block to be called when the task completes.
The block receives the following parameters:
- GLTextureName
The texture name for the newly created texture. If an error occurred, this value is
0.- error
If the operation was successful, this value is nil; otherwise, this parameter holds an object that describes the problem that occurred.
Discussion
This method is identical to textureWithContentsOfURL:options:error:, except that it loads the texture asynchronously. When this method is called, it creates a new background task to handle the request and then returns control to your app. Later, when the task is complete, GLKit calls your completion handler on the queue you provided.
Availability
- Available in iOS 5.0 and later.
Declared In
GLKTextureLoader.hConstants
Texture Loading Options
Keys to specify in a textureOperations dictionary.
NSString *const GLKTextureLoaderApplyPremultiplication; NSString *const GLKTextureLoaderGenerateMipmaps; NSString *const GLKTextureLoaderOriginBottomLeft; NSString *const GLKTextureLoaderGrayscaleAsAlpha;
Constants
GLKTextureLoaderApplyPremultiplicationThis key specifies whether the data in the image should be premultiplied before being loaded into the sharegroup. The value for this key is an
NSNumberobject that specifies a boolean value. IfNO, the data is loaded into the sharegroup without being modified. IfYES, the red, green and blue components of each pixel are multiplied by the alpha value. If the key is not specified, the default value isNO. Never specifyYESfor a texture that is in a compressed format.Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderGenerateMipmapsThis key specifies whether mipmaps should be created for the texture. The value for this key is an
NSNumberobject that specifies a boolean value. IfNO, only the texture is loaded. IfYES, a full set of mipmap levels are generated for the texture when the texture is created. TheGL_TEXTURE_MIN_FILTERparameter for the texture is changed toGL_LINEAR_MIPMAP_LINEARwhen mipmaps are generated. If the key is not specified, the default value isNO.Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderOriginBottomLeftThis key specifies whether the image data should be vertically flipped to match OpenGL’s coordinate system. The value for this key is an
NSNumberobject that specifies a boolean value. IfNO, the image data is not flipped. IfYES, the image data is flipped before being loaded. If the key is not specified, the default value isYES.Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderGrayscaleAsAlphaThis key specifies whether the image data in a grayscale image should be treated as alpha information. The value for this key is an
NSNumberobject that specifies a boolean value. IfNO, the image data is treated as luminance data. IfYES, the image data is treated as alpha data. The default value isNO. This key is ignored if the source image is not a grayscale image.Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.
Texture Error Handling
Strings used when handling NSError messages returned from a texture loading method.
extern NSString *const GLKTextureLoaderErrorDomain; extern NSString *const GLKTextureLoaderErrorKey; extern NSString *const GLKTextureLoaderGLErrorKey;
Constants
GLKTextureLoaderErrorDomainThe error doman used by GLKit when returning texture loading errors.
Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderErrorKeyA key used to retrieve an error string from an error object’s
userInfodictionary.Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderGLErrorKeyA key used to retrieve additional information from an error object’s
userInfodictionary.Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.
Texture Loading Error Codes
Values to be returned in an NSError when a texture loader encounters an error.
enum {
GLKTextureLoaderErrorFileOrURLNotFound = 0,
GLKTextureLoaderErrorInvalidNSData = 1,
GLKTextureLoaderErrorInvalidCGImage = 2,
GLKTextureLoaderErrorUnknownPathType = 3,
GLKTextureLoaderErrorUnknownFileType = 4,
GLKTextureLoaderErrorPVRAtlasUnsupported = 5,
GLKTextureLoaderErrorCubeMapInvalidNumFiles = 6,
GLKTextureLoaderErrorCompressedTextureUpload = 7,
GLKTextureLoaderErrorUncompressedTextureUpload = 8,
GLKTextureLoaderErrorUnsupportedCubeMapDimensions = 9,
GLKTextureLoaderErrorUnsupportedBitDepth = 10,
GLKTextureLoaderErrorUnsupportedPVRFormat = 11,
GLKTextureLoaderErrorDataPreprocessingFailure = 12
GLKTextureLoaderErrorMipmapUnsupported = 13,
GLKTextureLoaderErrorUnsupportedOrientation = 14,
GLKTextureLoaderErrorReorientationFailure = 15,
GLKTextureLoaderErrorAlphaPremultiplicationFailure = 16,
GLKTextureLoaderErrorInvalidEAGLContext = 17
};
typedef NSUInteger GLKTextureLoaderError;
Constants
GLKTextureLoaderErrorFileOrURLNotFoundA file could not be found at the path provided.
Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderErrorInvalidNSDataThe data provided is not in a recognized image format.
Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderErrorInvalidCGImageThe
CGImageprovided was invalid.Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderErrorUnknownPathTypeThe path type was unrecognized.
Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderErrorUnknownFileTypeThe file was in an unrecognized format.
Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderErrorPVRAtlasUnsupportedCube maps may not be compressed in PVRTC format.
Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderErrorCubeMapInvalidNumFilesThe incorrect number of files were specified for the cube map.
Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderErrorCompressedTextureUploadA compressed texture could not be uploaded.
Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderErrorUncompressedTextureUploadAn uncompressed texture could not be uploaded.
Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderErrorUnsupportedCubeMapDimensionsThe cube map’s dimensions are incorrect.
Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderErrorUnsupportedBitDepthThe data in the source image has an unsupported bit depth.
Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderErrorUnsupportedPVRFormatThe data in the PVRTC compressed format is in an unsupported format.
Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderErrorDataPreprocessingFailureThe data could not be preprocessed correctly.
Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderErrorMipmapUnsupportedThe texture source data does not allow mipmaps to be generated.
Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderErrorUnsupportedOrientationThe texture source data is stored with an unsupported origin position.
Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderErrorReorientationFailureThe texture source data does not allow the image to be reoriented.
Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderErrorAlphaPremultiplicationFailureThe texture source data does not allow the alpha to be premultiplied.
Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.GLKTextureLoaderErrorInvalidEAGLContextThe EAGL context was not a valid context.
Available in iOS 5.0 and later.
Declared in
GLKTextureLoader.h.
© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-07-17)