/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{vtlTextureBindingUnitSprites as e}from"../definitions.js";import t from"./WGLBrush.js";import{PrimitiveType as i,DataType as n}from"../../../../webgl/enums.js";class a extends t{constructor(){super(...arguments),this._programOptions={id:!1,pattern:!1,sdf:!1}}dispose(){}drawMany(t,a){const{context:r,displayLevel:o,state:s,painter:l,pixelRatio:f,spriteMosaic:u,styleLayerUID:c,requestRender:d,allowDelayedRender:m}=t;if(!a.some(e=>e.layerData.get(c)?.lineIndexCount??!1))return;const p=t.styleLayer,g=p.lineMaterial,y=l.vectorTilesMaterialManager,M=p.getPaintValue("line-translate",o),_=p.getPaintValue("line-translate-anchor",o),v=p.getPaintProperty("line-pattern"),U=void 0!==v,E=U&&v.isDataDriven;let x,I;if(U&&!E){const e=v.getValue(o);x=u.getMosaicItemPosition(e)}let P=!1;if(!U){const e=p.getPaintProperty("line-dasharray");if(I=void 0!==e,P=I&&e.isDataDriven,I&&!P){const t=e.getValue(o),i=p.getDashKey(t,p.getLayoutValue("line-cap",o));x=u.getMosaicItemPosition(i)}}const D=1/f,S=this._programOptions;S.pattern=U,S.sdf=I;const N=y.getMaterialProgram(r,g,S);if(m&&null!=d&&!N.compiled)return void d();if(r.useProgram(N),N.setUniformMatrix3fv("u_displayViewMat3",s.displayViewMat3),N.setUniformMatrix3fv("u_displayMat3",1===_?s.displayMat3:s.displayViewMat3),N.setUniform2fv("u_lineTranslation",M),N.setUniform1f("u_depth",p.z),N.setUniform1f("u_antialiasing",D),x&&null!=x){const{page:t}=x,i=u.getPageSize(t);null!=i&&(u.bind(r,9729,t,e),N.setUniform2fv("u_mosaicSize",i),N.setUniform1i("u_texture",e))}let T=-1;for(const V of a){if(!V.layerData.has(c))continue;V.key.level!==T&&(T=V.key.level,g.setDataUniforms(N,o,p,T,u));const t=2**(o-T)/f;N.setUniform1f("u_zoomFactor",t);const a=V.layerData.get(c);if(!a.lineIndexCount)continue;a.prepareForRendering(r);const s=a.vao;if(null!=s){if(r.bindVAO(s),N.setUniformMatrix3fv("u_dvsMat3",V.transforms.displayViewScreenMat3),r.setStencilFunction(514,V.stencilRef,255),E||P){const t=a.patternMap;if(!t)continue;for(const[a,o]of t){const t=u.getPageSize(a);null!=t&&(u.bind(r,9729,a,e),N.setUniform2fv("u_mosaicSize",t),N.setUniform1i("u_texture",e),r.drawElements(i.TRIANGLES,o[1],n.UNSIGNED_INT,Uint32Array.BYTES_PER_ELEMENT*o[0]))}}else r.drawElements(i.TRIANGLES,a.lineIndexCount,n.UNSIGNED_INT,Uint32Array.BYTES_PER_ELEMENT*a.lineIndexStart);V.triangleCount+=a.lineIndexCount/3}}}}export{a as WGLBrushVTLLine};
