/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/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 s}from"../shaders/vector-tiles/VTLShaderLine.js";class n extends i{constructor(){super(...arguments),this.type=41,this._mesh=null,this.shaders={line:new s}}shutdown(){this._mesh=null}render(i,s){const{context:n,displayLevel:l,drawPhase:a,is3D:o,painter:r,pixelRatio:u,spriteMosaic:c,state:p,styleLayer:f,styleLayerUID:d}=i,{tiles:h}=s;if(!h.some(e=>e.layerData.get(d)?.lineIndexCount??!1))return;const y=f,m=y.lineMaterial,g=y.getPaintValue("line-translate",l),M=y.getPaintValue("line-translate-anchor",l),x=1/u,v={layerInfo:{displayViewMat3:p.displayViewMat3,displayMat3:1===M?p.displayMat3:p.displayViewMat3,lineTranslation:g,depth:y.z,antialiasing:x},tileInfo:{dvsMat3:null,zoomFactor:1,tileOpacity: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},w=y.getPaintProperty("line-pattern"),P=void 0!==w,D=P&&w.isDataDriven;let T,V;if(P&&!D){const e=w.getValue(l);T=c.getMosaicItemPosition(e)}let b=!1;if(!P){const e=y.getPaintProperty("line-dasharray");if(V=void 0!==e,b=V&&e.isDataDriven,V&&!b){const t=e.getValue(l),i=y.getDashKey(t,y.getLayoutValue("line-cap",l));if(T=c.getMosaicItemPosition(i),null==T)return}}const z=P?1:V?2:0,I=m.key+e({lineType:z}),S={pageTexture:null};if(null!=T){const{page:e}=T,i=c.getPageSize(e);if(null!=i){c.bind(n,9729,e,t);const s={mosaicSize:[i[0],i[1]]};S.pageTexture={texture:c.getTexture(e),unit:t},v.page=s}}o||r.setPipelineState({color:{write:[!0,!0,!0,!0],blendMode:"composite"},stencil:{write:!1,test:{compare:514,op:{fail:7680,zFail:7680,zPass:7681},mask:255}},depth:{write:!1,test:515}});const{tileInfo:L}=v;let U=-1;for(const e of h){if(!e.layerData.has(d))continue;if(L.dvsMat3=e.transforms.displayViewScreenMat3,e.key.level!==U){U=e.key.level;const t=m.getUniforms();for(const e of t){const t=e.getValue(y,l,U,c);e.name in v&&(v[e.name]={value:t})}}const i=2**(l-U)/u;L.zoomFactor=i;const s=e.layerData.get(d);if(!s.lineIndexCount||s.isDestroyed)continue;if(this._mesh=s.getMesh(n),!this._mesh)continue;L.tileOpacity=1===a?e.fader.value():1;const o={shader:this.shaders.line,uniforms:v,textures:S,defines:{lineType:z},optionalAttributes:m.getUsedAttributes(),useComputeBuffer:!1,precisionFactors:m.getPrecisionFactors(),materialKey:I};if(D||b){const i=s.patternMap;if(!i)continue;let l=0;for(const s of i.keys()){const i=c.getPageSize(s);null!=i&&(c.bind(n,9729,s,t),v.page={mosaicSize:[i[0],i[1]]},S.pageTexture={texture:c.getTexture(s),unit:t},r.submitDrawMeshUntyped(n,o,this._mesh,{stencilRef:e.stencilRef,parts:[l++]}))}}else r.submitDrawMeshUntyped(n,o,this._mesh,{stencilRef:e.stencilRef});e.triangleCount+=s.lineIndexCount/3}}}export{n as VTLTechniqueLine};
