* @memberof ktxTexture * @~English * @brief Iterate over the levels or faces in a ktxTexture object. * * Blocks of image data are passed to an application-supplied callback * function. This is not a strict per-image iteration. Rather it reflects how * OpenGL needs the images. For most textures the block of data includes all * images of a mip level which implies all layers of an array. Howev
| 586 | * |
| 587 | */ |
| 588 | KTX_error_code |
| 589 | ktxTexture_IterateLevelFaces(ktxTexture* This, PFNKTXITERCB iterCb, |
| 590 | void* userdata) |
| 591 | { |
| 592 | ktx_uint32_t miplevel; |
| 593 | KTX_error_code result = KTX_SUCCESS; |
| 594 | |
| 595 | if (This == NULL) |
| 596 | return KTX_INVALID_VALUE; |
| 597 | |
| 598 | if (iterCb == NULL) |
| 599 | return KTX_INVALID_VALUE; |
| 600 | |
| 601 | for (miplevel = 0; miplevel < This->numLevels; ++miplevel) |
| 602 | { |
| 603 | ktx_uint32_t faceLodSize; |
| 604 | ktx_uint32_t face; |
| 605 | ktx_uint32_t innerIterations; |
| 606 | GLsizei width, height, depth; |
| 607 | |
| 608 | /* Array textures have the same number of layers at each mip level. */ |
| 609 | width = MAX(1, This->baseWidth >> miplevel); |
| 610 | height = MAX(1, This->baseHeight >> miplevel); |
| 611 | depth = MAX(1, This->baseDepth >> miplevel); |
| 612 | |
| 613 | faceLodSize = (ktx_uint32_t)ktxTexture_calcFaceLodSize( |
| 614 | This, miplevel); |
| 615 | |
| 616 | /* All array layers are passed in a group because that is how |
| 617 | * GL & Vulkan need them. Hence no |
| 618 | * for (layer = 0; layer < This->numLayers) |
| 619 | */ |
| 620 | if (This->isCubemap && !This->isArray) |
| 621 | innerIterations = This->numFaces; |
| 622 | else |
| 623 | innerIterations = 1; |
| 624 | for (face = 0; face < innerIterations; ++face) |
| 625 | { |
| 626 | /* And all z_slices are also passed as a group hence no |
| 627 | * for (slice = 0; slice < This->depth) |
| 628 | */ |
| 629 | ktx_size_t offset; |
| 630 | |
| 631 | ktxTexture_GetImageOffset(This, miplevel, 0, face, &offset); |
| 632 | result = iterCb(miplevel, face, |
| 633 | width, height, depth, |
| 634 | faceLodSize, This->pData + offset, userdata); |
| 635 | |
| 636 | if (result != KTX_SUCCESS) |
| 637 | break; |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | return result; |
| 642 | } |
| 643 | |
| 644 | /** |
| 645 | * @internal |
no outgoing calls