Expose Texture::NumLayers via NativeEngine.getTextureLayerCount#1733
Draft
bghgary wants to merge 1 commit into
Draft
Expose Texture::NumLayers via NativeEngine.getTextureLayerCount#1733bghgary wants to merge 1 commit into
bghgary wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
engine.wrapNativeTexture(...)in Babylon.js setsInternalTextureproperties from native engine bindings (getTextureWidth,getTextureHeight). Today there is no binding to expose the layer count, so wrappedTexture2DArrayresources end up withis2DArray = falseanddepth = 1on theInternalTexture, 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_treturningGraphics::Texture::NumLayers(). Mirrors the existingGetTextureWidth/GetTextureHeightpattern. Pure addition; no behavior change for existing callers.Consumer
Companion BJS PR BabylonJS/Babylon.js#18535 uses this binding in
wrapNativeTextureto auto-populateis2DArrayanddepthon the wrappedInternalTexture. Until that BJS PR merges + a new@babylonjs/coreships, this binding is dormant — hosts that don't call it see no change.[Created by Copilot on behalf of @bghgary]