/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../chunks/vec2f64","./context-util","./enums","./FramebufferObject","./Texture"],(function(e,t,r,i,n,a){"use strict";function o(e,t,n="nearest",o=!1){var u;const m=!(o&&"u8"===t.pixelType),s=m?i.PixelType.FLOAT:i.PixelType.UNSIGNED_BYTE,f=null==t.pixels||0===t.pixels.length?null:m?t.getAsRGBAFloat():t.getAsRGBA(),T=null==(u=e.capabilities.textureFloat)?void 0:u.textureFloatLinear,l={width:t.width,height:t.height,target:i.TextureType.TEXTURE_2D,pixelFormat:i.PixelFormat.RGBA,internalFormat:e.type===r.ContextType.WEBGL2&&m?i.SizedPixelFormat.RGBA32F:i.PixelFormat.RGBA,samplingMode:!T||"bilinear"!==n&&"cubic"!==n?i.TextureSamplingMode.NEAREST:i.TextureSamplingMode.LINEAR,dataType:s,wrapMode:i.TextureWrapMode.CLAMP_TO_EDGE,flipped:!1};return new a.Texture(e,l,f)}function u(e,t,r,o){const u=o?i.PixelType.UNSIGNED_BYTE:i.PixelType.FLOAT,m={width:t,height:r,target:i.TextureType.TEXTURE_2D,pixelFormat:i.PixelFormat.RGBA,internalFormat:i.PixelFormat.RGBA,samplingMode:i.TextureSamplingMode.NEAREST,dataType:u,wrapMode:i.TextureWrapMode.CLAMP_TO_EDGE,flipped:!1},s=new a.Texture(e,m);return new n.FramebufferObject(e,{colorTarget:i.TargetType.TEXTURE,depthStencilTarget:i.DepthStencilTargetType.DEPTH_STENCIL_RENDER_BUFFER,width:t,height:r},s)}function m(e,t){const{spacing:n,offsets:o,coefficients:u,size:[m,s]}=t,f=n[0]>1,T={width:f?4*m:m,height:s,target:i.TextureType.TEXTURE_2D,pixelFormat:i.PixelFormat.RGBA,internalFormat:e.type===r.ContextType.WEBGL2?i.SizedPixelFormat.RGBA32F:i.PixelFormat.RGBA,dataType:i.PixelType.FLOAT,samplingMode:i.TextureSamplingMode.NEAREST,wrapMode:i.TextureWrapMode.CLAMP_TO_EDGE,flipped:!1},l=new Float32Array(f?m*s*16:2*o.length);if(f)for(let r=0,i=0;r<u.length;r++)l[i++]=u[r],r%3==2&&(l[i++]=1);else for(let r=0;r<s;r++)for(let e=0;e<m;e++){const t=4*(r*m+e),i=2*(e*s+r);l[t]=o[i],l[t+1]=o[i+1],l[t+3]=-1===o[i]?0:1}return new a.Texture(e,T,l)}function s(e,t){const r={width:t.length/4,height:1,target:i.TextureType.TEXTURE_2D,pixelFormat:i.PixelFormat.RGBA,internalFormat:i.PixelFormat.RGBA,dataType:i.PixelType.UNSIGNED_BYTE,samplingMode:i.TextureSamplingMode.NEAREST,wrapMode:i.TextureWrapMode.CLAMP_TO_EDGE,flipped:!1};return new a.Texture(e,r,t)}function f(e,r,i,n=1,a=!0){return{u_flipY:a,u_applyTransform:!!e,u_opacity:n,u_transformSpacing:e?e.spacing:t.ZEROS,u_transformGridSize:e?e.size:t.ZEROS,u_targetImageSize:r,u_srcImageSize:i}}function T(e,t){return{u_colormapOffset:t||0,u_colormapMaxIndex:e?e.length/4-1:0}}function l(e,t){return{u_scale:e,u_offset:t}}function p(e){return{u_bandCount:e.bandCount,u_minOutput:e.outMin,u_maxOutput:e.outMax,u_minCutOff:e.minCutOff,u_maxCutOff:e.maxCutOff,u_factor:e.factor,u_useGamma:e.useGamma,u_gamma:e.gamma,u_gammaCorrection:e.gammaCorrection}}function c(e){return{u_hillshadeType:e.hillshadeType,u_sinZcosAs:e.sinZcosAs,u_sinZsinAs:e.sinZsinAs,u_cosZs:e.cosZs,u_weights:e.weights,u_factor:e.factor,u_minValue:e.minValue,u_maxValue:e.maxValue}}function x(e,t){const r=e.gl,i=t.glName,n=r.getProgramParameter(i,r.ACTIVE_UNIFORMS),a=new Map;let o;for(let u=0;u<n;u++)o=r.getActiveUniform(i,u),o&&a.set(o.name,{location:r.getUniformLocation(i,o.name),info:o});return a}function g(e,t,r){Object.keys(r).forEach((i=>{const n=t.get(i)||t.get(i+"[0]");n&&E(e,i,r[i],n)}))}function _(e,t,r,i){r.length===i.length&&(i.some((e=>null==e))||r.some((e=>null==e))||r.forEach(((r,n)=>{t.setUniform1i(r,n),e.bindTexture(i[n],n)})))}function E(e,t,r,n){if(null===n||null==r)return!1;const{info:a}=n;switch(a.type){case i.UniformType.FLOAT:a.size>1?e.setUniform1fv(t,r):e.setUniform1f(t,r);break;case i.UniformType.FLOAT_VEC2:e.setUniform2fv(t,r);break;case i.UniformType.FLOAT_VEC3:e.setUniform3fv(t,r);break;case i.UniformType.FLOAT_VEC4:e.setUniform4fv(t,r);break;case i.UniformType.FLOAT_MAT3:e.setUniformMatrix3fv(t,r);break;case i.UniformType.FLOAT_MAT4:e.setUniformMatrix4fv(t,r);break;case i.UniformType.INT:a.size>1?e.setUniform1iv(t,r):e.setUniform1i(t,r);break;case i.UniformType.BOOL:e.setUniform1i(t,r?1:0);break;case i.UniformType.INT_VEC2:case i.UniformType.BOOL_VEC2:e.setUniform2iv(t,r);break;case i.UniformType.INT_VEC3:case i.UniformType.BOOL_VEC3:e.setUniform3iv(t,r);break;case i.UniformType.INT_VEC4:case i.UniformType.BOOL_VEC4:e.setUniform4iv(t,r);break;default:return!1}return!0}e.createColormapTexture=s,e.createFrameBuffer=u,e.createRasterTexture=o,e.createTransformTexture=m,e.getBasicGridUniforms=l,e.getColormapUniforms=T,e.getCommonUniforms=f,e.getShadedReliefUniforms=c,e.getStretchUniforms=p,e.getUniformLocationInfos=x,e.setTextures=_,e.setUniforms=g,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
