Skip to content

Expose Texture::NumLayers via NativeEngine.getTextureLayerCount#1733

Draft
bghgary wants to merge 1 commit into
BabylonJS:masterfrom
bghgary:expose-texture-layer-count
Draft

Expose Texture::NumLayers via NativeEngine.getTextureLayerCount#1733
bghgary wants to merge 1 commit into
BabylonJS:masterfrom
bghgary:expose-texture-layer-count

Conversation

@bghgary
Copy link
Copy Markdown
Contributor

@bghgary bghgary commented Jun 4, 2026

Context

engine.wrapNativeTexture(...) in Babylon.js sets InternalTexture properties from native engine bindings (getTextureWidth, getTextureHeight). Today there is no binding to expose the layer count, so wrapped Texture2DArray resources end up with is2DArray = false and depth = 1 on the InternalTexture, even when the underlying native texture has multiple array slices. Hosts then have to thread that information through their own JS bridge to set the flags manually.

Change

Add NativeEngine::GetTextureLayerCount(handle) -> uint32_t returning Graphics::Texture::NumLayers(). Mirrors the existing GetTextureWidth / GetTextureHeight pattern. Pure addition; no behavior change for existing callers.

Consumer

Companion BJS PR BabylonJS/Babylon.js#18535 uses this binding in wrapNativeTexture to auto-populate is2DArray and depth on the wrapped InternalTexture. Until that BJS PR merges + a new @babylonjs/core ships, this binding is dormant — hosts that don't call it see no change.

[Created by Copilot on behalf of @bghgary]

Babylon.js side wraps native textures with engine.wrapNativeTexture and
sets InternalTexture properties from the engine bindings. Today the
binding only exposes width and height, so consumers cannot detect that
a wrapped texture is a Texture2DArray and InternalTexture.is2DArray /
.depth stay at their defaults.

Add getTextureLayerCount returning Texture::NumLayers so Babylon.js can
populate is2DArray and depth on the wrapped InternalTexture
automatically, without the host having to thread the layer count
through its own bridge.

[Created by Copilot on behalf of @bghgary]

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bghgary added a commit to bghgary/Babylon.js that referenced this pull request Jun 4, 2026
Mark `INativeEngine.getTextureLayerCount` optional and feature-detect
(`typeof === "function"`) before calling, so older Babylon Native builds
that don't expose the binding keep working:

- `wrapNativeTexture`: if the binding is absent, skip auto-populating
  `is2DArray` / `depth`. The wrapped InternalTexture stays at the
  defaults, matching pre-existing behavior.
- `updateWrappedNativeTexture`: if the binding is absent, skip the
  layer-count validation. Dimensions are still validated.

Removes the runtime dependency on BabylonJS/BabylonNative#1733, so this
PR can land independently. Hosts running on an updated native engine
get the auto-detect for free; hosts on older native engines see no
change.

[Created by Copilot on behalf of @bghgary]

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

1 participant