MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / updateTexture

Method updateTexture

Source/Node/VideoNode.cpp:426–487  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

424}
425
426VideoNode::UpdateFlag VideoNode::updateTexture() {
427 auto videoData = s_cast<VideoData*>(_videoData.get());
428 if (!videoData) return UpdateFlag::Stop;
429
430 uint32_t videoWidth = videoData->videoWidth;
431 uint32_t videoHeight = videoData->videoHeight;
432 if (videoWidth == 0 || videoHeight == 0) {
433 return UpdateFlag::Stop;
434 }
435
436 auto frame = videoData->getFrame();
437 if (!frame) {
438 return UpdateFlag::Wait;
439 }
440
441 if (frame.value().empty()) {
442 return UpdateFlag::Stop;
443 }
444
445 auto texture = getTexture();
446
447 if (!texture || texture->getWidth() != s_cast<int>(videoWidth) || texture->getHeight() != s_cast<int>(videoHeight)) {
448
449 bgfx::TextureHandle textureHandle = bgfx::createTexture2D(
450 s_cast<uint16_t>(videoWidth),
451 s_cast<uint16_t>(videoHeight),
452 false, 1,
453 bgfx::TextureFormat::RGBA8);
454
455 if (!bgfx::isValid(textureHandle)) {
456 Error("VideoNode: failed to create texture");
457 return UpdateFlag::Stop;
458 }
459
460 bgfx::TextureInfo info;
461 bgfx::calcTextureSize(info,
462 s_cast<uint16_t>(videoWidth),
463 s_cast<uint16_t>(videoHeight),
464 0, false, false, 1,
465 bgfx::TextureFormat::RGBA8);
466
467 texture = Texture2D::create(textureHandle, info, BGFX_TEXTURE_NONE);
468 setTexture(texture);
469 setTextureRect(Rect{0.0f, 0.0f, s_cast<float>(videoData->videoWidth), s_cast<float>(videoData->videoHeight)});
470 }
471
472 if (texture) {
473 auto buffer = new std::vector<uint32_t>(std::move(frame.value()));
474 const bgfx::Memory* mem = bgfx::makeRef(
475 buffer->data(),
476 s_cast<uint32_t>(buffer->size() * sizeof(uint32_t)),
477 releaseFrame,
478 buffer);
479
480 bgfx::updateTexture2D(texture->getHandle(), 0, 0, 0, 0,
481 s_cast<uint16_t>(videoWidth),
482 s_cast<uint16_t>(videoHeight),
483 mem);

Callers

nothing calls this directly

Calls 15

createTexture2DFunction · 0.85
calcTextureSizeFunction · 0.85
moveFunction · 0.85
makeRefFunction · 0.85
updateTexture2DFunction · 0.85
getMethod · 0.65
getTextureFunction · 0.50
isValidFunction · 0.50
ErrorEnum · 0.50
createFunction · 0.50
setTextureFunction · 0.50
getFrameMethod · 0.45

Tested by

no test coverage detected