| 1207 | } |
| 1208 | |
| 1209 | void NativeEngine::LoadTexture(const Napi::CallbackInfo& info) |
| 1210 | { |
| 1211 | const auto texture = info[0].As<Napi::External<TextureData>>().Data(); |
| 1212 | const auto data = info[1].As<Napi::TypedArray>(); |
| 1213 | const auto generateMips = info[2].As<Napi::Boolean>().Value(); |
| 1214 | const auto invertY = info[3].As<Napi::Boolean>().Value(); |
| 1215 | const auto onSuccess = info[4].As<Napi::Function>(); |
| 1216 | const auto onError = info[5].As<Napi::Function>(); |
| 1217 | |
| 1218 | const auto dataSpan = gsl::make_span(static_cast<uint8_t*>(data.ArrayBuffer().Data()) + data.ByteOffset(), data.ByteLength()); |
| 1219 | |
| 1220 | arcana::make_task(arcana::threadpool_scheduler, m_cancelSource, |
| 1221 | [this, dataSpan, generateMips, invertY]() { |
| 1222 | bimg::ImageContainer* image = bimg::imageParse(&m_allocator, dataSpan.data(), static_cast<uint32_t>(dataSpan.size())); |
| 1223 | // todo: bimg::imageParse will return nullptr when trying to load a texture with an url that is not a valid texture |
| 1224 | // Like a 404 html page. |
| 1225 | if (invertY) |
| 1226 | { |
| 1227 | FlipY(image); |
| 1228 | } |
| 1229 | if (generateMips) |
| 1230 | { |
| 1231 | GenerateMips(&m_allocator, &image); |
| 1232 | } |
| 1233 | return image; |
| 1234 | }) |
| 1235 | .then(m_runtimeScheduler, m_cancelSource, [texture, dataRef = Napi::Persistent(data)](bimg::ImageContainer* image) { |
| 1236 | CreateTextureFromImage(texture, image); |
| 1237 | }) |
| 1238 | .then(arcana::inline_scheduler, m_cancelSource, [onSuccessRef = Napi::Persistent(onSuccess), onErrorRef = Napi::Persistent(onError)](arcana::expected<void, std::exception_ptr> result) { |
| 1239 | if (result.has_error()) |
| 1240 | { |
| 1241 | onErrorRef.Call({}); |
| 1242 | } |
| 1243 | else |
| 1244 | { |
| 1245 | onSuccessRef.Call({}); |
| 1246 | } |
| 1247 | }); |
| 1248 | } |
| 1249 | |
| 1250 | void NativeEngine::LoadCubeTexture(const Napi::CallbackInfo& info) |
| 1251 | { |
nothing calls this directly
no test coverage detected