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