MCPcopy Create free account
hub / github.com/BabylonJS/BabylonNative / LoadCubeTexture

Method LoadCubeTexture

Plugins/NativeEngine/Source/NativeEngine.cpp:1250–1287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1248 }
1249
1250 void NativeEngine::LoadCubeTexture(const Napi::CallbackInfo& info)
1251 {
1252 const auto texture = info[0].As<Napi::External<TextureData>>().Data();
1253 const auto data = info[1].As<Napi::Array>();
1254 const auto generateMips = info[2].As<Napi::Boolean>().Value();
1255 const auto onSuccess = info[3].As<Napi::Function>();
1256 const auto onError = info[4].As<Napi::Function>();
1257
1258 std::array<arcana::task<bimg::ImageContainer*, std::exception_ptr>, 6> tasks;
1259 for (uint32_t face = 0; face < data.Length(); face++)
1260 {
1261 const auto typedArray = data[face].As<Napi::TypedArray>();
1262 const auto dataSpan = gsl::make_span(static_cast<uint8_t*>(typedArray.ArrayBuffer().Data()) + typedArray.ByteOffset(), typedArray.ByteLength());
1263 tasks[face] = arcana::make_task(arcana::threadpool_scheduler, m_cancelSource, [this, dataSpan, generateMips]() {
1264 bimg::ImageContainer* image = bimg::imageParse(&m_allocator, dataSpan.data(), static_cast<uint32_t>(dataSpan.size()));
1265 if (generateMips)
1266 {
1267 GenerateMips(&m_allocator, &image);
1268 }
1269 return image;
1270 });
1271 }
1272
1273 arcana::when_all(gsl::make_span(tasks))
1274 .then(m_runtimeScheduler, m_cancelSource,
1275 [texture, dataRef = Napi::Persistent(data), generateMips](const std::vector<bimg::ImageContainer*>& images) {
1276 CreateCubeTextureFromImages(texture, images, generateMips);
1277 })
1278 .then(arcana::inline_scheduler, m_cancelSource, [this, onSuccessRef = Napi::Persistent(onSuccess)]() {
1279 onSuccessRef.Call({Napi::Value::From(Env(), true)});
1280 })
1281 .then(arcana::inline_scheduler, m_cancelSource, [this, onErrorRef = Napi::Persistent(onError)](arcana::expected<void, std::exception_ptr> result) {
1282 if (result.has_error())
1283 {
1284 onErrorRef.Call({Napi::Value::From(Env(), true)});
1285 }
1286 });
1287 }
1288
1289 void NativeEngine::LoadCubeTextureWithMips(const Napi::CallbackInfo& info)
1290 {

Callers

nothing calls this directly

Calls 11

GenerateMipsFunction · 0.85
PersistentFunction · 0.85
ValueMethod · 0.80
ArrayBufferMethod · 0.80
ByteOffsetMethod · 0.80
ByteLengthMethod · 0.80
CallMethod · 0.80
EnvClass · 0.50
DataMethod · 0.45
LengthMethod · 0.45

Tested by

no test coverage detected