/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../../../core/screenUtils","../../VertexStream","../../../../../webgl/enums","../../../../../webgl/FramebufferObject","../../../../../webgl/Texture"],(function(e,t,r,i,s,o){"use strict";const a=[1,0],l=[0,1];let n=function(){function e(){this._horizontalBlurFBO=null,this._verticalBlurFBO=null,this._size=[0,0],this._programDesc={blur:{vsPath:"post-processing/pp",fsPath:"post-processing/blur/gaussianBlur",attributes:new Map([["a_position",0]])},composite:{vsPath:"post-processing/pp",fsPath:"post-processing/drop-shadow/composite",attributes:new Map([["a_position",0]])},blit:{vsPath:"post-processing/pp",fsPath:"post-processing/blit",attributes:new Map([["a_position",0]])}}}var n=e.prototype;return n.dispose=function(){this._layerFBOTexture&&(this._layerFBOTexture.dispose(),this._layerFBOTexture=null),this._horizontalBlurFBO&&(this._horizontalBlurFBO.dispose(),this._horizontalBlurFBO=null),this._verticalBlurFBO&&(this._verticalBlurFBO.dispose(),this._verticalBlurFBO=null)},n.draw=function(e,s,o){const{context:n,state:u,painter:p}=e,{materialManager:h}=p,d=this._programDesc,T=s.width,c=s.height,_=[Math.round(T/2),Math.round(c/2)],{blurRadius:B,offsetX:f,offsetY:m,color:x}=o,g=[t.pt2px(f/2),t.pt2px(m/2)];this._createOrResizeResources(e,T,c,_);const F=this._horizontalBlurFBO,b=this._verticalBlurFBO;n.setStencilWriteMask(0),n.setStencilTestEnabled(!1),n.setDepthWriteEnabled(!1),n.setDepthTestEnabled(!1);const O=this._layerFBOTexture;s.copyToTexture(0,0,T,c,0,0,O),this._quad||(this._quad=new r(n,[-1,-1,1,-1,-1,1,1,1])),n.setViewport(0,0,_[0],_[1]);const E=this._quad;E.bind(),n.setBlendingEnabled(!1);const w=h.getProgram(d.blur,[{name:"radius",value:Math.ceil(B)}]);n.useProgram(w),n.bindFramebuffer(F),n.bindTexture(s.colorTexture,4),w.setUniform1i("u_colorTexture",4),w.setUniform2fv("u_texSize",_),w.setUniform2fv("u_direction",a),w.setUniform1f("u_sigma",B),E.draw(),n.bindFramebuffer(b),n.bindTexture(F.colorTexture,5),w.setUniform1i("u_colorTexture",5),w.setUniform2fv("u_direction",l),E.draw(),n.bindFramebuffer(s),n.setViewport(0,0,T,c);const M=h.getProgram(d.composite);n.useProgram(M),n.bindTexture(b.colorTexture,2),M.setUniform1i("u_blurTexture",2),n.bindTexture(O,3),M.setUniform1i("u_layerFBOTexture",3),M.setUniform4fv("u_shadowColor",[x[3]*(x[0]/255),x[3]*(x[1]/255),x[3]*(x[2]/255),x[3]]),M.setUniformMatrix3fv("u_displayViewMat3",u.displayMat3),M.setUniform2fv("u_shadowOffset",g),E.draw(),n.setBlendingEnabled(!0),n.setStencilTestEnabled(!0),n.setBlendFunction(i.BlendFactor.ONE,i.BlendFactor.ONE_MINUS_SRC_ALPHA),E.unbind()},n._createOrResizeResources=function(e,t,r,a){const{context:l}=e;this._horizontalBlurFBO&&this._size[0]===t&&this._size[1]===r||(this._size[0]=t,this._size[1]=r,this._horizontalBlurFBO?this._horizontalBlurFBO.resize(a[0],a[1]):this._horizontalBlurFBO=new s.FramebufferObject(l,{colorTarget:i.TargetType.TEXTURE,depthStencilTarget:i.DepthStencilTargetType.NONE,width:a[0],height:a[1]},{target:i.TextureType.TEXTURE_2D,pixelFormat:i.PixelFormat.RGBA,internalFormat:i.PixelFormat.RGBA,dataType:i.PixelType.UNSIGNED_BYTE,wrapMode:i.TextureWrapMode.CLAMP_TO_EDGE,samplingMode:i.TextureSamplingMode.LINEAR,flipped:!1,width:a[0],height:a[1]}),this._verticalBlurFBO?this._verticalBlurFBO.resize(a[0],a[1]):this._verticalBlurFBO=new s.FramebufferObject(l,{colorTarget:i.TargetType.TEXTURE,depthStencilTarget:i.DepthStencilTargetType.NONE,width:a[0],height:a[1]},{target:i.TextureType.TEXTURE_2D,pixelFormat:i.PixelFormat.RGBA,internalFormat:i.PixelFormat.RGBA,dataType:i.PixelType.UNSIGNED_BYTE,wrapMode:i.TextureWrapMode.CLAMP_TO_EDGE,samplingMode:i.TextureSamplingMode.LINEAR,flipped:!1,width:a[0],height:a[1]}),this._layerFBOTexture?this._layerFBOTexture.resize(t,r):this._layerFBOTexture=new o.Texture(l,{target:i.TextureType.TEXTURE_2D,pixelFormat:i.PixelFormat.RGBA,internalFormat:i.PixelFormat.RGBA,dataType:i.PixelType.UNSIGNED_BYTE,wrapMode:i.TextureWrapMode.CLAMP_TO_EDGE,samplingMode:i.TextureSamplingMode.LINEAR,flipped:!1,width:t,height:r}))},e}();e.DropShadow=n,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
