Skip to content

Commit 373db14

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 4ada000 commit 373db14

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
@@ -64,6 +64,17 @@ export interface INativeEngine {
6464
initializeTexture(texture: NativeTexture, width: number, height: number, hasMips: boolean, format: number, renderTarget: boolean, srgb: boolean, samples: number): void;
6565
loadTexture(texture: NativeTexture, data: ArrayBufferView, generateMips: boolean, invertY: boolean, srgb: boolean, onSuccess: () => void, onError: () => void): void;
6666
loadRawTexture(texture: NativeTexture, data: ArrayBufferView, width: number, height: number, format: number, generateMips: boolean, invertY: boolean): void;
67+
updateTextureData(
68+
texture: NativeTexture,
69+
data: ArrayBufferView,
70+
xOffset: number,
71+
yOffset: number,
72+
width: number,
73+
height: number,
74+
faceIndex: number,
75+
lod: number,
76+
invertY: boolean
77+
): void;
6778
loadRawTexture2DArray(
6879
texture: NativeTexture,
6980
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
@@ -305,6 +305,10 @@ export class ThinNativeEngine extends ThinEngine {
305305
this._webGLVersion = 2;
306306
this.disableUniformBuffers = true;
307307
this._shaderPlatformName = "NATIVE";
308+
// Babylon Native is not WebGL and has no _gl context. Report a distinct engine name (like
309+
// WebGPU reports "WebGPU") so application/feature code that branches on engine.name === "WebGL"
310+
// to touch the WebGL-only _gl context skips the native engine instead of dereferencing null.
311+
this._name = "Native";
308312

309313
// TODO: Initialize this more correctly based on the hardware capabilities.
310314
// Init caps
@@ -2662,7 +2666,15 @@ export class ThinNativeEngine extends ThinEngine {
26622666
lod: number = 0,
26632667
generateMipMaps = false
26642668
): void {
2665-
throw new Error("updateTextureData not implemented.");
2669+
if (!texture._hardwareTexture) {
2670+
return;
2671+
}
2672+
2673+
// bgfx updates the requested sub-rectangle of the existing texture (faceIndex selects the cube
2674+
// face / array layer, lod selects the mip level). invertY is forwarded so the native side can match
2675+
// the vertical orientation the base texture upload uses. Mip regeneration after a partial update is
2676+
// not supported on Native, so generateMipMaps is ignored (consistent with the other raw-texture paths).
2677+
this._engine.updateTextureData(texture._hardwareTexture.underlyingResource, imageData, xOffset, yOffset, width, height, faceIndex, lod, texture.invertY);
26662678
}
26672679

26682680
/**

0 commit comments

Comments
 (0)