engineFactory.js 972 B

12345678910111213141516171819202122232425
  1. import { Engine } from "./engine.js";
  2. import { NullEngine } from "./nullEngine.js";
  3. import { WebGPUEngine } from "./webgpuEngine.js";
  4. /**
  5. * Helper class to create the best engine depending on the current hardware
  6. */
  7. export class EngineFactory {
  8. /**
  9. * Creates an engine based on the capabilities of the underlying hardware
  10. * @param canvas Defines the canvas to use to display the result
  11. * @param options Defines the options passed to the engine to create the context dependencies
  12. * @returns a promise that resolves with the created engine
  13. */
  14. static async CreateAsync(canvas, options) {
  15. const supported = await WebGPUEngine.IsSupportedAsync;
  16. if (supported) {
  17. return WebGPUEngine.CreateAsync(canvas, options);
  18. }
  19. if (Engine.IsSupported) {
  20. return new Engine(canvas, undefined, options);
  21. }
  22. return new NullEngine(options);
  23. }
  24. }
  25. //# sourceMappingURL=engineFactory.js.map