/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{vtlTextureBindingUnitSprites as e}from"../../../definitions.js";import{Technique as t}from"../Technique.js";import{VTLShaderLine as i}from"../shaders/vector-tiles/VTLShaderLine.js";class n extends t{constructor(){super(...arguments),this.type=38,this._mesh=null,this.shaders={line:new i}}shutdown(){this._mesh&&(this._mesh.destroy(),this._mesh=null)}render(t,i){const{context:n,displayLevel:s,painter:l,pixelRatio:a,spriteMosaic:o,state:r,styleLayer:u,styleLayerUID:c}=t,{tiles:f}=i;if(!f.some(e=>e.layerData.get(c)?.lineIndexCount??!1))return;const h=u,p=h.lineMaterial,d=h.getPaintValue("line-translate",s),y=h.getPaintValue("line-translate-anchor",s),m=1/a,g={layerInfo:{displayViewMat3:r.displayViewMat3,displayMat3:1===y?r.displayMat3:r.displayViewMat3,lineTranslation:d,depth:h.z,antialiasing:m},tileInfo:{dvsMat3:null,zoomFactor:1},page:null,color:null,width:null,opacity:null,blur:null,offset:null,colorMix:null,widthMix:null,opacityMix:null,blurMix:null,offsetMix:null,tlbr:null},M=h.getPaintProperty("line-pattern"),x=void 0!==M,v=x&&M.isDataDriven;let D,P;if(x&&!v){const e=M.getValue(s);D=o.getMosaicItemPosition(e)}let V=!1;if(!x){const e=h.getPaintProperty("line-dasharray");if(P=void 0!==e,V=P&&e.isDataDriven,P&&!V){const t=e.getValue(s),i=h.getDashKey(t,h.getLayoutValue("line-cap",s));D=o.getMosaicItemPosition(i)}}const w=x?1:P?2:0;if(null!=D){const{page:t}=D,i=o.getPageSize(t);if(null!=i){o.bind(n,9729,t,e);const s={texture:{texture:o.getTexture(t),unit:e},mosaicSize:[i[0],i[1]]};g.page=s}}const{tileInfo:b}=g;let I=-1;for(const _ of f){if(!_.layerData.has(c))continue;if(b.dvsMat3=_.transforms.displayViewScreenMat3,_.key.level!==I){I=_.key.level;const e=p.getUniforms();for(const t of e){const e=t.getValue(h,s,I,o);t.name in g&&(g[t.name]={value:e})}}const t=2**(s-I)/a;b.zoomFactor=t;const i=_.layerData.get(c);if(!i.lineIndexCount)continue;if(this._mesh=i.getMesh(n),!this._mesh)continue;const r={shader:this.shaders.line,uniforms:g,defines:{lineType:w},optionalAttributes:p.getUsedAttributes(),useComputeBuffer:!1,precisionFactors:p.getPrecisionFactors(),materialKey:p.key};if(v||V){const t=i.patternMap;if(!t)continue;let s=0;for(const i of t.keys()){const t=o.getPageSize(i);null!=t&&(o.bind(n,9729,i,e),g.page={texture:{texture:o.getTexture(i),unit:e},mosaicSize:[t[0],t[1]]},l.submitDrawMeshUntyped(n,r,this._mesh,{stencilRef:_.stencilRef,parts:[s++]}))}}else l.submitDrawMeshUntyped(n,r,this._mesh,{stencilRef:_.stencilRef});_.triangleCount+=i.lineIndexCount/3}}}export{n as VTLTechniqueLine};
