Skip to content

NativeEngine: implement updateTextureData (re-enables Test updateTextureData)#1751

Draft
bkaradzic-microsoft wants to merge 1 commit into
BabylonJS:masterfrom
bkaradzic-microsoft:native-update-texture-data
Draft

NativeEngine: implement updateTextureData (re-enables Test updateTextureData)#1751
bkaradzic-microsoft wants to merge 1 commit into
BabylonJS:masterfrom
bkaradzic-microsoft:native-update-texture-data

Conversation

@bkaradzic-microsoft

@bkaradzic-microsoft bkaradzic-microsoft commented Jun 11, 2026

Copy link
Copy Markdown
Member

Paired engine PR: BabylonJS/Babylon.js#18566

What

Implements updateTextureData on the native engine so partial (sub-rectangle) texture updates work;
previously it threw "not implemented". Pairs with the Babylon.js change that also stops the native
engine reporting engine.name === "WebGL" (that masquerade made engine.name-gated WebGL _gl
access run on native and crash with TEXTURE_2D undefined).

Changes

  • Plugins/NativeEngine/Source/NativeEngine.cpp / .h: add NativeEngine::UpdateTextureData, which
    uploads the requested sub-rectangle via bgfx::updateTexture2D (Texture::Update2D). It validates
    the JS-controlled rectangle against the mip-level extents, sizes the copy with
    bgfx::calcTextureSize (bgfx is always linked, unlike bimg, so this also works in builds without
    image loading), and mirrors the vertical flip the base texture upload applies so the sub-rectangle
    lines up on top-left-origin backends (e.g. D3D11).
  • Apps/Playground/Scripts/config.json: re-enable "Test updateTextureData".

CI

The validation suite uses the published babylonjs npm, which does not yet contain the paired JS
overrides, so the re-enabled test stays red until a babylonjs release with the Babylon.js change
ships and the dependency is bumped here. Draft until then.

Verified locally

Built against a local babylon.max.js with the paired change: the re-enabled test passes (stable
across repeated runs); no regressions in other texture / raw-texture tests.


Related PRs & landing order

Co-dependent; land in this order:

  1. Babylon.js #18566 first — adds the engine.name = "Native" + updateTextureData TS overrides; no WebGL behavior change.
  2. A babylonjs npm release ships that TS change.
  3. BabylonNative NativeEngine: implement updateTextureData (re-enables Test updateTextureData) #1751 last — bumps the bundled babylonjs and re-enables the Test updateTextureData validation test, which only passes once the paired JS is present in the bundled engine.

…ureData)

updateTextureData previously threw "not implemented" on Native. Implement it so
sub-rectangle texture updates work.

- Add NativeEngine::UpdateTextureData: upload the requested sub-rectangle via
  bgfx::updateTexture2D (Texture::Update2D). Validates the JS-controlled rect
  against the mip extents, sizes the copy with bgfx::calcTextureSize (no bimg
  dependency, so it also works in no-image-loading builds), and mirrors the
  vertical flip the base texture upload applies so the sub-rect lines up on
  top-left-origin backends (e.g. D3D11).
- Re-enable the "Test updateTextureData" validation test.

Pairs with the Babylon.js change (engine.name = "Native" so name-gated WebGL
_gl access skips Native, plus the updateTextureData override). CI stays red
until a babylonjs npm with that change is published and the dependency bumped.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bkaradzic-microsoft bkaradzic-microsoft force-pushed the native-update-texture-data branch from db312d3 to 027dcd1 Compare June 18, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants