/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{textureBindingBitmap as e}from"../../../definitions.js";import{Technique as i}from"../Technique.js";import{BitmapShader as t}from"../shaders/BitmapShader.js";const s={nearest:{samplingMode:9728,mips:!1},bilinear:{samplingMode:9729,mips:!1},bicubic:{samplingMode:9729,mips:!1},trilinear:{samplingMode:9987,mips:!0}},n=(e,i,t)=>{if("dynamic"===t.samplingMode){const{state:t}=e,n=i.resolution/i.pixelRatio/t.resolution,o=Math.round(e.pixelRatio)!==e.pixelRatio,r=n>1.05||n<.95;return t.rotation||r||o||i.isSourceScaled||i.rotation?s.bilinear:s.nearest}return s[t.samplingMode]};class o extends i{constructor(){super(...arguments),this.name="BrushBitmap",this.type=4,this.shaders={bitmap:new t}}render(i,t){const{context:o,renderingOptions:r,painter:a}=i;for(const p of t.bitmaps){const t=p.texture;if(!p.source||!p.isReady||null==t)continue;const c=n(i,p,r);i.timeline.begin(this.name),a.setPipelineState({depth:!1,stencil:{test:{mask:255,compare:514,op:{fail:7680,zFail:7680,zPass:7680}},write:!1},color:{write:[!0,!0,!0,!0],blendMode:"additive"===p.blendFunction?"additive":"composite"}}),p.setSamplingProfile(c);const{coordScale:m,computedOpacity:d,transforms:l}=p,u={dvsMat3:l.displayViewScreenMat3,coordScale:m,opacity:d};a.submitDrawMesh(o,{shader:this.shaders.bitmap,uniforms:{config:u},textures:{texture:{texture:t,unit:e}},defines:{bicubic:c===s.bicubic},optionalAttributes:null,useComputeBuffer:!1},a.quadMesh,p),i.timeline.end(this.name)}}}export{o as BitmapTechnique};
