@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 1.6 kB
JavaScript
import{isSome as r}from"../../../../core/maybe.js";import{WGLDrawPhase as e}from"./enums.js";import{createProgramTemplate as t}from"./shaders/MaterialPrograms.js";const a=r=>r===e.HITTEST||r===e.LABEL_ALPHA,s=r=>(a(r)?1:0)|(r===e.HIGHLIGHT?2:0),o=({rendererInfo:e,drawPhase:t},a,o)=>`${a.getVariationHash()}-${s(t)}-${e.getVariationHash()}-${r(o)&&o.join(".")}`,i=(t,s,o,i={})=>{if(i={...i,...s.getVariation(),...t.rendererInfo.getVariation(),highlight:t.drawPhase===e.HIGHLIGHT,id:a(t.drawPhase)},r(o))for(const r of o)i[r]=!0;return i};class h{constructor(r){this._rctx=r,this._programByKey=new Map}dispose(){this._programByKey.forEach((r=>r.dispose())),this._programByKey.clear()}getProgram(r,e=[]){const a=r.vsPath+"."+r.fsPath+JSON.stringify(e);if(this._programByKey.has(a))return this._programByKey.get(a);const s={...e.map((r=>"string"==typeof r?{name:r,value:!0}:r)).reduce(((r,e)=>({...r,[e.name]:e.value})),{})},{vsPath:o,fsPath:i,attributes:h}=r,n=t(o,i,h,s),g=this._rctx.programCache.acquire(n.shaders.vertexShader,n.shaders.fragmentShader,n.attributes);if(!g)throw new Error("Unable to get program for key: ${key}");return this._programByKey.set(a,g),g}getMaterialProgram(r,e,a,s,h){const n=o(r,e,h);if(this._programByKey.has(n))return this._programByKey.get(n);const g=i(r,e,h,{ignoresSamplerPrecision:r.context.driverTest.ignoresSamplerPrecision.result}),m=t(a,a,s,g),y=this._rctx.programCache.acquire(m.shaders.vertexShader,m.shaders.fragmentShader,m.attributes);if(!y)throw new Error("Unable to get program for key: ${key}");return this._programByKey.set(n,y),y}}export{h as default};