libktx - The KTX Library
ktxTexture Class Reference

Class representing a texture. More...

#include <ktx.h>

Public Types

enum  ktxTextureCreateStorageEnum
 Enum for requesting, or not, allocation of storage for images. More...
 
enum  ktxTextureCreateFlagBits
 Flags for requesting services during creation. More...
 
typedef ktx_uint32_t ktxTextureCreateFlags
 Type for TextureCreateFlags parameters. More...
 
typedef KTX_error_code(KTXAPIENTRY * PFNKTXITERCB) (int miplevel, int face, int width, int height, int depth, ktx_uint32_t faceLodSize, void *pixels, void *userdata)
 Signature of function called by the ktxTexture_Iterate* functions to receive image data. More...
 

Public Member Functions

KTX_error_code ktxTexture_GLUpload (ktxTexture *This, GLuint *pTexture, GLenum *pTarget, GLenum *pGlerror)
 Create a GL texture object from a ktxTexture object. More...
 
KTX_error_code ktxTexture_Create (ktxTextureCreateInfo *createInfo, ktxTextureCreateStorageEnum storageAllocation, ktxTexture **newTex)
 Create a new empty ktxTexture. More...
 
KTX_error_code ktxTexture_CreateFromStdioStream (FILE *stdioStream, ktxTextureCreateFlags createFlags, ktxTexture **newTex)
 Create a ktxTexture from a stdio stream reading from a KTX source. More...
 
KTX_error_code ktxTexture_CreateFromNamedFile (const char *const filename, ktxTextureCreateFlags createFlags, ktxTexture **newTex)
 Create a ktxTexture from a named KTX file. More...
 
KTX_error_code ktxTexture_CreateFromMemory (const ktx_uint8_t *bytes, ktx_size_t size, ktxTextureCreateFlags createFlags, ktxTexture **newTex)
 Create a ktxTexture from KTX-formatted data in memory. More...
 
void ktxTexture_Destroy (ktxTexture *This)
 Destroy a ktxTexture object. More...
 
ktx_uint8_t * ktxTexture_GetData (ktxTexture *This)
 Return a pointer to the texture image data. More...
 
ktx_size_t ktxTexture_GetSize (ktxTexture *This)
 Return the size of the texture image data in bytes. More...
 
KTX_error_code ktxTexture_LoadImageData (ktxTexture *This, ktx_uint8_t *pBuffer, ktx_size_t bufSize)
 Load all the image data from the ktxTexture's source. More...
 
KTX_error_code ktxTexture_IterateLevelFaces (ktxTexture *This, PFNKTXITERCB iterCb, void *userdata)
 Iterate over the images in a ktxTexture object. More...
 
KTX_error_code ktxTexture_IterateLoadLevelFaces (ktxTexture *This, PFNKTXITERCB iterCb, void *userdata)
 Iterate over the images in a ktxTexture object while loading the image data. More...
 
KTX_error_code ktxTexture_IterateLevels (ktxTexture *This, PFNKTXITERCB iterCb, void *userdata)
 Iterate over the mip levels in a ktxTexture object. More...
 
KTX_error_code ktxTexture_GetImageOffset (ktxTexture *This, ktx_uint32_t level, ktx_uint32_t layer, ktx_uint32_t faceSlice, ktx_size_t *pOffset)
 Find the offset of an image within a ktxTexture's image data. More...
 
KTX_error_code ktxTexture_VkUploadEx (ktxTexture *This, ktxVulkanDeviceInfo *vdi, ktxVulkanTexture *vkTexture, VkImageTiling tiling, VkImageUsageFlags usageFlags, VkImageLayout finalLayout)
 Create a Vulkan image object from a ktxTexture object. More...
 
KTX_error_code ktxTexture_VkUpload (ktxTexture *texture, ktxVulkanDeviceInfo *vdi, ktxVulkanTexture *vkTexture)
 Create a Vulkan image object from a ktxTexture object. More...
 
VkFormat ktxTexture_GetVkFormat (ktxTexture *This)
 Return the VkFormat enum of a ktxTexture object. More...
 
KTX_error_code ktxTexture_SetImageFromStdioStream (ktxTexture *This, ktx_uint32_t level, ktx_uint32_t layer, ktx_uint32_t faceSlice, FILE *src, ktx_size_t srcSize)
 Set image for level, layer, faceSlice from a stdio stream source. More...
 
KTX_error_code ktxTexture_SetImageFromMemory (ktxTexture *This, ktx_uint32_t level, ktx_uint32_t layer, ktx_uint32_t faceSlice, const ktx_uint8_t *src, ktx_size_t srcSize)
 Set image for level, layer, faceSlice from an image in memory. More...
 
KTX_error_code ktxTexture_WriteToStdioStream (ktxTexture *This, FILE *dstsstr)
 Write a ktxTexture object to a stdio stream in KTX format. More...
 
KTX_error_code ktxTexture_WriteToNamedFile (ktxTexture *This, const char *const dstname)
 Write a ktxTexture object to a named file in KTX format. More...
 
KTX_error_code ktxTexture_WriteToMemory (ktxTexture *This, ktx_uint8_t **ppDstBytes, ktx_size_t *pSize)
 Write a ktxTexture object to block of memory in KTX format. More...
 

Data Fields

ktx_uint32_t glFormat
 
ktx_uint32_t glInternalformat
 
ktx_uint32_t glBaseInternalformat
 
ktx_uint32_t glType
 
ktx_bool_t isArray
 
ktx_bool_t isCubemap
 
ktx_bool_t isCompressed
 
ktx_bool_t generateMipmaps
 
ktx_uint32_t baseWidth
 
ktx_uint32_t baseHeight
 
ktx_uint32_t baseDepth
 
ktx_uint32_t numDimensions
 
ktx_uint32_t numLevels
 
ktx_uint32_t numLayers
 
ktx_uint32_t numFaces
 
ktxHashList kvDataHead
 
ktx_uint32_t kvDataLen
 
ktx_uint8_t * kvData
 
ktx_size_t dataSize
 
ktx_uint8_t * pData
 

Detailed Description

Class representing a texture.

ktxTextures should be created only by one of the ktxTexture_Create* functions and these fields should be considered read-only.

Examples:
glloader.c, and vkload.cpp.

Member Typedef Documentation

◆ ktxTextureCreateFlags

typedef ktx_uint32_t ktxTextureCreateFlags

Type for TextureCreateFlags parameters.

See also
ktxTexture_CreateFrom*()

◆ PFNKTXITERCB

typedef KTX_error_code(KTXAPIENTRY* PFNKTXITERCB) (int miplevel, int face, int width, int height, int depth, ktx_uint32_t faceLodSize, void *pixels, void *userdata)

Signature of function called by the ktxTexture_Iterate* functions to receive image data.

The function parameters are used to pass values which change for each image. Obtain values which are uniform across all images from the ktxTexture object.

Parameters
[in]miplevelMIP level from 0 to the max level which is dependent on the texture size.
[in]faceusually 0; for cube maps and cube map arrays, one of the 6 cube faces in the order +X, -X, +Y, -Y, +Z, -Z.
[in]widthwidth of the image.
[in]heightheight of the image or, for 1D textures textures, 1.
[in]depthdepth of the image or, for 1D & 2D textures, 1.
[in]faceLodSizenumber of bytes of data pointed at by pixels.
[in]pixelspointer to the image data.
[in,out]userdatapointer for the application to pass data to and from the callback function.
Examples:
glloader.c.

Member Enumeration Documentation

◆ ktxTextureCreateFlagBits

Flags for requesting services during creation.

See also
ktxTexture_CreateFrom*

◆ ktxTextureCreateStorageEnum

Enum for requesting, or not, allocation of storage for images.

See also
ktxTexture_Create()

Field Documentation

◆ baseDepth

ktx_uint32_t ktxTexture::baseDepth

Depth of the base level of the texture.

Examples:
glloader.c.

◆ baseHeight

ktx_uint32_t ktxTexture::baseHeight

Height of the base level of the texture.

Examples:
glloader.c.

◆ baseWidth

ktx_uint32_t ktxTexture::baseWidth

Width of the base level of the texture.

Examples:
glloader.c.

◆ dataSize

ktx_size_t ktxTexture::dataSize

Length of the image data in bytes.

◆ generateMipmaps

ktx_bool_t ktxTexture::generateMipmaps

KTX_TRUE if mipmaps should be generated for the texture by ktxTexture_GLUpload() or ktx_Texture_VkUpload().

Examples:
glloader.c.

◆ glBaseInternalformat

ktx_uint32_t ktxTexture::glBaseInternalformat

Base format of the texture data, e.g., GL_RGB.

Examples:
glloader.c.

◆ glFormat

ktx_uint32_t ktxTexture::glFormat

Format of the texture data, e.g., GL_RGB.

Examples:
glloader.c.

◆ glInternalformat

ktx_uint32_t ktxTexture::glInternalformat

Internal format of the texture data, e.g., GL_RGB8.

Examples:
glloader.c.

◆ glType

ktx_uint32_t ktxTexture::glType

Type of the texture data, e.g, GL_UNSIGNED_BYTE.

Examples:
glloader.c.

◆ isArray

ktx_bool_t ktxTexture::isArray

KTX_TRUE if the texture is an array texture.

Examples:
glloader.c.

◆ isCompressed

ktx_bool_t ktxTexture::isCompressed

KTX_TRUE if glInternalFormat is that of a compressed texture.

Examples:
glloader.c.

◆ isCubemap

ktx_bool_t ktxTexture::isCubemap

KTX_TRUE if the texture is a cubemap/

◆ kvData

ktx_uint8_t* ktxTexture::kvData

Pointer to the metadata, if it has been extracted in its raw form, otherwise NULL.

Examples:
glloader.c.

◆ kvDataHead

ktxHashList ktxTexture::kvDataHead

Head of the hash list of metadata.

Examples:
vkload.cpp.

◆ kvDataLen

ktx_uint32_t ktxTexture::kvDataLen

Length of the metadata, if it has been extracted in its raw form, otherwise 0.

Examples:
glloader.c.

◆ numDimensions

ktx_uint32_t ktxTexture::numDimensions

Number of dimensions in the texture: 1, 2 or 3.

Examples:
glloader.c.

◆ numFaces

ktx_uint32_t ktxTexture::numFaces

Number of faces, 6 for cube maps, 1 otherwise.

Examples:
glloader.c.

◆ numLayers

ktx_uint32_t ktxTexture::numLayers

Number of array layers in the texture.

Examples:
glloader.c.

◆ numLevels

ktx_uint32_t ktxTexture::numLevels

Number of mip levels in the texture. Should be 1, if generateMipmaps is KTX_TRUE. Can be less than a full pyramid but always starts at the base level.

Examples:
glloader.c.

◆ pData

ktx_uint8_t* ktxTexture::pData

Pointer to the image data.