All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | Typedefs | Functions
loader.c File Reference

Functions for instantiating GL or GLES textures from KTX files. More...

#include <string.h>
#include <stdlib.h>
#include "KHR/khrplatform.h"
#include "ktx.h"
#include "ktxint.h"

Classes

struct  ktxStream
 
struct  ktxMem
 

Macros

#define KTX_GL_UNPACK_ALIGNMENT   4
 

Typedefs

typedef int(* ktxStream_read )(void *dst, const GLsizei count, void *src)
 
typedef int(* ktxStream_skip )(const GLsizei count, void *src)
 

Functions

KTX_error_code ktxLoadTextureF (FILE *file, GLuint *pTexture, GLenum *pTarget, KTX_dimensions *pDimensions, GLboolean *pIsMipmapped, GLenum *pGlerror, unsigned int *pKvdLen, unsigned char **ppKvd)
 Load a GL texture object from 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)
 Load a GL texture object from 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)
 Load a GL texture object from KTX formatted data in memory. More...
 

Detailed Description

Functions for instantiating GL or GLES textures from KTX files.

Author
Georg Kolling, Imagination Technology
Mark Callow, HI Corporation
Revision:
16722
Date:
2012-01-26 17:09:37 +0900 #

Function Documentation

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

Load a GL texture object from a stdio FILE stream.

This function will unpack GL_ETC1_RGB8_OES format compressed textures in software when the format is not supported by the GL implementation, provided the library has been compiled with SUPPORT_SOFTWARE_ETC_UNPACK defined as 1.

Parameters
[in]filepointer to the stdio FILE stream from which to load.
[in,out]pTexturename of the GL texture 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 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_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 
)

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

Parameters
[in]bytespointer to the array of bytes containing the KTX format data to load.
[in]sizesize of the memory array containing the KTX format data.
[in,out]pTexturename of the GL texture 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_error_code ktxLoadTextureN ( const char *const  filename,
GLuint *  pTexture,
GLenum *  pTarget,
KTX_dimensions pDimensions,
GLboolean *  pIsMipmapped,
GLenum *  pGlerror,
unsigned int *  pKvdLen,
unsigned char **  ppKvd 
)

Load a GL texture object from a named file on disk.

Parameters
[in]filenamepointer to a C string that contains the path of the file to load.
[in,out]pTexturename of the GL texture 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.