/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../../chunks/_rollupPluginBabelHelpers","../../../../../core/maybe","../../vectorTiles/style/StyleDefinition","../definitions","../enums","../number","./WGLBrush","../../../../webgl/enums"],(function(e,t,i,n,a,r,o,s,l){"use strict";let u=function(e){function s(){var t;return(t=e.apply(this,arguments)||this)._programOptions={id:!1,pattern:!1,sdf:!1},t}t._inheritsLoose(s,e);var u=s.prototype;return u.dispose=function(){},u.drawMany=function(e,t){const{context:s,displayLevel:u,state:f,drawPhase:c,painter:T,pixelRatio:d,spriteMosaic:p,styleLayerUID:m,requestRender:_}=e;if(!t.some((e=>{var t,i;return null!=(t=null==(i=e.layerData.get(m))?void 0:i.lineIndexCount)&&t})))return;const y=e.styleLayer,I=y.lineMaterial,E=T.vectorTilesMaterialManager,g=y.getPaintValue("line-translate",u),S=y.getPaintValue("line-translate-anchor",u),v=y.getPaintProperty("line-pattern"),U=void 0!==v,N=U&&v.isDataDriven;let P,M;if(U&&!N){const e=v.getValue(u);P=p.getMosaicItemPosition(e)}let L=!1;if(!U){const e=y.getPaintProperty("line-dasharray");if(M=void 0!==e,L=M&&e.isDataDriven,M&&!L){const t=e.getValue(u),i=y.getDashKey(t,y.getLayoutValue("line-cap",u));P=p.getMosaicItemPosition(i)}}const D=1/d,R=c===r.WGLDrawPhase.HITTEST,x=this._programOptions;x.id=R,x.pattern=U,x.sdf=M;const V=E.getMaterialProgram(s,I,x);if(i.isSome(_)&&!R&&!V.isCompiled)return void _();if(s.useProgram(V),V.setUniformMatrix3fv("u_displayViewMat3",f.displayViewMat3),V.setUniformMatrix3fv("u_displayMat3",S===n.TranslateAnchor.VIEWPORT?f.displayMat3:f.displayViewMat3),V.setUniform2fv("u_lineTranslation",g),V.setUniform1f("u_depth",y.z),V.setUniform1f("u_antialiasing",D),R){const e=o.u32to4Xu8(m+1);V.setUniform4fv("u_id",e)}if(P&&i.isSome(P)){const{page:e}=P,t=p.getPageSize(e);i.isSome(t)&&(p.bind(s,l.TextureSamplingMode.LINEAR,e,a.VTL_TEXTURE_BINDING_UNIT_SPRITES),V.setUniform2fv("u_mosaicSize",t),V.setUniform1i("u_texture",a.VTL_TEXTURE_BINDING_UNIT_SPRITES))}let h=-1;for(const n of t){if(!n.layerData.has(m))continue;n.key.level!==h&&(h=n.key.level,I.setDataUniforms(V,u,y,h,p));const e=2**(u-h)/d;V.setUniform1f("u_zoomFactor",e);const t=n.layerData.get(m);if(!t.lineIndexCount)continue;t.prepareForRendering(s);const r=t.lineVertexArrayObject;if(!i.isNone(r)){if(s.bindVAO(r),V.setUniformMatrix3fv("u_dvsMat3",n.transforms.dvs),s.setStencilFunction(l.CompareFunction.EQUAL,n.stencilRef,255),N||L){const e=t.patternMap;if(!e)continue;for(const[t,n]of e){const e=p.getPageSize(t);i.isSome(e)&&(p.bind(s,l.TextureSamplingMode.LINEAR,t,a.VTL_TEXTURE_BINDING_UNIT_SPRITES),V.setUniform2fv("u_mosaicSize",e),V.setUniform1i("u_texture",a.VTL_TEXTURE_BINDING_UNIT_SPRITES),s.drawElements(l.PrimitiveType.TRIANGLES,n[1],l.DataType.UNSIGNED_INT,Uint32Array.BYTES_PER_ELEMENT*n[0]))}}else s.drawElements(l.PrimitiveType.TRIANGLES,t.lineIndexCount,l.DataType.UNSIGNED_INT,Uint32Array.BYTES_PER_ELEMENT*t.lineIndexStart);n.triangleCount+=t.lineIndexCount/3}}},s}(s);e.WGLBrushVTLLine=u,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
