libktx - The KTX Library
OpenGL Texture Image Loader

Create texture objects in current OpenGL context. More...

Functions

KTX_error_code ktxLoadTextureF (FILE *file, GLuint *pTexture, GLenum *pTarget, KTX_dimensions *pDimensions, GLboolean *pIsMipmapped, GLenum *pGlerror, unsigned int *pKvdLen, unsigned char **ppKvd)
 Create a GL texture object from KTX data in a stdio FILE stream. More...
 
KTX_error_code ktxLoadTextureN (const char *const filename, GLuint *pTexture, GLenum *pTarget, KTX_dimensions *pDimensions, GLboolean *pIsMipmapped, GLenum *pGlerror, unsigned int *pKvdLen, unsigned char **ppKvd)
 Create a GL texture object from KTX data in a named file on disk. More...
 
KTX_error_code ktxLoadTextureM (const void *bytes, GLsizei size, GLuint *pTexture, GLenum *pTarget, KTX_dimensions *pDimensions, GLboolean *pIsMipmapped, GLenum *pGlerror, unsigned int *pKvdLen, unsigned char **ppKvd)
 Create a GL texture object from KTX formatted data in memory. More...
 
KTX_error_code ktxTexture::ktxTexture_GLUpload (ktxTexture *This, GLuint *pTexture, GLenum *pTarget, GLenum *pGlerror)
 Create a GL texture object from a ktxTexture object. More...
 

Detailed Description

Create texture objects in current OpenGL context.

Function Documentation

§ ktxLoadTextureF()

KTX_error_code ktxLoadTextureF ( FILE *  file,
GLuint *  pTexture,
GLenum *  pTarget,
KTX_dimensions pDimensions,
GLboolean *  pIsMipmapped,
GLenum *  pGlerror,
unsigned int *  pKvdLen,
unsigned char **  ppKvd 
)

Create a GL texture object from KTX data in a stdio FILE stream.

Deprecated:
Use ktxTexture_CreateFromStdioStream() and ktxTexture_GLUpload().

Sets the texture object's GL_TEXTURE_MAX_LEVEL parameter according to the number of levels in the ktxStream, provided the library has been compiled with a version of gl.h where GL_TEXTURE_MAX_LEVEL is defined.

Unpacks compressed GL_ETC1_RGB8_OES and GL_ETC2_* format textures in software when the format is not supported by the GL context, provided the library has been compiled with SUPPORT_SOFTWARE_ETC_UNPACK defined as 1.

Also converts texture with legacy formats to their modern equivalents when the format is not supported by the GL context, provided the library has been compiled with SUPPORT_LEGACY_FORMAT_CONVERSION defined as 1.

Parameters
[in]filestdio stream FILE pointer
[in,out]pTexturename of the GL texture object to load. If NULL or if *pTexture == 0 the function will generate a texture name. The function binds either the generated name or the name given in *pTexture to the texture target returned in *pTarget, before loading the texture data. If pTexture is not NULL and a name was generated, the generated name will be returned in *pTexture.
[out]pTarget*pTarget is set to the texture target used. The target is chosen based on the file contents.
[out]pDimensionsIf pDimensions is not NULL, the width, height and depth of the texture's base level are returned in the fields of the KTX_dimensions structure to which it points.
[out]pIsMipmappedIf pIsMipmapped is not NULL, *pIsMipmapped is set to GL_TRUE if the KTX texture is mipmapped, GL_FALSE otherwise.
[out]pGlerror*pGlerror is set to the value returned by glGetError when this function returns the error KTX_GL_ERROR. glerror can be NULL.
[in,out]pKvdLenIf not NULL, *pKvdLen is set to the number of bytes of key-value data pointed at by *ppKvd. Must not be NULL, if ppKvd is not NULL.
[in,out]ppKvdIf not NULL, *ppKvd is set to the point to a block of memory containing key-value data read from the file. The application is responsible for freeing the memory.
Returns
KTX_SUCCESS on success, other KTX_* enum values on error.
Exceptions
KTX_INVALID_VALUEtarget is NULL or the size of a mip level is greater than the size of the preceding level.
KTX_INVALID_OPERATIONppKvd is not NULL but pKvdLen is NULL.
KTX_UNEXPECTED_END_OF_FILEthe file does not contain the expected amount of data.
KTX_OUT_OF_MEMORYSufficient memory could not be allocated for the underlying ktxTexture object or to store the requested key-value data.
KTX_GL_ERRORA GL error was raised by glBindTexture, glGenTextures or gl*TexImage*. The GL error will be returned in *glerror, if glerror is not NULL.
KTX_UNSUPPORTED_TEXTURE_TYPEThe type of texture is not supported by the current OpenGL context.
Examples:
glloader.c.

§ ktxLoadTextureM()

KTX_error_code ktxLoadTextureM ( const void *  bytes,
GLsizei  size,
GLuint *  pTexture,
GLenum *  pTarget,
KTX_dimensions pDimensions,
GLboolean *  pIsMipmapped,
GLenum *  pGlerror,
unsigned int *  pKvdLen,
unsigned char **  ppKvd 
)

Create a GL texture object from KTX formatted data in memory.

Deprecated:
Use ktxTexture_CreateFromMemory() and ktxTexture_GLUpload().
Parameters
[in]bytespointer to the array of bytes containing the KTX data to load.
[in]sizesize of the memory array containing the KTX format data.
[in,out]pTexturename of the GL texture object to load. See ktxLoadTextureF() for details.
[out]pTarget*pTarget is set to the texture target used. See ktxLoadTextureF() for details.
[out]pDimensionsthe texture's base level width depth and height are returned in structure to which this points. See ktxLoadTextureF() for details.
[out]pIsMipmapped*pIsMipMapped is set to indicate if the loaded texture is mipmapped. See ktxLoadTextureF() for details.
[out]pGlerror*pGlerror is set to the value returned by glGetError when this function returns the error KTX_GL_ERROR. glerror can be NULL.
[in,out]pKvdLenIf not NULL, *pKvdLen is set to the number of bytes of key-value data pointed at by *ppKvd. Must not be NULL, if ppKvd is not NULL.
[in,out]ppKvdIf not NULL, *ppKvd is set to the point to a block of memory containing key-value data read from the file. The application is responsible for freeing the memory.
Returns
KTX_SUCCESS on success, other KTX_* enum values on error.
Exceptions
KTX_FILE_OPEN_FAILEDThe specified memory could not be opened as a file.
KTX_INVALID_VALUESee ktxLoadTextureF() for causes.
KTX_INVALID_OPERATIONSee ktxLoadTextureF() for causes.
KTX_UNEXPECTED_END_OF_FILESee ktxLoadTextureF() for causes.
KTX_GL_ERRORSee ktxLoadTextureF() for causes.
KTX_UNSUPPORTED_TEXTURE_TYPESee ktxLoadTextureF() for causes.
Examples:
glloader.c.

§ ktxLoadTextureN()

KTX_error_code ktxLoadTextureN ( const char *const  filename,
GLuint *  pTexture,
GLenum *  pTarget,
KTX_dimensions pDimensions,
GLboolean *  pIsMipmapped,
GLenum *  pGlerror,
unsigned int *  pKvdLen,
unsigned char **  ppKvd 
)

Create a GL texture object from KTX data in a named file on disk.

Deprecated:
Use ktxTexture_CreateFromNamedFile() and ktxTexture_GLUpload().
Parameters
[in]filenamepointer to a C string that contains the path of the file to load.
[in,out]pTexturename of the GL texture object to load. See ktxLoadTextureF() for details.
[out]pTarget*pTarget is set to the texture target used. See ktxLoadTextureF() for details.
[out]pDimensionsthe texture's base level width depth and height are returned in structure to which this points. See ktxLoadTextureF() for details.
[out]pIsMipmappedpIsMipMapped is set to indicate if the loaded texture is mipmapped. See ktxLoadTextureF() for details.
[out]pGlerror*pGlerror is set to the value returned by glGetError when this function returns the error KTX_GL_ERROR. glerror can be NULL.
[in,out]pKvdLenIf not NULL, *pKvdLen is set to the number of bytes of key-value data pointed at by *ppKvd. Must not be NULL, if ppKvd is not NULL.
[in,out]ppKvdIf not NULL, *ppKvd is set to the point to a block of memory containing key-value data read from the file. The application is responsible for freeing the memory.
Returns
KTX_SUCCESS on success, other KTX_* enum values on error.
Exceptions
KTX_FILE_OPEN_FAILEDThe specified file could not be opened.
KTX_INVALID_VALUESee ktxLoadTextureF() for causes.
KTX_INVALID_OPERATIONSee ktxLoadTextureF() for causes.
KTX_UNEXPECTED_END_OF_FILESee ktxLoadTextureF() for causes.
KTX_GL_ERRORSee ktxLoadTextureF() for causes.
KTX_UNSUPPORTED_TEXTURE_TYPESee ktxLoadTextureF() for causes.
Examples:
glloader.c.

§ ktxTexture_GLUpload()

KTX_error_code ktxTexture_GLUpload ( ktxTexture This,
GLuint *  pTexture,
GLenum *  pTarget,
GLenum *  pGlerror 
)

Create a GL texture object from a ktxTexture object.

Sets the texture object's GL_TEXTURE_MAX_LEVEL parameter according to the number of levels in the KTX data, provided the library has been compiled with a version of gl.h where GL_TEXTURE_MAX_LEVEL is defined.

Unpacks compressed GL_ETC1_RGB8_OES and GL_ETC2_* format textures in software when the format is not supported by the GL context, provided the library has been compiled with SUPPORT_SOFTWARE_ETC_UNPACK defined as 1.

It will also convert textures with legacy formats to their modern equivalents when the format is not supported by the GL context, provided the library has been compiled with SUPPORT_LEGACY_FORMAT_CONVERSION defined as 1.

Parameters
[in]Thishandle of the ktxTexture to upload.
[in,out]pTexturename of the GL texture object to load. If NULL or if *pTexture == 0 the function will generate a texture name. The function binds either the generated name or the name given in *pTexture to the texture target returned in *pTarget, before loading the texture data. If pTexture is not NULL and a name was generated, the generated name will be returned in *pTexture.
[out]pTarget*pTarget is set to the texture target used. The target is chosen based on the file contents.
[out]pGlerror*pGlerror is set to the value returned by glGetError when this function returns the error KTX_GL_ERROR. glerror can be NULL.
Returns
KTX_SUCCESS on success, other KTX_* enum values on error.
Exceptions
KTX_INVALID_VALUEThis or target is NULL or the size of a mip level is greater than the size of the preceding level.
KTX_GL_ERRORA GL error was raised by glBindTexture, glGenTextures or gl*TexImage*. The GL error will be returned in *glerror, if glerror is not NULL.
KTX_UNSUPPORTED_TEXTURE_TYPEThe type of texture is not supported by the current OpenGL context.
Examples:
glloader.c.