/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../../chunks/_rollupPluginBabelHelpers","../../../../core/maybe","./RasterBitmap","../webgl/VertexStream","../webgl/brushes/WGLBrush","../../../webgl/enums","../../../webgl/rasterUtils"],(function(e,t,r,s,n,i,o){"use strict";let a=function(n){function a(){var e;return(e=n.apply(this,arguments)||this)._desc={lut:{vsPath:"raster/lut",fsPath:"raster/lut",attributes:new Map([["a_position",0],["a_texcoord",1]])},stretch:{vsPath:"raster/stretch",fsPath:"raster/stretch",attributes:new Map([["a_position",0],["a_texcoord",1]])},hillshade:{vsPath:"raster/hillshade",fsPath:"raster/hillshade",attributes:new Map([["a_position",0],["a_texcoord",1]])}},e._rendererUniformInfos=new Map,e}e._inheritsLoose(a,n);var c=a.prototype;return c.dispose=function(){this._quad&&this._quad.dispose()},c.prepareState=function({context:e},t){e.setBlendingEnabled(!0),e.setBlendFunctionSeparate(i.BlendFactor.ONE,i.BlendFactor.ONE_MINUS_SRC_ALPHA,i.BlendFactor.ONE,i.BlendFactor.ONE_MINUS_SRC_ALPHA),e.setColorMask(!0,!0,!0,!0),e.setStencilWriteMask(0),e.setStencilTestEnabled(!0),e.setStencilFunction(i.CompareFunction.EQUAL,t.stencilRef,255)},c.draw=function(e,t){var s;if(!r.hasSource(t)||t.suspended)return;const{timeline:n,context:i,painter:o,requestRender:a}=e;n.begin(this.name);const c=!(null!=(s=i.capabilities.textureFloat)&&s.textureFloatLinear);t.updateTexture(e);const l=this._getShaderVariations(t,c),u=o.materialManager.getProgram(this._desc[t.symbolizerParameters.type],l);this._drawWithProgram(i,u,t,a),n.end(this.name)},c._drawWithProgram=function(e,r,n,i,a=1,c=[0,0],l=!1){if(this._quad||(this._quad=new s(e,[0,0,1,0,0,1,1,1])),t.isSome(i)&&!r.isCompiled)return void i();const{symbolizerParameters:u,transformGrid:h,width:d,height:p,opacity:f}=n,m=u.type;e.useProgram(r);const _=this._getShaderVariations(n),g=this._getUniformInfos(m,e,r,_),{names:b,textures:S}=n.getTextures();o.setTextures(e,r,b,S);const U=o.getBasicGridUniforms(a,c),P=o.getCommonUniforms(h,[d,p],[n.source.width,n.source.height],f,l);if(o.setUniforms(r,g,{u_coordScale:n.coordScale,u_dvsMat3:n.transforms.dvs,...U,...P}),u.colormap){const{colormap:e,colormapOffset:t}=u,s=o.getColormapUniforms(e,t);o.setUniforms(r,g,s)}if("stretch"===u.type){const e=o.getStretchUniforms(u);o.setUniforms(r,g,e)}else if("hillshade"===u.type){const e=o.getShadedReliefUniforms(u);o.setUniforms(r,g,e)}this._quad.draw()},c._getUniformInfos=function(e,t,r,s){const n=s.length>0?e+"-"+s.join("-"):e;if(this._rendererUniformInfos.has(n))return this._rendererUniformInfos.get(n);const i=o.getUniformLocationInfos(t,r);return this._rendererUniformInfos.set(n,i),i},c._getShaderVariations=function(e,t=!1){const r=[],{interpolation:s}=e,{type:n,colormap:i}=e.symbolizerParameters;return"cubic"===s?r.push("bicubic"):"bilinear"===s&&"stretch"===n&&null!=i?(r.push("bilinear"),r.push("nnedge")):t&&"bilinear"===s&&r.push("bilinear"),e.isRendereredSource?r.push("noop"):i&&r.push("applyColormap"),e.transformGrid&&(r.push("applyProjection"),1===e.transformGrid.spacing[0]&&r.push("lookupProjection")),r},a}(n);return a}));
