I don’t understand why you are doing all this to create a WebGPU engine.
You are already not using WebGPUEngine, but Engine :
this.engine = new BABYLON.Engine(this.canvas, true, this.engineOptions, true);
And why create all these things for the canvas?
//webGPUSupported = await BABYLON.WebGPUEngine.IsSupportedAsync
this.gl = this.canvas.getContext("webgl2")
this.gl.drawingBufferColorSpace = "display-p3";
this.gl.unpackColorSpace = "display-p3";
var framebuffer = this.gl.createFramebuffer();
var texture_gl = this.gl.createTexture();
this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, framebuffer);
this.gl.bindTexture(this.gl.TEXTURE_2D, texture_gl);
this.gl.texImage2D(this.gl.TEXTURE_2D, 0, this.gl.RGBA, this.canvas.width, this.canvas.height, 0, this.gl.RGBA, this.gl.UNSIGNED_BYTE, null);
this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER, this.gl.COLOR_ATTACHMENT0, this.gl.TEXTURE_2D, texture_gl, 0);
this.engine = new BABYLON.Engine(this.canvas, true, this.engineOptions, true);
You want to use WebGPU and yet:
this.gl = this.canvas.getContext(‘webgl2’)
You just need this for the canvas and create engine.
var canvas = document.getElementById("renderCanvas");
this.engine = new BABYLON.Engine(canvas, true, this.engineOptions, true);
Anything this.gl
is useless.
I can’t figure out what you are trying to do with the code you have shown.
I think you’re mixing up a lot of things.
You should start here as brianzinn says :
https://doc.babylonjs.com/setup/starterHTML
If I use your code provided, it should look something like this.
this.canvas = document.getElementById("renderCanvas");
//webGPUSupported = await BABYLON.WebGPUEngine.IsSupportedAsync;
this.engine = new BABYLON.Engine(this.canvas, true, this.engineOptions, true);
this.engine.enableOfflineSupport = false;
this.engine.doNotHandleContextLost = true;
this.scene = new BABYLON.Scene(this.engine);
this.camera = this.getCamera();
window.camera = this.camera;
this.scene.ambientColor = new BABYLON.Color3(0.2, 0.2, 0.2);
this.scene.collisionsEnabled = true;
this.scene.useConstantAnimationDeltaTime = true;
this.getLighting();
this.getDds();
var options = new BABYLON.SceneOptimizerOptions(60, 2000);
options.addOptimization(new BABYLON.HardwareScalingOptimization(0, 4));
options.addOptimization(new BABYLON.RenderTargetsOptimization(1));
options.addOptimization(new BABYLON.TextureOptimization(0, 512));
options.addOptimization(new BABYLON.PostProcessesOptimization(1));
this.optimizer_fps = new BABYLON.SceneOptimizer(this.scene, options);
this.engine.runRenderLoop(() => { if (this.scene) { this.scene.render(); } });