From 62da094d4f008c1df8b680eb2e1be57fac283dd4 Mon Sep 17 00:00:00 2001 From: Branimir Karadzic Date: Thu, 11 Jun 2026 07:54:50 -0700 Subject: [PATCH 1/3] [Native] Report engine.name "Native" and implement updateTextureData MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The native engine inherited engine.name === "WebGL" from ThinEngine, so code that guards WebGL-only _gl access with ngine.name === "WebGL" ran on the native engine and dereferenced the null _gl context (e.g. TEXTURE_2D undefined). updateTextureData also threw "not implemented". - Report a distinct engine name ("Native"), mirroring how the WebGPU engine reports "WebGPU", so name-gated WebGL-only code paths skip the native engine. - Implement updateTextureData: forward the sub-rectangle (plus invertY, so the native side can match the base texture's vertical orientation) to the native engine. generateMipMaps is ignored (mip regeneration after a partial update is not supported on Native). Pairs with the BabylonNative change adding NativeEngine::UpdateTextureData. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../core/src/Engines/Native/nativeInterfaces.ts | 11 +++++++++++ .../dev/core/src/Engines/thinNativeEngine.pure.ts | 14 +++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/dev/core/src/Engines/Native/nativeInterfaces.ts b/packages/dev/core/src/Engines/Native/nativeInterfaces.ts index 93042b31403..2b07d26d39a 100644 --- a/packages/dev/core/src/Engines/Native/nativeInterfaces.ts +++ b/packages/dev/core/src/Engines/Native/nativeInterfaces.ts @@ -74,6 +74,17 @@ export interface INativeEngine { ): void; loadTexture(texture: NativeTexture, data: ArrayBufferView, generateMips: boolean, invertY: boolean, srgb: boolean, onSuccess: () => void, onError: () => void): void; loadRawTexture(texture: NativeTexture, data: ArrayBufferView, width: number, height: number, format: number, generateMips: boolean, invertY: boolean): void; + updateTextureData( + texture: NativeTexture, + data: ArrayBufferView, + xOffset: number, + yOffset: number, + width: number, + height: number, + faceIndex: number, + lod: number, + invertY: boolean + ): void; loadRawTexture2DArray( texture: NativeTexture, data: Nullable, diff --git a/packages/dev/core/src/Engines/thinNativeEngine.pure.ts b/packages/dev/core/src/Engines/thinNativeEngine.pure.ts index d86eea235b8..8cd76512241 100644 --- a/packages/dev/core/src/Engines/thinNativeEngine.pure.ts +++ b/packages/dev/core/src/Engines/thinNativeEngine.pure.ts @@ -307,6 +307,10 @@ export class ThinNativeEngine extends ThinEngine { this._webGLVersion = 2; this.disableUniformBuffers = true; this._shaderPlatformName = "NATIVE"; + // Babylon Native is not WebGL and has no _gl context. Report a distinct engine name (like + // WebGPU reports "WebGPU") so application/feature code that branches on engine.name === "WebGL" + // to touch the WebGL-only _gl context skips the native engine instead of dereferencing null. + this._name = "Native"; // TODO: Initialize this more correctly based on the hardware capabilities. // Init caps @@ -2821,7 +2825,15 @@ export class ThinNativeEngine extends ThinEngine { lod: number = 0, generateMipMaps = false ): void { - throw new Error("updateTextureData not implemented."); + if (!texture._hardwareTexture) { + return; + } + + // bgfx updates the requested sub-rectangle of the existing texture (faceIndex selects the cube + // face / array layer, lod selects the mip level). invertY is forwarded so the native side can match + // the vertical orientation the base texture upload uses. Mip regeneration after a partial update is + // not supported on Native, so generateMipMaps is ignored (consistent with the other raw-texture paths). + this._engine.updateTextureData(texture._hardwareTexture.underlyingResource, imageData, xOffset, yOffset, width, height, faceIndex, lod, texture.invertY); } /** From aef72b957a08632266cddf36cd7dcdea0c582a17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 17 Jun 2026 07:25:56 -0700 Subject: [PATCH 2/3] Native: make updateTextureData binding optional on INativeEngine --- packages/dev/core/src/Engines/Native/nativeInterfaces.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dev/core/src/Engines/Native/nativeInterfaces.ts b/packages/dev/core/src/Engines/Native/nativeInterfaces.ts index 2b07d26d39a..90e077e9dec 100644 --- a/packages/dev/core/src/Engines/Native/nativeInterfaces.ts +++ b/packages/dev/core/src/Engines/Native/nativeInterfaces.ts @@ -74,7 +74,7 @@ export interface INativeEngine { ): void; loadTexture(texture: NativeTexture, data: ArrayBufferView, generateMips: boolean, invertY: boolean, srgb: boolean, onSuccess: () => void, onError: () => void): void; loadRawTexture(texture: NativeTexture, data: ArrayBufferView, width: number, height: number, format: number, generateMips: boolean, invertY: boolean): void; - updateTextureData( + updateTextureData?( texture: NativeTexture, data: ArrayBufferView, xOffset: number, From 56b98ff49eb3ce19a0cf7bcade335d9eb07a4bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 17 Jun 2026 07:26:09 -0700 Subject: [PATCH 3/3] Native: throw explicit error if old-native lacks updateTextureData Addresses review: existence-check before calling this._engine.updateTextureData so older native binaries (PROTOCOL_VERSION not bumped) restore the explicit 'updateTextureData not implemented.' error instead of a raw 'is not a function'. --- packages/dev/core/src/Engines/thinNativeEngine.pure.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/dev/core/src/Engines/thinNativeEngine.pure.ts b/packages/dev/core/src/Engines/thinNativeEngine.pure.ts index 8cd76512241..bfc26f3b8bc 100644 --- a/packages/dev/core/src/Engines/thinNativeEngine.pure.ts +++ b/packages/dev/core/src/Engines/thinNativeEngine.pure.ts @@ -2829,6 +2829,10 @@ export class ThinNativeEngine extends ThinEngine { return; } + if (!this._engine.updateTextureData) { + throw new Error("updateTextureData not implemented."); + } + // bgfx updates the requested sub-rectangle of the existing texture (faceIndex selects the cube // face / array layer, lod selects the mip level). invertY is forwarded so the native side can match // the vertical orientation the base texture upload uses. Mip regeneration after a partial update is