| 411 | * @exception KTX_OUT_OF_MEMORY Not enough memory to carry out compression. |
| 412 | */ |
| 413 | extern "C" KTX_error_code |
| 414 | ktxTexture2_CompressBasisEx(ktxTexture2* This, ktxBasisParams* params) |
| 415 | { |
| 416 | KTX_error_code result; |
| 417 | |
| 418 | if (!params) |
| 419 | return KTX_INVALID_VALUE; |
| 420 | |
| 421 | if (params->structSize != sizeof(struct ktxBasisParams)) |
| 422 | return KTX_INVALID_VALUE; |
| 423 | |
| 424 | if (This->generateMipmaps) |
| 425 | return KTX_INVALID_OPERATION; |
| 426 | |
| 427 | if (This->supercompressionScheme != KTX_SS_NONE) |
| 428 | return KTX_INVALID_OPERATION; // Can't apply multiple schemes. |
| 429 | |
| 430 | if (This->isCompressed) |
| 431 | return KTX_INVALID_OPERATION; // Only non-block compressed formats |
| 432 | // can be encoded into a Basis format. |
| 433 | |
| 434 | if (This->_protected->_formatSize.flags & KTX_FORMAT_SIZE_PACKED_BIT) |
| 435 | return KTX_INVALID_OPERATION; |
| 436 | |
| 437 | // Basic descriptor block begins after the total size field. |
| 438 | const uint32_t* BDB = This->pDfd+1; |
| 439 | |
| 440 | uint32_t num_components, component_size; |
| 441 | getDFDComponentInfoUnpacked(This->pDfd, &num_components, &component_size); |
| 442 | |
| 443 | if (component_size != 1) |
| 444 | return KTX_INVALID_OPERATION; // Basis must have 8-bit components. |
| 445 | |
| 446 | if (num_components == 1 && params->normalMap) |
| 447 | return KTX_INVALID_OPERATION; // Not enough components. |
| 448 | |
| 449 | if (This->pData == NULL) { |
| 450 | result = ktxTexture2_LoadImageData(This, NULL, 0); |
| 451 | if (result != KTX_SUCCESS) |
| 452 | return result; |
| 453 | } |
| 454 | |
| 455 | if (!basisuEncoderInitialized) { |
| 456 | // force_serialization uses a mutex to serialize when multiple command |
| 457 | // queues per thread are used. We shouldn't need to worry about this. |
| 458 | // How to decide whether to use OpenCL? |
| 459 | basisu_encoder_init((BASISU_SUPPORT_OPENCL ? true : false)/*use_opencl*/ |
| 460 | /*opencl_force_serialization = false*/); |
| 461 | //atexit(basisu_encoder_deinit); |
| 462 | basisuEncoderInitialized = true; |
| 463 | } |
| 464 | |
| 465 | basis_compressor_params cparams; |
| 466 | cparams.m_read_source_images = false; // Don't read from source files. |
| 467 | cparams.m_write_output_basis_files = false; // Don't write output files. |
| 468 | cparams.m_status_output = params->verbose; |
| 469 | |
| 470 | // |