| 318 | } |
| 319 | |
| 320 | ktx_error_code_e setImageFromMemory(ktx_uint32_t level, |
| 321 | ktx_uint32_t layer, |
| 322 | ktx_uint32_t faceSlice, |
| 323 | const val& jsimage) |
| 324 | { |
| 325 | std::vector<uint8_t> image{}; |
| 326 | image.resize(jsimage["byteLength"].as<size_t>()); |
| 327 | val memory = emscripten::val::module_property("HEAP8")["buffer"]; |
| 328 | val memoryView = jsimage["constructor"].new_(memory, |
| 329 | reinterpret_cast<uintptr_t>(image.data()), |
| 330 | jsimage["length"].as<uint32_t>()); |
| 331 | // Yes, this code IS copying the data. Sigh! According to Alon |
| 332 | // Zakai: |
| 333 | // "There isn't a way to let compiled code access a new |
| 334 | // ArrayBuffer. The compiled code has hardcoded access to the |
| 335 | // wasm Memory it was instantiated with - all the pointers it |
| 336 | // can understand are indexes into that Memory. It can't refer |
| 337 | // to anything else, I'm afraid." |
| 338 | // |
| 339 | // "In the future using different address spaces or techniques |
| 340 | // with reference types may open up some possibilities here." |
| 341 | memoryView.call<void>("set", jsimage); |
| 342 | ktx_error_code_e result; |
| 343 | result = ktxTexture_SetImageFromMemory(m_ptr.get(), |
| 344 | level, layer, faceSlice, |
| 345 | image.data(), image.size()); |
| 346 | |
| 347 | if (result != KTX_SUCCESS) { |
| 348 | std::cout << "ERROR: Failed to setImageFromMemory: " << ktxErrorString(result) << std::endl; |
| 349 | } |
| 350 | return result; |
| 351 | |
| 352 | } |
| 353 | |
| 354 | ktx_error_code_e compressAstc(const ktxAstcParams& params_input) |
| 355 | { |
no test coverage detected