/*
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/mathUtils","../../../../../core/maybe","../../../../../chunks/mat3f32","../../../../../chunks/vec4f32","../definitions","../enums","../number","./WGLBrush","../../../../webgl/BufferObject","../../../../webgl/enums","../../../../webgl/VertexArrayObject"],(function(e,t,r,o,i,a,n,s,c,u,l,_,f){"use strict";let d=function(e){function u(){var t;return(t=e.apply(this,arguments)||this)._color=a.fromValues(1,0,0,1),t._patternMatrix=i.create(),t._programOptions={id:!1,pattern:!1},t}t._inheritsLoose(u,e);var d=u.prototype;return d.dispose=function(){this._vao&&(this._vao.dispose(),this._vao=null)},d.drawMany=function(e,t){const{context:i,painter:a,styleLayerUID:u,requestRender:l}=e;this._loadWGLResources(e);const f=e.displayLevel,d=e.styleLayer,m=d.backgroundMaterial,p=a.vectorTilesMaterialManager,g=d.getPaintValue("background-color",f),h=d.getPaintValue("background-opacity",f),T=d.getPaintValue("background-pattern",f),v=void 0!==T,b=g[3]*h,y=1|window.devicePixelRatio,M=e.spriteMosaic;let x,L;const U=y>n.VTL_HIGH_RES_CUTOFF?2:1,I=e.drawPhase===s.WGLDrawPhase.HITTEST,P=this._programOptions;P.id=I,P.pattern=v;const S=p.getMaterialProgram(i,m,P);if(!o.isSome(l)||I||S.isCompiled){if(i.bindVAO(this._vao),i.useProgram(S),v){const e=M.getMosaicItemPosition(T,!0);if(o.isSome(e)){const{tl:t,br:r,page:a}=e;x=r[0]-t[0],L=r[1]-t[1];const s=M.getPageSize(a);o.isSome(s)&&(M.bind(i,_.TextureSamplingMode.LINEAR,a,n.VTL_TEXTURE_BINDING_UNIT_SPRITES),S.setUniform4f("u_tlbr",t[0],t[1],r[0],r[1]),S.setUniform2fv("u_mosaicSize",s),S.setUniform1i("u_texture",n.VTL_TEXTURE_BINDING_UNIT_SPRITES))}S.setUniform1f("u_opacity",h)}else this._color[0]=b*g[0],this._color[1]=b*g[1],this._color[2]=b*g[2],this._color[3]=b,S.setUniform4fv("u_color",this._color);if(S.setUniform1f("u_depth",d.z||0),I){const e=c.u32to4Xu8(u+1);S.setUniform4fv("u_id",e)}for(const e of t){if(S.setUniform1f("u_coord_range",e.rangeX),S.setUniformMatrix3fv("u_dvsMat3",e.transforms.dvs),v){const t=Math.max(2**(Math.round(f)-e.key.level),1),o=U*e.width*t,i=o/r.nextPowerOfTwo(x),a=o/r.nextPowerOfTwo(L);this._patternMatrix[0]=i,this._patternMatrix[4]=a,S.setUniformMatrix3fv("u_pattern_matrix",this._patternMatrix)}i.setStencilFunction(_.CompareFunction.EQUAL,e.stencilRef,255),i.drawArrays(_.PrimitiveType.TRIANGLE_STRIP,0,4)}}else l()},d._loadWGLResources=function(e){if(this._vao)return;const{context:t,styleLayer:r}=e,o=r.backgroundMaterial,i=new Int8Array([0,0,1,0,0,1,1,1]),a=l.BufferObject.createVertex(t,_.Usage.STATIC_DRAW,i),n=new f.VertexArrayObject(t,o.getAttributeLocations(),o.getLayoutInfo(),{geometry:a});this._vao=n},u}(u);e.WGLBrushVTLBackground=d,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
