/** * @~English * @brief Load a GL texture object from a stdio FILE stream. * * This function will unpack 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 texture with legacy formats to their modern equivalents * when the format is not supported by the GL context, provided that the library * has been compiled with SUPPORT_LEGACY_FORMAT_CONVERSION defined as 1. * * @param [in] file pointer to the stdio FILE stream from which to * load. * @param [in,out] pTexture name of the GL texture to load. If NULL or if * <tt>*pTexture == 0</tt> the function will generate * a texture name. The function binds either the * generated name or the name given in @p *pTexture * to the texture target returned in @p *pTarget, * before loading the texture data. If @p pTexture * is not NULL and a name was generated, the generated * name will be returned in *pTexture. * @param [out] pTarget @p *pTarget is set to the texture target used. The * target is chosen based on the file contents. * @param [out] pDimensions If @p 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. * @param [out] pIsMipmapped * If @p pIsMipmapped is not NULL, @p *pIsMipmapped is set * to GL_TRUE if the KTX texture is mipmapped, GL_FALSE * otherwise. * @param [out] pGlerror @p *pGlerror is set to the value returned by * glGetError when this function returns the error * KTX_GL_ERROR. glerror can be NULL. * @param [in,out] pKvdLen If not NULL, @p *pKvdLen is set to the number of bytes * of key-value data pointed at by @p *ppKvd. Must not be * NULL, if @p ppKvd is not NULL. * @param [in,out] ppKvd If not NULL, @p *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. * * * @return KTX_SUCCESS on success, other KTX_* enum values on error. * * @exception KTX_INVALID_VALUE @p target is @c NULL or the size of a mip * level is greater than the size of the * preceding level. * @exception KTX_INVALID_OPERATION @p ppKvd is not NULL but pKvdLen is NULL. * @exception KTX_UNEXPECTED_END_OF_FILE the file does not contain the * expected amount of data. * @exception KTX_OUT_OF_MEMORY Sufficient memory could not be allocated to store * the requested key-value data. * @exception KTX_GL_ERROR A GL error was raised by glBindTexture, * glGenTextures or gl*TexImage*. The GL error * will be returned in @p *glerror, if glerror * is not @c NULL. */ KTX_error_code ktxLoadTextureF(FILE* file, GLuint* pTexture, GLenum* pTarget, KTX_dimensions* pDimensions, GLboolean* pIsMipmapped, GLenum* pGlerror, unsigned int* pKvdLen, unsigned char** ppKvd) { struct ktxStream stream; if (!ktxFileInit(&stream, file)) { return KTX_FILE_OPEN_FAILED; } return ktxLoadTextureS(&stream, pTexture, pTarget, pDimensions, pIsMipmapped, pGlerror, pKvdLen, ppKvd); }
/** * @~English * @brief Load a GL texture object from a stdio FILE stream. * * This function will unpack 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 texture with legacy formats to their modern equivalents * when the format is not supported by the GL context, provided that the library * has been compiled with SUPPORT_LEGACY_FORMAT_CONVERSION defined as 1. * * @param [in] file pointer to the stdio FILE stream from which to * load. * @param [in,out] pTexture name of the GL texture to load. If NULL or if * <tt>*pTexture == 0</tt> the function will generate * a texture name. The function binds either the * generated name or the name given in @p *pTexture * to the texture target returned in @p *pTarget, * before loading the texture data. If @p pTexture * is not NULL and a name was generated, the generated * name will be returned in *pTexture. * @param [out] pTarget @p *pTarget is set to the texture target used. The * target is chosen based on the file contents. * @param [out] pDimensions If @p 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. * @param [out] pIsMipmapped * If @p pIsMipmapped is not NULL, @p *pIsMipmapped is set * to GL_TRUE if the KTX texture is mipmapped, GL_FALSE * otherwise. * @param [out] pGlerror @p *pGlerror is set to the value returned by * glGetError when this function returns the error * KTX_GL_ERROR. glerror can be NULL. * @param [in,out] pKvdLen If not NULL, @p *pKvdLen is set to the number of bytes * of key-value data pointed at by @p *ppKvd. Must not be * NULL, if @p ppKvd is not NULL. * @param [in,out] ppKvd If not NULL, @p *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. * * * @return KTX_SUCCESS on success, other KTX_* enum values on error. * * @exception KTX_INVALID_VALUE @p target is @c NULL or the size of a mip * level is greater than the size of the * preceding level. * @exception KTX_INVALID_OPERATION @p ppKvd is not NULL but pKvdLen is NULL. * @exception KTX_UNEXPECTED_END_OF_FILE the file does not contain the * expected amount of data. * @exception KTX_OUT_OF_MEMORY Sufficient memory could not be allocated to store * the requested key-value data. * @exception KTX_GL_ERROR A GL error was raised by glBindTexture, * glGenTextures or gl*TexImage*. The GL error * will be returned in @p *glerror, if glerror * is not @c NULL. */ KTX_error_code ktxLoadTextureF(FILE* file, GLuint* pTexture, GLenum* pTarget, KTX_dimensions* pDimensions, GLboolean* pIsMipmapped, GLenum* pGlerror, unsigned int* pKvdLen, unsigned char** ppKvd) { struct ktxStream stream; KTX_error_code errorCode = KTX_SUCCESS; errorCode = ktxFileInit(&stream, file); if (errorCode != KTX_SUCCESS) return errorCode; return ktxLoadTextureS(&stream, pTexture, pTarget, pDimensions, pIsMipmapped, pGlerror, pKvdLen, ppKvd); }
/** * @~English * @brief Load a GL texture object from KTX formatted data in memory. * * @param [in] bytes pointer to the array of bytes containing * the KTX format data to load. * @param [in] size size of the memory array containing the * KTX format data. * @param [in,out] pTexture name of the GL texture to load. See * ktxLoadTextureF() for details. * @param [out] pTarget @p *pTarget is set to the texture target used. See * ktxLoadTextureF() for details. * @param [out] pDimensions @p the texture's base level width depth and height * are returned in structure to which this points. * See ktxLoadTextureF() for details. * @param [out] pIsMipmapped @p *pIsMipMapped is set to indicate if the loaded * texture is mipmapped. See ktxLoadTextureF() for * details. * @param [out] pGlerror @p *pGlerror is set to the value returned by * glGetError when this function returns the error * KTX_GL_ERROR. glerror can be NULL. * @param [in,out] pKvdLen If not NULL, @p *pKvdLen is set to the number of bytes * of key-value data pointed at by @p *ppKvd. Must not be * NULL, if @p ppKvd is not NULL. * @param [in,out] ppKvd If not NULL, @p *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.* * * @return KTX_SUCCESS on success, other KTX_* enum values on error. * * @exception KTX_FILE_OPEN_FAILED The specified memory could not be opened as a file. * @exception KTX_INVALID_VALUE See ktxLoadTextureF() for causes. * @exception KTX_INVALID_OPERATION See ktxLoadTextureF() for causes. * @exception KTX_UNEXPECTED_END_OF_FILE See ktxLoadTextureF() for causes. * * @exception KTX_GL_ERROR See ktxLoadTextureF() for causes. */ 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) { struct ktxMem mem; struct ktxStream stream; if (!ktxMemInit(&stream, &mem, bytes, size)) { return KTX_FILE_OPEN_FAILED; } return ktxLoadTextureS(&stream, pTexture, pTarget, pDimensions, pIsMipmapped, pGlerror, pKvdLen, ppKvd); }
/** * @~English * @brief Load a GL texture object from KTX formatted data in memory. * * @param [in] bytes pointer to the array of bytes containing * the KTX format data to load. * @param [in] size size of the memory array containing the * KTX format data. * @param [in,out] pTexture name of the GL texture to load. See * ktxLoadTextureF() for details. * @param [out] pTarget @p *pTarget is set to the texture target used. See * ktxLoadTextureF() for details. * @param [out] pDimensions @p the texture's base level width depth and height * are returned in structure to which this points. * See ktxLoadTextureF() for details. * @param [out] pIsMipmapped @p *pIsMipMapped is set to indicate if the loaded * texture is mipmapped. See ktxLoadTextureF() for * details. * @param [out] pGlerror @p *pGlerror is set to the value returned by * glGetError when this function returns the error * KTX_GL_ERROR. glerror can be NULL. * @param [in,out] pKvdLen If not NULL, @p *pKvdLen is set to the number of bytes * of key-value data pointed at by @p *ppKvd. Must not be * NULL, if @p ppKvd is not NULL. * @param [in,out] ppKvd If not NULL, @p *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.* * * @return KTX_SUCCESS on success, other KTX_* enum values on error. * * @exception KTX_FILE_OPEN_FAILED The specified memory could not be opened as a file. * @exception KTX_INVALID_VALUE See ktxLoadTextureF() for causes. * @exception KTX_INVALID_OPERATION See ktxLoadTextureF() for causes. * @exception KTX_UNEXPECTED_END_OF_FILE See ktxLoadTextureF() for causes. * * @exception KTX_GL_ERROR See ktxLoadTextureF() for causes. */ 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) { struct ktxMem mem; struct ktxStream stream; KTX_error_code errorCode = KTX_SUCCESS; errorCode = ktxMemInit(&stream, &mem, bytes, size); if (errorCode != KTX_SUCCESS) return errorCode; return ktxLoadTextureS(&stream, pTexture, pTarget, pDimensions, pIsMipmapped, pGlerror, pKvdLen, ppKvd); }