libktx is a small library of functions for creating and reading KTX (Khronos TeXture) files and instantiating OpenGL® and OpenGL® ES textures and Vulkan images from them.
For information about the KTX format see the formal specification.
The library is open source software. Source code is available at GitHub. Most of the source code and the documentation is licensed under the Apache 2.0 license. See License and Attribution Notices for details. When distributing the library, whether in source or binary form, this documentation must be included in the distribution or otherwise made available to recipients.
See Revision History for the list of changes.
See To Do List for the current To Do list.
- Authors
- Mark Callow, Edgewise Consulting, formerly at HI Corporation
Georg Kolling, Imagination Technology
Jacob Ström, Ericsson AB
- Version
- 3.0.0
$Date$
Usage Overview
Reading a KTX file for non-GL and non-Vulkan Use
ktx_size_t offset;
ktx_uint8_t* image;
ktx_uint32_t level, layer, faceSlice;
&texture);
ktx_bool_t isArray = texture->
isArray;
level = 1; layer = 0; faceSlice = 3;
Creating a GL texture object from a KTX file.
ktx_size_t offset;
ktx_uint8_t* image;
ktx_uint32_t level, layer, faceSlice;
GLuint texture = 0;
GLenum target, glerror;
KTX_TEXTURE_CREATE_NO_FLAGS,
&kTexture);
glGenTextures(1, &texture);
result = ktxtexture_GLUpload(kTexture, &texture, &target, &glerror);
Creating a Vulkan image object from a KTX file.
#include <ktxvulkan.h>
ktx_size_t offset;
ktx_uint8_t* image;
ktx_uint32_t level, layer, faceSlice;
vkctx.queue, vkctx.commandPool, nullptr);
KTX_TEXTURE_CREATE_NO_FLAGS,
&kTexture);
VK_IMAGE_TILING_OPTIMAL,
VK_IMAGE_USAGE_SAMPLED_BIT,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
Extracting Metadata
Once a ktxTexture object has been created, metadata can be easily found and extracted. The following can be added to any of the above.
char* pValue;
uint32_t valueLen;
&valueLen, (void**)&pValue))
{
char s, t;
...
}
}
Writing a KTX file
ktx_uint32_t level, layer, faceSlice;
FILE* src;
ktx_size_t srcSize;
createInfo.numLevels = log2(createInfo.
baseWidth) + 1
&texture);
src =
srcSize =
level = 0;
layer = 0;
faceSlice = 0;
src, srcSize);
Modifying a KTX file
ktx_size_t offset;
ktx_uint8_t* image;
ktx_uint32_t level, layer, faceSlice;
&texture);