Skip to content

Commit

Permalink
libktx: update ktxTexture2_setImageFromStream to allow setting the en…
Browse files Browse the repository at this point in the history
…tire level's data in one call (KhronosGroup#794)

This change updates `ktxTexture2_setImageFromStream` to allow setting
`faceSlice` to `KTX_FACESLICE_WHOLE_LEVEL`. This allows setting
the entire level's data in one call rather having to do a loop setting each
slice individually.

Fixes: KhronosGroup#792
  • Loading branch information
AlexRouSg authored Nov 5, 2023
1 parent e0a93f5 commit c760f2f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
2 changes: 2 additions & 0 deletions include/ktx.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @snippet{doc} version.h API version
*/

#include <limits.h>
#include <stdio.h>
#include <stdbool.h>
#include <sys/types.h>
Expand Down Expand Up @@ -156,6 +157,7 @@ extern "C" {
* @brief Required unpack alignment
*/
#define KTX_GL_UNPACK_ALIGNMENT 4
#define KTX_FACESLICE_WHOLE_LEVEL UINT_MAX

#define KTX_TRUE true
#define KTX_FALSE false
Expand Down
30 changes: 19 additions & 11 deletions lib/writer2.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ appendLibId(ktxHashList* head, ktxHashListEntry* writerEntry)
* @param[in] This pointer to the target ktxTexture object.
* @param[in] level mip level of the image to set.
* @param[in] layer array layer of the image to set.
* @param[in] faceSlice cube map face or depth slice of the image to set.
* @param[in] faceSlice cube map face or depth slice of the image to set or
* KTX_FACESLICE_WHOLE_LEVEL to set the entire level.
* @param[in] src ktxStream pointer to the source.
* @param[in] srcSize size of the source image in bytes.
*
Expand Down Expand Up @@ -208,13 +209,19 @@ ktxTexture2_setImageFromStream(ktxTexture2* This, ktx_uint32_t level,
if (!This->pData)
return KTX_INVALID_OPERATION;

result = ktxTexture_GetImageOffset(ktxTexture(This),
level, layer, faceSlice,
&imageByteOffset);
if (result != KTX_SUCCESS)
return result;

imageByteLength = ktxTexture_GetImageSize(ktxTexture(This), level);
if (faceSlice == KTX_FACESLICE_WHOLE_LEVEL) {
result = ktxTexture_GetImageOffset(ktxTexture(This), level, layer, 0, &imageByteOffset);
if (result != KTX_SUCCESS) {
return result;
}
imageByteLength = ktxTexture_calcLevelSize(ktxTexture(This), level, KTX_FORMAT_VERSION_TWO);
} else {
result = ktxTexture_GetImageOffset(ktxTexture(This), level, layer, faceSlice, &imageByteOffset);
if (result != KTX_SUCCESS) {
return result;
}
imageByteLength = ktxTexture_GetImageSize(ktxTexture(This), level);
}

if (srcSize != imageByteLength)
return KTX_INVALID_OPERATION;
Expand Down Expand Up @@ -242,7 +249,8 @@ ktxTexture2_setImageFromStream(ktxTexture2* This, ktx_uint32_t level,
* @param[in] This pointer to the target ktxTexture object.
* @param[in] level mip level of the image to set.
* @param[in] layer array layer of the image to set.
* @param[in] faceSlice cube map face or depth slice of the image to set.
* @param[in] faceSlice cube map face or depth slice of the image to set or
* KTX_FACESLICE_WHOLE_LEVEL to set the entire level.
* @param[in] src stdio stream pointer to the source.
* @param[in] srcSize size of the source image in bytes.
*
Expand Down Expand Up @@ -287,7 +295,8 @@ ktxTexture2_SetImageFromStdioStream(ktxTexture2* This, ktx_uint32_t level,
* @param[in] This pointer to the target ktxTexture object.
* @param[in] level mip level of the image to set.
* @param[in] layer array layer of the image to set.
* @param[in] faceSlice cube map face or depth slice of the image to set.
* @param[in] faceSlice cube map face or depth slice of the image to set or
* KTX_FACESLICE_WHOLE_LEVEL to set the entire level.
* @param[in] src pointer to the image source in memory.
* @param[in] srcSize size of the source image in bytes.
*
Expand Down Expand Up @@ -941,4 +950,3 @@ ktxTexture2_DeflateZLIB(ktxTexture2* This, ktx_uint32_t compressionLevel)
}

/** @} */

0 comments on commit c760f2f

Please sign in to comment.