Skip to content

Commit aee206d

Browse files
bkaradzicCopilot
authored andcommitted
[Native] Report engine.name "Native" and implement updateTextureData
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>
1 parent f590bad commit aee206d

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ export interface INativeEngine {
7474
): void;
7575
loadTexture(texture: NativeTexture, data: ArrayBufferView, generateMips: boolean, invertY: boolean, srgb: boolean, onSuccess: () => void, onError: () => void): void;
7676
loadRawTexture(texture: NativeTexture, data: ArrayBufferView, width: number, height: number, format: number, generateMips: boolean, invertY: boolean): void;
77+
updateTextureData(
78+
texture: NativeTexture,
79+
data: ArrayBufferView,
80+
xOffset: number,
81+
yOffset: number,
82+
width: number,
83+
height: number,
84+
faceIndex: number,
85+
lod: number,
86+
invertY: boolean
87+
): void;
7788
loadRawTexture2DArray(
7889
texture: NativeTexture,
7990
data: Nullable<ArrayBufferView>,

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ export class ThinNativeEngine extends ThinEngine {
307307
this._webGLVersion = 2;
308308
this.disableUniformBuffers = true;
309309
this._shaderPlatformName = "NATIVE";
310+
// Babylon Native is not WebGL and has no _gl context. Report a distinct engine name (like
311+
// WebGPU reports "WebGPU") so application/feature code that branches on engine.name === "WebGL"
312+
// to touch the WebGL-only _gl context skips the native engine instead of dereferencing null.
313+
this._name = "Native";
310314

311315
// TODO: Initialize this more correctly based on the hardware capabilities.
312316
// Init caps
@@ -2757,7 +2761,15 @@ export class ThinNativeEngine extends ThinEngine {
27572761
lod: number = 0,
27582762
generateMipMaps = false
27592763
): void {
2760-
throw new Error("updateTextureData not implemented.");
2764+
if (!texture._hardwareTexture) {
2765+
return;
2766+
}
2767+
2768+
// bgfx updates the requested sub-rectangle of the existing texture (faceIndex selects the cube
2769+
// face / array layer, lod selects the mip level). invertY is forwarded so the native side can match
2770+
// the vertical orientation the base texture upload uses. Mip regeneration after a partial update is
2771+
// not supported on Native, so generateMipMaps is ignored (consistent with the other raw-texture paths).
2772+
this._engine.updateTextureData(texture._hardwareTexture.underlyingResource, imageData, xOffset, yOffset, width, height, faceIndex, lod, texture.invertY);
27612773
}
27622774

27632775
/**

0 commit comments

Comments
 (0)