BabylonJS/Babylon.js · error

wrapWebGLTexture is not supported, use wrapNativeTexture ins

Error message

wrapWebGLTexture is not supported, use wrapNativeTexture instead.

What it means

NativeEngine (Babylon Native) does not consume WebGL handles, so wrapWebGLTexture() — which wraps an existing WebGL texture into an InternalTexture — is intentionally unimplemented and always throws. The Native equivalent is wrapNativeTexture().

Source

Thrown at packages/dev/core/src/Engines/nativeEngine.pure.ts:37

     * Will be overriden by the Thin Native engine implementation
     * No code should be placed here
     */
    protected _initializeNativeEngine(_adaptToDeviceRatio: boolean): void {}

    /**
     * @internal
     */
    public constructor(options: NativeEngineOptions = {}) {
        super(null, false, undefined, options.adaptToDeviceRatio);

        this._initializeNativeEngine(options.adaptToDeviceRatio ?? false);
    }

    /**
     * @internal
     */
    public override wrapWebGLTexture(): InternalTexture {
        throw new Error("wrapWebGLTexture is not supported, use wrapNativeTexture instead.");
    }

    /**
     * @internal
     */
    public override updateWrappedWebGLTexture(): void {
        throw new Error("updateWrappedWebGLTexture is not supported, use updateWrappedNativeTexture instead.");
    }

    /**
     * @internal
     */
    public override _uploadImageToTexture(texture: InternalTexture, image: HTMLImageElement, _faceIndex: number = 0, _lod: number = 0) {
        throw new Error("_uploadArrayBufferViewToTexture not implemented.");
    }
}

/**

View on GitHub (pinned to 0592b347b8)

Solutions

  1. On native, call wrapNativeTexture() with the platform-native texture handle instead.
  2. Branch on engine capabilities: if ((engine as any).wrapNativeTexture) use it, else use wrapWebGLTexture().
  3. Remove the WebGL-only wrapping code from the native path.

Example fix

// before
const tex = engine.wrapWebGLTexture(glTexture);
// after
const tex = "wrapNativeTexture" in engine
  ? engine.wrapNativeTexture(nativeTexture)
  : engine.wrapWebGLTexture(glTexture);
Defensive patterns

Strategy: type-guard

Validate before calling

const isNative = typeof (engine as any).wrapNativeTexture === "function";
if (!isNative) engine.wrapWebGLTexture(handle);

Type guard

function isNativeEngine(e) {
  return "wrapNativeTexture" in e;
}

Try / catch

try {
  return engine.wrapWebGLTexture(handle);
} catch (e) {
  if (/use wrapNativeTexture/.test(e.message)) {
    return (engine as any).wrapNativeTexture(nativeHandle);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling engine.wrapWebGLTexture(...) on a NativeEngine instance (Babylon Native / react-native-babylon / Node native build).

Common situations: Code shared between the web and native builds that assumes a WebGL engine, accidentally running the WebGL wrapping path under Babylon Native.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/81101ebe64b29426. Report an issue: GitHub.