@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 1.39 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{ShaderProgramType as e}from"../enums.js";import{text as r,outline as t,line as a,icon as s,fill as n,circle as c,background as o}from"./Programs.js";class p{constructor(){this._programByKey=new Map}dispose(){this._programByKey.forEach((e=>e.dispose())),this._programByKey.clear()}getMaterialProgram(e,r,t){const a=r.key<<3|this._getMaterialOptionsValue(r.type,t);if(this._programByKey.has(a))return this._programByKey.get(a);const s=this._getProgramTemplate(r.type),{shaders:n}=s,{vertexShader:c,fragmentShader:o}=n(t),p=r.getShaderHeader(),u=r.getShaderMain(),i=c.replace("#pragma header",p).replace("#pragma main",u),g=e.programCache.acquire(i,o,r.getAttributeLocations());return this._programByKey.set(a,g),g}_getMaterialOptionsValue(r,t){switch(r){case e.BACKGROUND:return(t.pattern?1:0)<<1;case e.FILL:return(t.pattern?1:0)<<1;case e.OUTLINE:return 0;case e.LINE:{const e=t;return(e.sdf?1:0)<<2|(e.pattern?1:0)<<1}case e.ICON:return(t.sdf?1:0)<<1;case e.CIRCLE:case e.TEXT:default:return 0}}_getProgramTemplate(p){switch(p){case e.BACKGROUND:return o;case e.CIRCLE:return c;case e.FILL:return n;case e.ICON:return s;case e.LINE:return a;case e.OUTLINE:return t;case e.TEXT:return r;default:return null}}}export{p as default};