MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / ktxTexture1_IterateLoadLevelFaces

Function ktxTexture1_IterateLoadLevelFaces

lib/texture1.c:1175–1278  ·  view source on GitHub ↗

* @memberof ktxTexture1 * @~English * @brief Iterate over the images in a ktxTexture1 object while loading the * image data. * * This operates similarly to @ref ktxTexture::ktxTexture_IterateLevelFaces * "ktxTexture_IterateLevelFaces" except that it loads the images from the * ktxTexture1's source to a temporary buffer while iterating. The callback * function must copy the image dat

Source from the content-addressed store, hash-verified

1173 * hold the base level image.
1174 */
1175KTX_error_code
1176ktxTexture1_IterateLoadLevelFaces(ktxTexture1* This, PFNKTXITERCB iterCb,
1177 void* userdata)
1178{
1179 DECLARE_PRIVATE(ktxTexture1);
1180 struct ktxTexture_protected* prtctd = This->_protected;
1181 ktxStream* stream = (ktxStream *)&prtctd->_stream;
1182 ktx_uint32_t dataSize = 0;
1183 ktx_uint32_t miplevel;
1184 KTX_error_code result = KTX_SUCCESS;
1185 void* data = NULL;
1186
1187 if (This == NULL)
1188 return KTX_INVALID_VALUE;
1189
1190 if (This->classId != ktxTexture1_c)
1191 return KTX_INVALID_OPERATION;
1192
1193 if (iterCb == NULL)
1194 return KTX_INVALID_VALUE;
1195
1196 if (prtctd->_stream.data.file == NULL)
1197 // This Texture not created from a stream or images are already loaded.
1198 return KTX_INVALID_OPERATION;
1199
1200 for (miplevel = 0; miplevel < This->numLevels; ++miplevel)
1201 {
1202 ktx_uint32_t faceLodSize;
1203 ktx_uint32_t faceLodSizePadded;
1204 ktx_uint32_t face;
1205 ktx_uint32_t innerIterations;
1206 GLsizei width, height, depth;
1207
1208 /* Array textures have the same number of layers at each mip level. */
1209 width = MAX(1, This->baseWidth >> miplevel);
1210 height = MAX(1, This->baseHeight >> miplevel);
1211 depth = MAX(1, This->baseDepth >> miplevel);
1212
1213 result = stream->read(stream, &faceLodSize, sizeof(ktx_uint32_t));
1214 if (result != KTX_SUCCESS) {
1215 goto cleanup;
1216 }
1217 if (private->_needSwap) {
1218 _ktxSwapEndian32(&faceLodSize, 1);
1219 }
1220#if (KTX_GL_UNPACK_ALIGNMENT != 4)
1221 faceLodSizePadded = _KTX_PAD4(faceLodSize);
1222#else
1223 faceLodSizePadded = faceLodSize;
1224#endif
1225 if (!data) {
1226 /* allocate memory sufficient for the base miplevel */
1227 data = malloc(faceLodSizePadded);
1228 if (!data) {
1229 result = KTX_OUT_OF_MEMORY;
1230 goto cleanup;
1231 }
1232 dataSize = faceLodSizePadded;

Callers

nothing calls this directly

Calls 4

_ktxSwapEndian32Function · 0.85
_ktxSwapEndian16Function · 0.85
readMethod · 0.45
destructMethod · 0.45

Tested by

no test coverage detected