Skip to content

Commit 9b38142

Browse files
authored
Auto-populate is2DArray/depth in wrapNativeTexture from native layer count (#18535)
1 parent 77b1484 commit 9b38142

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

packages/dev/core/src/Engines/Native/nativeInterfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export interface INativeEngine {
7878
loadCubeTextureWithMips(texture: NativeTexture, data: Array<Array<ArrayBufferView>>, invertY: boolean, srgb: boolean, onSuccess: () => void, onError: () => void): void;
7979
getTextureWidth(texture: NativeTexture): number;
8080
getTextureHeight(texture: NativeTexture): number;
81+
getTextureLayerCount?(texture: NativeTexture): number;
8182
deleteTexture(texture: NativeTexture): void;
8283
readTexture(
8384
texture: NativeTexture,

packages/dev/core/src/Engines/thinNativeEngine.pure.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,13 @@ export class ThinNativeEngine extends ThinEngine {
20352035
internalTexture.baseHeight = this._engine.getTextureHeight(texture);
20362036
internalTexture.width = internalTexture.baseWidth;
20372037
internalTexture.height = internalTexture.baseHeight;
2038+
if (this._engine.getTextureLayerCount) {
2039+
const layerCount = this._engine.getTextureLayerCount(texture);
2040+
if (layerCount > 1) {
2041+
internalTexture.is2DArray = true;
2042+
internalTexture.baseDepth = internalTexture.depth = layerCount;
2043+
}
2044+
}
20382045
internalTexture.isReady = true;
20392046
internalTexture.useMipMaps = hasMipMaps;
20402047
this.updateTextureSamplingMode(samplingMode, internalTexture);
@@ -2073,6 +2080,13 @@ export class ThinNativeEngine extends ThinEngine {
20732080
`updateWrappedNativeTexture: new handle dimensions (${newWidth}x${newHeight}) must match the wrapped texture's dimensions (${internalTexture.baseWidth}x${internalTexture.baseHeight}).`
20742081
);
20752082
}
2083+
if (this._engine.getTextureLayerCount) {
2084+
const newLayerCount = this._engine.getTextureLayerCount(texture);
2085+
const oldLayerCount = internalTexture.is2DArray ? internalTexture.depth : 1;
2086+
if (newLayerCount !== oldLayerCount) {
2087+
throw new Error(`updateWrappedNativeTexture: new handle layer count (${newLayerCount}) must match the wrapped texture's layer count (${oldLayerCount}).`);
2088+
}
2089+
}
20762090

20772091
// Pre-validate before mutating any state so a thrown precondition leaves the InternalTexture untouched.
20782092
// Note: rtWrapper.texture only returns _textures[0]; walk every attachment to catch the multi-RT case where

0 commit comments

Comments
 (0)