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