UNPKG

@animech-public/playcanvas

Version:
2 lines (1 loc) 2.69 kB
import{TEXTUREDIMENSION_2D as t,SAMPLETYPE_FLOAT as e,SHADERSTAGE_COMPUTE as s,PIXELFORMAT_RGBA8 as r,SAMPLETYPE_UINT as a,SAMPLETYPE_INT as o,TEXTUREDIMENSION_CUBE as i,TEXTUREDIMENSION_3D as n,TEXTUREDIMENSION_2D_ARRAY as u}from"./constants.js";let m=0;const h={[t]:"texture2D",[i]:"textureCube",[n]:"texture3D",[u]:"texture2DArray"};class p{constructor(t,e){this.slot=-1,this.scopeId=null,this.name=t,this.visibility=e}}class l extends p{}class c extends p{constructor(t,e,s=!1){super(t,e),this.readOnly=s}}class f extends p{constructor(s,r,a=t,o=e,i=!0){super(s,r),this.textureDimension=a,this.sampleType=o,this.hasSampler=i}}class x extends p{constructor(e,a=r,o=t,i=!0,n=!1){super(e,s),this.format=a,this.textureDimension=o,this.write=i,this.read=n}}class F{constructor(t,e){this.uniformBufferFormats=[],this.textureFormats=[],this.storageTextureFormats=[],this.storageBufferFormats=[],this.id=m++;let s=0;e.forEach((t=>{t.slot=s++,t instanceof f&&t.hasSampler&&s++,t instanceof l?this.uniformBufferFormats.push(t):t instanceof f?this.textureFormats.push(t):t instanceof x?this.storageTextureFormats.push(t):t instanceof c&&this.storageBufferFormats.push(t)})),this.device=t;const r=t.scope;this.bufferFormatsMap=new Map,this.uniformBufferFormats.forEach(((t,e)=>this.bufferFormatsMap.set(t.name,e))),this.textureFormatsMap=new Map,this.textureFormats.forEach(((t,e)=>{this.textureFormatsMap.set(t.name,e),t.scopeId=r.resolve(t.name)})),this.storageTextureFormatsMap=new Map,this.storageTextureFormats.forEach(((t,e)=>{this.storageTextureFormatsMap.set(t.name,e),t.scopeId=r.resolve(t.name)})),this.storageBufferFormatsMap=new Map,this.storageBufferFormats.forEach(((t,e)=>{this.storageBufferFormatsMap.set(t.name,e),t.scopeId=r.resolve(t.name)})),this.impl=t.createBindGroupFormatImpl(this)}destroy(){this.impl.destroy()}getTexture(t){const e=this.textureFormatsMap.get(t);return void 0!==e?this.textureFormats[e]:null}getStorageTexture(t){const e=this.storageTextureFormatsMap.get(t);return void 0!==e?this.storageTextureFormats[e]:null}getShaderDeclarationTextures(t){let e="";return this.textureFormats.forEach((s=>{let r=h[s.textureDimension];const i="texture2DArray"===r,n=s.sampleType===a?"u":s.sampleType===o?"i":"";r=`${n}${r}`;let u="",m="";i&&(u="_texture",m=`#define ${s.name} ${n}sampler2DArray(${s.name}${u}, ${s.name}_sampler)\n`),e+=`layout(set = ${t}, binding = ${s.slot}) uniform ${r} ${s.name}${u};\n`,s.hasSampler&&(e+=`layout(set = ${t}, binding = ${s.slot+1}) uniform sampler ${s.name}_sampler;\n`),e+=m})),e}loseContext(){}}export{F as BindGroupFormat,c as BindStorageBufferFormat,x as BindStorageTextureFormat,f as BindTextureFormat,l as BindUniformBufferFormat};