UNPKG

@animech-public/playcanvas

Version:
2 lines (1 loc) 1.09 kB
import{platform as e}from"../../core/platform.js";import{DEVICETYPE_WEBGL2 as r,DEVICETYPE_WEBGL1 as l,DEVICETYPE_NULL as o,DEVICETYPE_WEBGPU as n}from"./constants.js";import{WebgpuGraphicsDevice as s}from"./webgpu/webgpu-graphics-device.js";import{WebglGraphicsDevice as t}from"./webgl/webgl-graphics-device.js";import{NullGraphicsDevice as i}from"./null/null-graphics-device.js";function p(p,c={}){var u;const a=null!=(u=c.deviceTypes)?u:[];(a.includes(r)||a.push(r),a.includes(l)||a.push(l),a.includes(o)||a.push(o),e.browser&&navigator.xr)&&(null!=c.xrCompatible||(c.xrCompatible=!0));const g=[];for(let e=0;e<a.length;e++){var m;const u=a[e];u===n&&null!=(m=window)&&null!=(m=m.navigator)&&m.gpu&&g.push((()=>new s(p,c).initWebGpu(c.glslangUrl,c.twgslUrl))),u!==l&&u!==r||g.push((()=>(c.preferWebGl2=u===r,new t(p,c)))),u===o&&g.push((()=>new i(p,c)))}return new Promise(((e,r)=>{let l=0;const o=()=>{l>=g.length?r(new Error("Failed to create a graphics device")):Promise.resolve(g[l++]()).then((r=>{r?e(r):o()})).catch((e=>{console.log(e),o()}))};o()}))}export{p as createGraphicsDevice};