UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 2.66 kB
import{nextPowerOfTwo as t}from"../../../../../core/mathUtils.js";import{isSome as r}from"../../../../../core/maybe.js";import{c as e}from"../../../../../chunks/mat3f32.js";import{f as o}from"../../../../../chunks/vec4f32.js";import{VTL_TEXTURE_BINDING_UNIT_SPRITES as i,VTL_HIGH_RES_CUTOFF as s}from"../definitions.js";import{WGLDrawPhase as a}from"../enums.js";import{u32to4Xu8 as n}from"../number.js";import c from"./WGLBrush.js";import{BufferObject as m}from"../../../../webgl/BufferObject.js";import{TextureSamplingMode as f,CompareFunction as l,PrimitiveType as u,Usage as p}from"../../../../webgl/enums.js";import{VertexArrayObject as _}from"../../../../webgl/VertexArrayObject.js";class d extends c{constructor(){super(...arguments),this._color=o(1,0,0,1),this._patternMatrix=e(),this._programOptions={id:!1,pattern:!1}}dispose(){this._vao&&(this._vao.dispose(),this._vao=null)}drawMany(e,o){const{context:c,painter:m,styleLayerUID:p,requestRender:_,allowDelayedRender:d}=e;this._loadWGLResources(e);const h=e.displayLevel,g=e.styleLayer,v=g.backgroundMaterial,y=m.vectorTilesMaterialManager,b=g.getPaintValue("background-color",h),x=g.getPaintValue("background-opacity",h),M=g.getPaintValue("background-pattern",h),j=void 0!==M,U=b[3]*x,w=1|window.devicePixelRatio,L=e.spriteMosaic;let A,P;const I=w>s?2:1,R=e.drawPhase===a.HITTEST,k=this._programOptions;k.id=R,k.pattern=j;const T=y.getMaterialProgram(c,v,k);if(d&&r(_)&&!T.compiled)_();else{if(c.bindVAO(this._vao),c.useProgram(T),j){const t=L.getMosaicItemPosition(M,!0);if(r(t)){const{tl:e,br:o,page:s}=t;A=o[0]-e[0],P=o[1]-e[1];const a=L.getPageSize(s);r(a)&&(L.bind(c,f.LINEAR,s,i),T.setUniform4f("u_tlbr",e[0],e[1],o[0],o[1]),T.setUniform2fv("u_mosaicSize",a),T.setUniform1i("u_texture",i))}T.setUniform1f("u_opacity",x)}else this._color[0]=U*b[0],this._color[1]=U*b[1],this._color[2]=U*b[2],this._color[3]=U,T.setUniform4fv("u_color",this._color);if(T.setUniform1f("u_depth",g.z||0),R){const t=n(p+1);T.setUniform4fv("u_id",t)}for(const r of o){if(T.setUniform1f("u_coord_range",r.rangeX),T.setUniformMatrix3fv("u_dvsMat3",r.transforms.dvs),j){const e=Math.max(2**(Math.round(h)-r.key.level),1),o=I*r.width*e,i=o/t(A),s=o/t(P);this._patternMatrix[0]=i,this._patternMatrix[4]=s,T.setUniformMatrix3fv("u_pattern_matrix",this._patternMatrix)}c.setStencilFunction(l.EQUAL,0,255),c.drawArrays(u.TRIANGLE_STRIP,0,4)}}}_loadWGLResources(t){if(this._vao)return;const{context:r,styleLayer:e}=t,o=e.backgroundMaterial,i=new Int8Array([0,0,1,0,0,1,1,1]),s=m.createVertex(r,p.STATIC_DRAW,i),a=new _(r,o.getAttributeLocations(),o.getLayoutInfo(),{geometry:s});this._vao=a}}export{d as WGLBrushVTLBackground};