Skip to content

[Native] Add cube render target support to the native engine#18561

Merged
bkaradzic-microsoft merged 4 commits into
masterfrom
native-cube-render-target
Jun 18, 2026
Merged

[Native] Add cube render target support to the native engine#18561
bkaradzic-microsoft merged 4 commits into
masterfrom
native-cube-render-target

Conversation

@bkaradzic-microsoft

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

Copy link
Copy Markdown
Member

Paired native PR: BabylonJS/BabylonNative#1750

What

Adds cube render target support to the Babylon Native engine. Previously the
native engine had no createRenderTargetCubeTexture override and
bindFramebuffer(faceIndex) threw, so any feature that renders into a cube map
ReflectionProbe, point-light cube shadow maps — fell through to the WebGL
code path and dereferenced the null _gl context (TEXTURE_CUBE_MAP undefined).

Changes (packages/dev/core/src/Engines)

  • thinNativeEngine.pure.ts
    • createRenderTargetCubeTexture: creates a native cube color texture and one
      framebuffer per face (the native side binds the matching cube layer).
    • bindFramebuffer: binds the per-face framebuffer for cube render targets.
    • generateMipMapsForCubemap: no-op on Native — bgfx auto-generates the mip
      chain on render-target resolve, the same way 2D RTTs get their mips.
  • Native/nativeRenderTargetWrapper.ts: tracks per-face framebuffers and
    releases them on dispose.
  • Native/nativeInterfaces.ts: threads the cube/layer params through
    initializeTexture and createFrameBuffer.

Paired native change

Requires the matching BabylonNative C++ change (cube color texture + per-face
attachment). Draft until both land.

Testing

Built babylon.max.js and ran the BabylonNative Playground validation suite
(D3D11). The "Shadows with instances" tests (left/right handed), which
previously crashed, now pass; the ReflectionProbe and point-light-shadow scenes
render with correct geometry and orientation.


Related PRs & landing order

Co-dependent; land in this order:

  1. Babylon.js [Native] Add cube render target support to the native engine #18561 first — adds the cube render-target TS overrides; no WebGL behavior change.
  2. A babylonjs npm release ships that TS change.
  3. BabylonNative Export Entities With Optional Default Camera #1750 last — bumps the bundled babylonjs and re-enables the 2 Shadows with instances (left/right handed) validation tests, which only pass once the paired JS is present in the bundled engine.

@bjsplat

bjsplat commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat

bjsplat commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Snapshot stored with reference name:
refs/pull/18561/merge

Test environment:
https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18561/merge/index.html

To test a playground add it to the URL, for example:

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18561/merge/index.html#WGZLGJ#4600

Links to test your changes to core in the published versions of the Babylon tools (does not contain changes you made to the tools themselves):

https://playground.babylonjs.com/?snapshot=refs/pull/18561/merge
https://sandbox.babylonjs.com/?snapshot=refs/pull/18561/merge
https://gui.babylonjs.com/?snapshot=refs/pull/18561/merge
https://nme.babylonjs.com/?snapshot=refs/pull/18561/merge

To test the snapshot in the playground with a playground ID add it after the snapshot query string:

https://playground.babylonjs.com/?snapshot=refs/pull/18561/merge#BCU1XR#0

If you made changes to the sandbox or playground in this PR, additional comments will be generated soon containing links to the dev versions of those tools.

@bjsplat

bjsplat commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

🟢 Memory Leak Test Results

13 passed, 0 leaked out of 13 scenarios

🟢 All memory leak tests passed — no leaks detected.

Passed Scenarios (13)
Scenario Package
Core Feature Stack @babylonjs/core
Core Rendering Materials Shadows Stack @babylonjs/core
Core Textures Render Targets PostProcess Stack @babylonjs/core
GUI Fullscreen UI Controls @babylonjs/gui
GUI Mesh ADT Controls @babylonjs/gui
Loaders Boombox Import @babylonjs/loaders
Loaders OBJ Direct Load @babylonjs/loaders
Loaders STL Direct Load @babylonjs/loaders
Materials Library Stack @babylonjs/materials
Serializers glTF Export @babylonjs/serializers
Serializers GLB Export @babylonjs/serializers
PostProcesses Digital Rain Stack @babylonjs/post-processes
Procedural Textures Stack @babylonjs/procedural-textures

@bjsplat

bjsplat commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

⚡ Performance Test Results

🟢 All performance tests passed — no regressions detected.

@bkaradzic-microsoft
bkaradzic-microsoft force-pushed the native-cube-render-target branch from 3309ed2 to cfa76cd Compare June 16, 2026 17:04
NativeEngine had no createRenderTargetCubeTexture / per-face bindFramebuffer
override, so ReflectionProbe and point-light cube shadows fell through to the
WebGL path and dereferenced the null _gl context (TEXTURE_CUBE_MAP undefined).

- createRenderTargetCubeTexture: native cube color texture + one framebuffer
  per face (the native side binds the matching cube layer).
- bindFramebuffer: bind the per-face framebuffer for cube render targets.
- generateMipMapsForCubemap: no-op on Native (bgfx auto-generates the mip
  chain on render-target resolve, like 2D RTTs).
- NativeRenderTargetWrapper: track per-face framebuffers, release on dispose.
- nativeInterfaces: thread cube/layer params through initializeTexture and
  createFrameBuffer.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bkaradzic-microsoft
bkaradzic-microsoft force-pushed the native-cube-render-target branch from cfa76cd to 3381c85 Compare June 16, 2026 23:51
@bjsplat

bjsplat commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

🟢 Memory Leak Test Results

13 passed, 0 leaked out of 13 scenarios

🟢 All memory leak tests passed — no leaks detected.

Passed Scenarios (13)
Scenario Package
Core Feature Stack @babylonjs/core
Core Rendering Materials Shadows Stack @babylonjs/core
Core Textures Render Targets PostProcess Stack @babylonjs/core
GUI Fullscreen UI Controls @babylonjs/gui
GUI Mesh ADT Controls @babylonjs/gui
Loaders Boombox Import @babylonjs/loaders
Loaders OBJ Direct Load @babylonjs/loaders
Loaders STL Direct Load @babylonjs/loaders
Materials Library Stack @babylonjs/materials
Serializers glTF Export @babylonjs/serializers
Serializers GLB Export @babylonjs/serializers
PostProcesses Digital Rain Stack @babylonjs/post-processes
Procedural Textures Stack @babylonjs/procedural-textures

@bjsplat

bjsplat commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

⚡ Performance Test Results

🟢 All performance tests passed — no regressions detected.

@bjsplat

bjsplat commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

@bghgary bghgary left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Reviewed by Copilot on behalf of @bghgary]

LGTM; one non-blocking note inline.

Comment thread packages/dev/core/src/Engines/thinNativeEngine.pure.ts
@bkaradzic-microsoft
bkaradzic-microsoft marked this pull request as ready for review June 17, 2026 22:12
Copilot AI review requested due to automatic review settings June 17, 2026 22:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Babylon Native support for rendering into cube-map render targets by implementing a Native-specific createRenderTargetCubeTexture path and updating framebuffer binding to select per-face framebuffers. This closes the gap where cube-map RTT features (eg ReflectionProbe, point-light cube shadows) previously fell back to WebGL code paths and crashed on Native due to the missing GL context.

Changes:

  • Implement ThinNativeEngine.createRenderTargetCubeTexture with native cube texture initialization and one framebuffer per cube face.
  • Update Native RTT wrapper lifecycle to track/release per-face framebuffers.
  • Extend the native engine TypeScript interface to thread isCube/layer parameters into texture/framebuffer initialization.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
packages/dev/core/src/Engines/thinNativeEngine.pure.ts Adds cube RTT creation + per-face framebuffer binding, plus a Native no-op override for cubemap mipgen.
packages/dev/core/src/Engines/Native/nativeRenderTargetWrapper.ts Tracks per-face framebuffer arrays for cube RTTs and releases them on reassignment/dispose.
packages/dev/core/src/Engines/Native/nativeInterfaces.ts Updates native interface signatures to support cube texture init and per-layer/per-face framebuffer creation.

Comment thread packages/dev/core/src/Engines/thinNativeEngine.pure.ts
Comment thread packages/dev/core/src/Engines/thinNativeEngine.pure.ts
Comment thread packages/dev/core/src/Engines/thinNativeEngine.pure.ts
Comment thread packages/dev/core/src/Engines/thinNativeEngine.pure.ts
Addresses review: cube RT adds isCube/layer params that old native silently ignores (2D RT with aliased faces, no error). Bumping the protocol version makes any JS<->Native version skew fail loudly at engine init via the existing strict-equality check, instead of rendering incorrectly. Pairs with the native-side bump in BabylonJS/BabylonNative#1750 (landed together with the babylonjs pin bump).
@bjsplat

bjsplat commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

…are MSAA update

Address Copilot reviewer feedback on createRenderTargetCubeTexture:
- apply float/half-float linear-filtering samplingMode fallback (NEAREST)
- propagate options.label to the InternalTexture
- push the hand-built texture to _internalTexturesCache for lifecycle tracking
- make updateRenderTargetTextureSampleCount cube-aware (reinit with isCube + recreate all six per-face framebuffers) so changing samples after creation no longer breaks bindFramebuffer(faceIndex)
@bjsplat

bjsplat commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

Comment thread packages/dev/core/src/Engines/Native/nativeRenderTargetWrapper.ts
@bjsplat

bjsplat commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Snapshot stored with reference name:
refs/pull/18561/merge

Test environment:
https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18561/merge/index.html

To test a playground add it to the URL, for example:

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18561/merge/index.html#WGZLGJ#4600

Links to test your changes to core in the published versions of the Babylon tools (does not contain changes you made to the tools themselves):

https://playground.babylonjs.com/?snapshot=refs/pull/18561/merge
https://sandbox.babylonjs.com/?snapshot=refs/pull/18561/merge
https://gui.babylonjs.com/?snapshot=refs/pull/18561/merge
https://nme.babylonjs.com/?snapshot=refs/pull/18561/merge

To test the snapshot in the playground with a playground ID add it after the snapshot query string:

https://playground.babylonjs.com/?snapshot=refs/pull/18561/merge#BCU1XR#0

If you made changes to the sandbox or playground in this PR, additional comments will be generated soon containing links to the dev versions of those tools.

@bjsplat

bjsplat commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

🟢 Memory Leak Test Results

13 passed, 0 leaked out of 13 scenarios

🟢 All memory leak tests passed — no leaks detected.

Passed Scenarios (13)
Scenario Package
Core Feature Stack @babylonjs/core
Core Rendering Materials Shadows Stack @babylonjs/core
Core Textures Render Targets PostProcess Stack @babylonjs/core
GUI Fullscreen UI Controls @babylonjs/gui
GUI Mesh ADT Controls @babylonjs/gui
Loaders Boombox Import @babylonjs/loaders
Loaders OBJ Direct Load @babylonjs/loaders
Loaders STL Direct Load @babylonjs/loaders
Materials Library Stack @babylonjs/materials
Serializers glTF Export @babylonjs/serializers
Serializers GLB Export @babylonjs/serializers
PostProcesses Digital Rain Stack @babylonjs/post-processes
Procedural Textures Stack @babylonjs/procedural-textures

@bjsplat

bjsplat commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

⚡ Performance Test Results

🟢 All performance tests passed — no regressions detected.

@bjsplat

bjsplat commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

The required Native tests check runs the PR JS against the BabylonNative
Nightly artifact (native PROTOCOL_VERSION = 9 from BN master), so bumping the
JS side to 10 made new NativeEngine() throw a protocol-version mismatch and
crash every native test. The version gate will land later as a coordinated
atomic bump (BJS JS + BabylonNative native + babylonjs pin together).
@bjsplat

bjsplat commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

🟢 Memory Leak Test Results

13 passed, 0 leaked out of 13 scenarios

🟢 All memory leak tests passed — no leaks detected.

Passed Scenarios (13)
Scenario Package
Core Feature Stack @babylonjs/core
Core Rendering Materials Shadows Stack @babylonjs/core
Core Textures Render Targets PostProcess Stack @babylonjs/core
GUI Fullscreen UI Controls @babylonjs/gui
GUI Mesh ADT Controls @babylonjs/gui
Loaders Boombox Import @babylonjs/loaders
Loaders OBJ Direct Load @babylonjs/loaders
Loaders STL Direct Load @babylonjs/loaders
Materials Library Stack @babylonjs/materials
Serializers glTF Export @babylonjs/serializers
Serializers GLB Export @babylonjs/serializers
PostProcesses Digital Rain Stack @babylonjs/post-processes
Procedural Textures Stack @babylonjs/procedural-textures

@bjsplat

bjsplat commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

@bkaradzic-microsoft
bkaradzic-microsoft merged commit 5adc34d into master Jun 18, 2026
22 checks passed
@bkaradzic-microsoft
bkaradzic-microsoft deleted the native-cube-render-target branch June 18, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants