@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 1.95 kB
JavaScript
import{isSome as e}from"../../../../../core/maybe.js";import{TEXTURE_BINDING_BITMAP as t}from"../definitions.js";import i from"../VertexStream.js";import s from"./WGLBrush.js";import{TextureSamplingMode as n,BlendFactor as r,CompareFunction as a}from"../../../../webgl/enums.js";const o={nearest:{defines:[],samplingMode:n.NEAREST,mips:!1},bilinear:{defines:[],samplingMode:n.LINEAR,mips:!1},bicubic:{defines:["bicubic"],samplingMode:n.LINEAR,mips:!1},trilinear:{defines:[],samplingMode:n.LINEAR_MIPMAP_LINEAR,mips:!0}},d=(e,t,i)=>{if("dynamic"===i.samplingMode){const{state:i}=e,s=t.resolution/t.pixelRatio/i.resolution,n=Math.round(e.pixelRatio)!==e.pixelRatio,r=s>1.05||s<.95;return i.rotation||r||n||t.isSourceScaled||t.rotation?o.bilinear:o.nearest}return o[i.samplingMode]};class m extends s{constructor(){super(...arguments),this._desc={vsPath:"raster/bitmap",fsPath:"raster/bitmap",attributes:new Map([["a_pos",0]])}}dispose(){this._quad&&this._quad.dispose()}prepareState({context:e}){e.setBlendingEnabled(!0),e.setColorMask(!0,!0,!0,!0),e.setStencilWriteMask(0),e.setStencilTestEnabled(!0)}draw(s,n){const{context:o,renderingOptions:m,painter:l,requestRender:c,allowDelayedRender:p}=s;if(!n.source||!n.isReady)return;const u=d(s,n,m),f=l.materialManager.getProgram(this._desc,u.defines);if(p&&e(c)&&!f.compiled)return void c();s.timeline.begin(this.name),"additive"===n.blendFunction?o.setBlendFunctionSeparate(r.ONE,r.ONE,r.ONE,r.ONE):o.setBlendFunctionSeparate(r.ONE,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA),o.setStencilFunction(a.EQUAL,n.stencilRef,255),this._quad||(this._quad=new i(o,[0,0,1,0,0,1,1,1]));const{coordScale:_,computedOpacity:E,transforms:M}=n;n.setSamplingProfile(u),n.bind(s.context,t),o.useProgram(f),f.setUniformMatrix3fv("u_dvsMat3",M.dvs),f.setUniform1i("u_texture",t),f.setUniform2fv("u_coordScale",_),f.setUniform1f("u_opacity",E),this._quad.draw(),s.timeline.end(this.name)}}export{m as default};