/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{disposeMaybe as e}from"../../../../../../../core/maybe.js";import{simplePipelineState as t}from"../../utils.js";import{Technique as r}from"../Technique.js";import{FilterEffectShader as s}from"../shaders/ColorizeShader.js";import i from"../../../../../../webgl/Texture.js";import{TextureDescriptor as o}from"../../../../../../webgl/TextureDescriptor.js";class l extends r{constructor(){super(...arguments),this.type=9,this._layerFBOTexture=null,this._size=[0,0],this.shaders={filterEffect:new s}}shutdown(){super.shutdown(),this._layerFBOTexture=e(this._layerFBOTexture)}render(e,r){const{width:s,height:i}=r.layerFBO;this._createOrResizeResources(e,s,i);const{context:o,painter:l}=e,n=r.effect.colorMatrix,a=this._layerFBOTexture;o.bindFramebuffer(r.layerFBO),r.layerFBO.copyToTexture(0,0,s,i,0,0,a);const u={color:{write:[!0,!0,!0,!0],blendMode:"none"},depth:!1,stencil:!1};l.setPipelineState(u);const c={coefficients:n};l.submitDrawMesh(o,{shader:this.shaders.filterEffect,uniforms:{filterEffectConfig:c},textures:{colorTexture:{texture:a,unit:2}},defines:null,optionalAttributes:null,useComputeBuffer:!1},l.quadMesh),l.setPipelineState({...t,stencil:{test:{mask:255,compare:514,op:{fail:7680,zFail:7680,zPass:7680}},write:!1}})}_createOrResizeResources(e,t,r){const{context:s}=e;if(!this._layerFBOTexture||this._size[0]!==t||this._size[1]!==r)if(this._size[0]=t,this._size[1]=r,this._layerFBOTexture)this._layerFBOTexture.resize(t,r);else{const e=new o(t,r);e.internalFormat=6408,e.wrapMode=33071,this._layerFBOTexture=new i(s,e)}}}export{l as ColorizeTechnique};
