Expose bound texture layer count via NativeEngine.getTextureLayerCount#1733
Draft
bghgary wants to merge 2 commits into
Draft
Expose bound texture layer count via NativeEngine.getTextureLayerCount#1733bghgary wants to merge 2 commits into
bghgary wants to merge 2 commits into
Conversation
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>
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 so Babylon.js can populate is2DArray and depth on the wrapped InternalTexture automatically. It returns the bound layer count: ViewNumLayers() when the texture is wrapped as a single-slice view (e.g. an ExternalTexture created with a layerIndex), otherwise NumLayers(). This lets wrapNativeTexture distinguish a whole-array wrap (is2DArray) from a single slice of an array texture (a plain 2D texture), so a single-slice view is not misreported as an array. [Created by Copilot on behalf of @bghgary] Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
f9ca23c to
efa0d70
Compare
Exercises the cross-repo path end to end: getTextureLayerCount feeds Babylon.js wrapNativeTexture (BabylonJS/Babylon.js#18535), which sets is2DArray / depth / baseDepth when a wrapped texture presents more than one layer. Wraps three ExternalTextures and asserts the resulting InternalTexture: - whole array (arraySize 2, no layerIndex) -> is2DArray, depth=baseDepth=2 - single slice (arraySize 2, layerIndex 0) -> plain 2D (one slice of an NV12 array) - single layer (arraySize 1) -> plain 2D The single-slice case guards against regressing a single array slice into a 2D array. Skips cleanly when the native binding or the consuming Babylon.js change is absent so it stays green across the cross-repo landing order. [Created by Copilot on behalf of @bghgary] Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
efa0d70 to
7aa2d93
Compare
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.
Change
Adds
NativeEngine::GetTextureLayerCount(handle)sowrapNativeTexturecan populateis2DArray/depthon a wrappedTexture2DArray(today they stay at 2D defaults). Returns the bound layer count —Texture::ViewNumLayers()for a single-slice view (e.g. anExternalTexturewrapped with alayerIndex), elseTexture::NumLayers()— distinguishing a whole-array wrap (is2DArray) from a single array slice (plain 2D). Pure addition; existing callers unaffected.Single-slice reporting keeps hosts correct: a host that wraps one slice of an NV12 array per video plane needs that plane to stay 2D, not be flagged
is2DArray.Consumer
BJS #18535 consumes this in
wrapNativeTexture. Dormant until that PR ships in@babylonjs/core.Test
ExternalTexture.WrapNativeTextureLayerCount(UnitTests) wraps threeExternalTextures end to end and asserts theInternalTexture:is2DArray,depth=baseDepth=2Skips when the BJS consumer is absent, staying green across the cross-repo landing order.
[Created by Copilot on behalf of @bghgary]