Skip to content

Commit 0333ba6

Browse files
bkaradzicCopilot
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 4ff061b commit 0333ba6

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
@@ -55,6 +55,17 @@ export interface INativeEngine {
5555
initializeTexture(texture: NativeTexture, width: number, height: number, hasMips: boolean, format: number, renderTarget: boolean, srgb: boolean, samples: number): void;
5656
loadTexture(texture: NativeTexture, data: ArrayBufferView, generateMips: boolean, invertY: boolean, srgb: boolean, onSuccess: () => void, onError: () => void): void;
5757
loadRawTexture(texture: NativeTexture, data: ArrayBufferView, width: number, height: number, format: number, generateMips: boolean, invertY: boolean): void;
58+
updateTextureData(
59+
texture: NativeTexture,
60+
data: ArrayBufferView,
61+
xOffset: number,
62+
yOffset: number,
63+
width: number,
64+
height: number,
65+
faceIndex: number,
66+
lod: number,
67+
invertY: boolean
68+
): void;
5869
loadRawTexture2DArray(
5970
texture: NativeTexture,
6071
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
@@ -291,6 +291,10 @@ export class ThinNativeEngine extends ThinEngine {
291291
this._webGLVersion = 2;
292292
this.disableUniformBuffers = true;
293293
this._shaderPlatformName = "NATIVE";
294+
// Babylon Native is not WebGL and has no _gl context. Report a distinct engine name (like
295+
// WebGPU reports "WebGPU") so application/feature code that branches on engine.name === "WebGL"
296+
// to touch the WebGL-only _gl context skips the native engine instead of dereferencing null.
297+
this._name = "Native";
294298

295299
// TODO: Initialize this more correctly based on the hardware capabilities.
296300
// Init caps
@@ -2648,7 +2652,15 @@ export class ThinNativeEngine extends ThinEngine {
26482652
lod: number = 0,
26492653
generateMipMaps = false
26502654
): void {
2651-
throw new Error("updateTextureData not implemented.");
2655+
if (!texture._hardwareTexture) {
2656+
return;
2657+
}
2658+
2659+
// bgfx updates the requested sub-rectangle of the existing texture (faceIndex selects the cube
2660+
// face / array layer, lod selects the mip level). invertY is forwarded so the native side can match
2661+
// the vertical orientation the base texture upload uses. Mip regeneration after a partial update is
2662+
// not supported on Native, so generateMipMaps is ignored (consistent with the other raw-texture paths).
2663+
this._engine.updateTextureData(texture._hardwareTexture.underlyingResource, imageData, xOffset, yOffset, width, height, faceIndex, lod, texture.invertY);
26522664
}
26532665

26542666
/**

0 commit comments

Comments
 (0)