* Added helper function for easy pipeline vertex input state create info structure setup from glTF model vertex class * Split glTF loader into header and implementation * Updated sample to use glTF * Removed collada files Replaced assets are now part of the asset pack * Return value for glTF model vertex input state create info helper * Removed unused assets * Use glTF assets * Added default material for glTF node's without materials * Use glTF assets * Apply pre-transforms to normals * Use glTF assets * Use glTF assets * Use vertex input state from glTF model class * Scene setup * Use glTF assets * Use glTF assets * Display error message and exit if glTF file could not be loaded * Use glTF assets * Use glTF assets * Use glTF assets * Remove unused buffer binds * Use glTF assets * Remove no longer used model files * Remove no longer used model files * Added support for rendering glTF models with images * glTF model normal pre-transform ignores translation * Use glTF assets * Use glTF assets * Use glTF assets * Use glTF assets * Use glTF assets * Only add combined image samplers to pool if actually used in the scene * Use global descriptor set layouts * Use global descriptor set layouts * Use glTF assets * Use glTF assets * Use glTF assets Code cleanup Updated GLSL and HLSL shaders * Use glTF assets Code cleanup * Use glTF assets Code cleanup Updated GLSL and HLSL shaders * Remove no-longer used model * Use glTF assets Code cleanup Updated GLSL and HLSL shaders * Use glTF assets Code cleanup Updated GLSL and HLSL shaders Removed no-longer used model * Use glTF assets Code cleanup Use RGBA texture instead of different compressed formats Removed no-longer used assets * Adnrdoid build file * Use glTF assets Code cleanup and refactoring Updated GLSL and HLSL shaders * Added vertex count and way of passing additional memory property type flags to glTF loader * Use glTF assets Updated GLSL and HLSL shaders Removed no-longer used assets * Use glTF assets Updated GLSL and HLSL shaders * Remove unfinished sample * Completely reworked push constants sample Use glTF assets Updated GLSL and HLSL shaders Removed no-longer used assets * Android CMake build files * Removed un-used asset * Explicit buffer binding function * Use glTF assets Code cleanup Updated GLSL and HLSL shaders * Use glTF assets Code cleanup * Use glTF assets Code cleanup Removed no-longer used assets * Use glTF assets Code cleanup Updated GLSL and HLSL shaders Removed no-longer used assets * Remove no-longer used asset * Use glTF assets Code cleanup and refactoring Performance optimizations Updated GLSL and HLSL shaders Removed no-longer used assets * Use glTF assets Code cleanup and refactoring Updated GLSL and HLSL shaders Removed no-longer used assets * Use glTF assets Code cleanup and refactoring Updated GLSL and HLSL shaders Removed no-longer used assets * Use glTF assets Code cleanup and refactoring Removed no-longer used assets * Use glTF assets Code cleanup and refactoring Removed no-longer used assets * Use glTF assets Code cleanup and refactoring * Use glTF assets Code cleanup and refactoring * Use glTF assets Code cleanup and refactoring Removed no-longer used assets * Pass vertex size and calculate multiplier in shaders instead of hard-coding With this, changes to the glTF vertex structure won't break the ray tracing samples * Load tangents (if present) * Use glTF assets Code cleanup and heavy refactoring Reworked debug display code * Android build * Normal mapping fixes Udpated HLSL shaders * Use glTF assets Code cleanup and heavy refactoring Reworked debug display code Updated GLSL and HLSL shaders * Code cleanup, comments * Use glTF assets Code cleanup and heavy refactoring Reworked debug display code Updated GLSL and HLSL shaders * Added sample count to framebuffer create info * Removed no-longer used assets * Android build Removed no-longer used assets * Code cleanup and heavy refactoring Updated GLSL and HLSL shaders Use tangents stored in GLSL instead of calculating them in the fragment shader * Renamed textured PBR sample main cpp file * Use glTF assets Code cleanup and refactoring Updated GLSL and HLSL shaders Removed no-longer used assets * Use glTF assets Removed no-longer used assets * Android build files * Android build files * Use glTF assets Removed no-longer used assets * Fixed HLSL shaders * Android build files * Use glTF assets Updated GLSL and HLSL shaders Removed no-longer used assets * Use glTF assets Updated GLSL and HLSL shaders Removed no-longer used assets * Added flag to disable glTF image loading Useful for samples that use their own textures or don't use textures at all to speed up loading * Use glTF assets Code cleanup Use Sponza scene instead of Sibenik to better highlight the effect Updated GLSL and HLSL shaders * Updated Android build files * Removed left-over comment * Use Sponza scene for the SSAO sample * Removed unused code * Removed ASSIMP No longer required as all samples now use the glTF file format * Added missing vertex shader stage * Removed old ASSIMP-based model loader * Added support for loading external glTF images from ktx Android fixes for loading external buffer files * Scene setup * Added missing shader stages * Removed ASSIMP from build files * Fixed compiler warning * Removed ASSIMP from readmes * Android build files cleanup * Replaced ktx submodule with only the files required for this repo The ktx submodule was a tad too big and contained lots of files not required for this repo * Moved ktx build files into base project * Use glTF assets * Use glTF assets * Removed license files, will be moved to asset pack * Use RGBA textures * Use RGBA cubemp texture with face assignment based on original images Refs #679 * Android build files * Removed textures All textures will be moved to the asset pack * Ignore asset folders * Removed font Fonts will be moved to the asset pack * Link to gltf asset pack * Updated gitignore * Android build file
214 lines
6.7 KiB
Markdown
214 lines
6.7 KiB
Markdown
Introduction {#mainpage}
|
|
=========
|
|
|
|
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
|
|
<a href="http://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/">
|
|
formal specification.</a>
|
|
|
|
The library is open source software. Source code is available at
|
|
<a href="https://github.com/KhronosGroup/KTX">GitHub</a>. Most of the source
|
|
code and the documentation is licensed under the Apache 2.0 license. See @ref license
|
|
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 @ref libktx_history for the list of changes.
|
|
|
|
See @ref todo for the current To Do list.
|
|
|
|
@authors
|
|
Mark Callow, <a href="http://www.edgewise-consulting.com">Edgewise Consulting</a>,
|
|
formerly at <a href="http://www.hicorp.co.jp">HI Corporation</a>\n
|
|
Georg Kolling, <a href="http://www.imgtec.com">Imagination Technology</a>\n
|
|
Jacob Ström, <a href="http://www.ericsson.com">Ericsson AB</a>
|
|
|
|
@version 3.0.0
|
|
|
|
$Date$
|
|
|
|
# Usage Overview {#overview}
|
|
|
|
## Reading a KTX file for non-GL and non-Vulkan Use {#readktx}
|
|
|
|
~~~~~~~~~~~~~~~~{.c}
|
|
#include <ktx.h>
|
|
|
|
ktxTexture* texture;
|
|
KTX_error_code result;
|
|
ktx_size_t offset;
|
|
ktx_uint8_t* image;
|
|
ktx_uint32_t level, layer, faceSlice;
|
|
|
|
result = ktxTexture_CreateFromNamedFile("mytex3d.ktx",
|
|
KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT,
|
|
&texture);
|
|
|
|
// Retrieve information about the texture from fields in the ktxTexture
|
|
// such as:
|
|
ktx_uint32 numLevels = texture->numLevels;
|
|
ktx_uint32 baseWidth = texture->baseWidth;
|
|
ktx_bool_t isArray = texture->isArray;
|
|
|
|
// Retrieve a pointer to the image for a specific mip level, array layer
|
|
// & face or depth slice.
|
|
level = 1; layer = 0; faceSlice = 3;
|
|
result = ktxTexture_GetImageOffset(texture, level, layer, faceSlice, &offset);
|
|
image = ktxTexture_GetData(texture) + offset;
|
|
// ...
|
|
// Do something with the texture image.
|
|
// ...
|
|
ktxTexture_Destroy(texture);
|
|
~~~~~~~~~~~~~~~~
|
|
|
|
## Creating a GL texture object from a KTX file. {#createGL}
|
|
|
|
~~~~~~~~~~~~~~~~{.c}
|
|
#include <ktx.h>
|
|
|
|
ktxTexture* kTexture;
|
|
KTX_error_code result;
|
|
ktx_size_t offset;
|
|
ktx_uint8_t* image;
|
|
ktx_uint32_t level, layer, faceSlice;
|
|
GLuint texture = 0;
|
|
GLenum target, glerror;
|
|
|
|
result = ktxTexture_CreateFromNamedFile("mytex3d.ktx",
|
|
KTX_TEXTURE_CREATE_NO_FLAGS,
|
|
&kTexture);
|
|
glGenTextures(1, &texture); // Optional. GLUpload can generate a texture.
|
|
result = ktxtexture_GLUpload(kTexture, &texture, &target, &glerror);
|
|
ktxTexture_Destroy(texture);
|
|
// ...
|
|
// GL rendering using the texture
|
|
// ...
|
|
~~~~~~~~~~~~~~~~
|
|
|
|
## Creating a Vulkan image object from a KTX file. {#createVulkan}
|
|
|
|
~~~~~~~~~~~~~~~~{.c}
|
|
#include <ktxvulkan.h>
|
|
|
|
ktxTexture* kTexture;
|
|
KTX_error_code result;
|
|
ktx_size_t offset;
|
|
ktx_uint8_t* image;
|
|
ktx_uint32_t level, layer, faceSlice;
|
|
ktxVulkanDeviceInfo vdi;
|
|
ktxVulkanTexture texture;
|
|
|
|
// Set up Vulkan physical device (gpu), logical device (device), queue
|
|
// and command pool. Save the handles to these in a struct called vkctx.
|
|
// ktx VulkanDeviceInfo is used to pass these with the expectation that
|
|
// apps are likely to upload a large number of textures.
|
|
ktxVulkanDeviceInfo_Construct(&vdi, vkctx.gpu, vkctx.device,
|
|
vkctx.queue, vkctx.commandPool, nullptr);
|
|
|
|
ktxresult = ktxTexture_CreateFromNamedFile("mytex3d.ktx",
|
|
KTX_TEXTURE_CREATE_NO_FLAGS,
|
|
&kTexture);
|
|
|
|
ktxresult = ktxTexture_VkUploadEx(kTexture, &vdi, &texture,
|
|
VK_IMAGE_TILING_OPTIMAL,
|
|
VK_IMAGE_USAGE_SAMPLED_BIT,
|
|
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
|
|
|
ktxTexture_Destroy(kTexture);
|
|
ktxVulkanDeviceInfo_Destruct(&vdi);
|
|
// ...
|
|
// Vulkan rendering using the texture
|
|
// ...
|
|
// When done using the image in Vulkan...
|
|
ktxVulkanTexture_Destruct(&texture, vkctx.device, nullptr);
|
|
~~~~~~~~~~~~~~~~
|
|
|
|
## Extracting Metadata {#subsection}
|
|
|
|
Once a ktxTexture object has been created, metadata can be easily found
|
|
and extracted. The following can be added to any of the above.
|
|
|
|
~~~~~~~~~~~~~~~~{.c}
|
|
char* pValue;
|
|
uint32_t valueLen;
|
|
if (KTX_SUCCESS == ktxHashList_FindValue(&kTexture->kvDataHead,
|
|
KTX_ORIENTATION_KEY,
|
|
&valueLen, (void**)&pValue))
|
|
{
|
|
char s, t;
|
|
|
|
if (sscanf(pValue, KTX_ORIENTATION2_FMT, &s, &t) == 2) {
|
|
...
|
|
}
|
|
}
|
|
~~~~~~~~~~~~~~~~
|
|
|
|
## Writing a KTX file {#writektx}
|
|
|
|
~~~~~~~~~~~~~~~~{.c}
|
|
#include <ktx.h>
|
|
|
|
ktxTexture* texture;
|
|
ktxTextureCreateInfo createInfo;
|
|
KTX_error_code result;
|
|
ktx_uint32_t level, layer, faceSlice;
|
|
FILE* src;
|
|
ktx_size_t srcSize;
|
|
|
|
createInfo.glInternalformat = GL_RGB8;
|
|
createInfo.baseWidth = 2048;
|
|
createInfo.baseHeight = 1024;
|
|
createInfo.baseDepth = 16;
|
|
createInfo.numDimensions = 3.
|
|
// Note: it is not necessary to provide a full mipmap pyramid.
|
|
createInfo.numLevels = log2(createInfo.baseWidth) + 1
|
|
createInfo.numLayers = 1;
|
|
createInfo.numFaces = 1;
|
|
createInfo.isArray = KTX_FALSE;
|
|
createInfo.generateMipmaps = KTX_FALSE;
|
|
|
|
result = ktxTexture_Create(createInfo,
|
|
KTX_TEXTURE_CREATE_ALLOC_STORAGE,
|
|
&texture);
|
|
|
|
src = // Open a stdio FILE* on the baseLevel image, slice 0.
|
|
srcSize = // Query size of the file.
|
|
level = 0;
|
|
layer = 0;
|
|
faceSlice = 0;
|
|
result = ktxTexture_SetImageFromMemory(texture, level, layer, faceSlice,
|
|
src, srcSize);
|
|
// Repeat for the other 15 slices of the base level and all other levels
|
|
// up to createInfo.numLevels.
|
|
|
|
ktxTexture_WriteToNamedFile(texture, "mytex3d.ktx");
|
|
ktxTexture_Destroy(texture);
|
|
~~~~~~~~~~~~~~~~
|
|
|
|
## Modifying a KTX file {#modifyktx}
|
|
|
|
~~~~~~~~~~~~~~~~{.c}
|
|
#include <ktx.h>
|
|
|
|
ktxTexture* texture;
|
|
KTX_error_code result;
|
|
ktx_size_t offset;
|
|
ktx_uint8_t* image;
|
|
ktx_uint32_t level, layer, faceSlice;
|
|
|
|
result = ktxTexture_CreateFromNamedFile("mytex3d.ktx",
|
|
KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT,
|
|
&texture);
|
|
// The file is closed after all the data has been read.
|
|
|
|
// It is the responsibilty of the application to make sure its
|
|
// modifications are valid.
|
|
texture->generateMipmaps = KTX_TRUE;
|
|
|
|
ktxTexture_WriteToNamedFile(texture, "mytex3d.ktx");
|
|
ktxTexture_Destroy(texture);
|
|
~~~~~~~~~~~~~~~~
|
|
|