* In hindsight this function should have been `#if KTX_FEATURE_WRITE`. * In the interest of not breaking an app that may be using this via * `ktxTexture2_Create` in `libktx_read` we won't change it. */ * @memberof ktxTexture2 @private * @~English * @brief Construct a new, empty, ktxTexture2. * * @param[in] This pointer to a ktxTexture2-sized block of memory to *
| 430 | * unsupported. |
| 431 | */ |
| 432 | static KTX_error_code |
| 433 | ktxTexture2_construct(ktxTexture2* This, |
| 434 | const ktxTextureCreateInfo* const createInfo, |
| 435 | ktxTextureCreateStorageEnum storageAllocation) |
| 436 | { |
| 437 | ktxFormatSize formatSize; |
| 438 | KTX_error_code result; |
| 439 | |
| 440 | memset(This, 0, sizeof(*This)); |
| 441 | |
| 442 | if (createInfo->vkFormat != VK_FORMAT_UNDEFINED) { |
| 443 | if (isProhibitedFormat(createInfo->vkFormat)) |
| 444 | return KTX_UNSUPPORTED_TEXTURE_TYPE; |
| 445 | This->pDfd = ktxVk2dfd(createInfo->vkFormat); |
| 446 | if (!This->pDfd) |
| 447 | return KTX_INVALID_VALUE; // Format is unknown or unsupported. |
| 448 | |
| 449 | #ifdef _DEBUG |
| 450 | // If this fires, an unsupported format or incorrect DFD |
| 451 | // has crept into vk2dfd. |
| 452 | assert(ktxFormatSize_initFromDfd(&formatSize, This->pDfd)); |
| 453 | #else |
| 454 | (void)ktxFormatSize_initFromDfd(&formatSize, This->pDfd); |
| 455 | #endif |
| 456 | |
| 457 | } else { |
| 458 | // TODO: Validate createInfo->pDfd. |
| 459 | This->pDfd = (ktx_uint32_t*)malloc(*createInfo->pDfd); |
| 460 | if (!This->pDfd) |
| 461 | return KTX_OUT_OF_MEMORY; |
| 462 | memcpy(This->pDfd, createInfo->pDfd, *createInfo->pDfd); |
| 463 | if (!ktxFormatSize_initFromDfd(&formatSize, This->pDfd)) { |
| 464 | result = KTX_UNSUPPORTED_TEXTURE_TYPE; |
| 465 | goto cleanup; |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | result = ktxTexture_construct(ktxTexture(This), createInfo, &formatSize); |
| 470 | |
| 471 | if (result != KTX_SUCCESS) |
| 472 | return result; |
| 473 | result = ktxTexture2_constructCommon(This, createInfo->numLevels); |
| 474 | if (result != KTX_SUCCESS) |
| 475 | goto cleanup;; |
| 476 | |
| 477 | This->vkFormat = createInfo->vkFormat; |
| 478 | |
| 479 | // The typeSize cannot be reconstructed just from the DFD as the BDFD |
| 480 | // does not capture the packing expressed by the [m]PACK[n] layout |
| 481 | // information in the VkFormat, so we calculate the typeSize directly |
| 482 | // from the vkFormat |
| 483 | This->_protected->_typeSize = vkFormatTypeSize(createInfo->vkFormat); |
| 484 | |
| 485 | This->supercompressionScheme = KTX_SS_NONE; |
| 486 | |
| 487 | This->_private->_requiredLevelAlignment |
| 488 | = ktxTexture2_calcRequiredLevelAlignment(This); |
| 489 |
no test coverage detected