Engine Initialization
Creating an Engine instance links Babylon.js to your canvas and initializes the rendering context. For WebGPU, use `WebGPUEngine` instead:
// Get the canvas element from the DOM
const canvas = document.getElementById("renderCanvas");
// Initialize the Babylon Engine with the canvas
// Parameters: canvas, antialias, options, adaptToDeviceRatio
const engine = new BABYLON.Engine(canvas, true, {
preserveDrawingBuffer: true,
stencil: true,
disableWebGL2Support: false
}, true);
// Or use WebGPU for better performance (async initialization)
const webGPUEngine = new BABYLON.WebGPUEngine(canvas);
await webGPUEngine.initAsync();
// Then use webGPUEngine the same way as the WebGL engine