UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 3.77 kB
import{isNone as e}from"../../core/maybe.js";import{Z as t}from"../../chunks/vec2f64.js";import{ContextType as n}from"./context-util.js";import{PixelType as a,TextureType as r,PixelFormat as i,SizedPixelFormat as o,TextureSamplingMode as s,TextureWrapMode as u,UniformType as f}from"./enums.js";import{Texture as m}from"./Texture.js";function c(e,t,f="nearest",c=!1){const l=!(c&&"u8"===t.pixelType),_=l?a.FLOAT:a.UNSIGNED_BYTE,p=null==t.pixels||0===t.pixels.length?null:l?t.getAsRGBAFloat():t.getAsRGBA(),g=e.capabilities.textureFloat?.textureFloatLinear,T={width:t.width,height:t.height,target:r.TEXTURE_2D,pixelFormat:i.RGBA,internalFormat:e.type===n.WEBGL2&&l?o.RGBA32F:i.RGBA,samplingMode:!g||"bilinear"!==f&&"cubic"!==f?s.NEAREST:s.LINEAR,dataType:_,wrapMode:u.CLAMP_TO_EDGE,flipped:!1};return new m(e,T,p)}function l(e,t){const{spacing:f,offsets:c,coefficients:l,size:[_,p]}=t,g=f[0]>1,T={width:g?4*_:_,height:p,target:r.TEXTURE_2D,pixelFormat:i.RGBA,internalFormat:e.type===n.WEBGL2?o.RGBA32F:i.RGBA,dataType:a.FLOAT,samplingMode:s.NEAREST,wrapMode:u.CLAMP_TO_EDGE,flipped:!1},E=new Float32Array(g?_*p*16:2*c.length);if(g&&null!=l)for(let n=0,a=0;n<l.length;n++)E[a++]=l[n],n%3==2&&(E[a++]=1);else for(let n=0;n<p;n++)for(let e=0;e<_;e++){const t=4*(n*_+e),a=2*(e*p+n);E[t]=c[a],E[t+1]=c[a+1],E[t+3]=-1===c[a]?0:1}return new m(e,T,E)}function _(e,t){const n={width:t.length/4,height:1,target:r.TEXTURE_2D,pixelFormat:i.RGBA,internalFormat:i.RGBA,dataType:a.UNSIGNED_BYTE,samplingMode:s.NEAREST,wrapMode:u.CLAMP_TO_EDGE,flipped:!1};return new m(e,n,t)}function p(e,n,a,r=1,i=!0){return{u_flipY:i,u_applyTransform:!!e,u_opacity:r,u_transformSpacing:e?e.spacing:t,u_transformGridSize:e?e.size:t,u_targetImageSize:n,u_srcImageSize:a}}function g(e,t){return{u_colormapOffset:t||0,u_colormapMaxIndex:e?e.length/4-1:0}}function T(e,t){return{u_scale:e,u_offset:t}}function E(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 A(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 h(t,n){const a=t.gl,r=n.glName,i=new Map;if(e(r))return i;const o=a.getProgramParameter(r,a.ACTIVE_UNIFORMS);let s;for(let e=0;e<o;e++)s=a.getActiveUniform(r,e),s&&i.set(s.name,{location:a.getUniformLocation(r,s.name),info:s});return i}function O(e,t,n){Object.keys(n).forEach((a=>{const r=t.get(a)||t.get(a+"[0]");r&&x(e,a,n[a],r)}))}function d(e,t,n,a){n.length===a.length&&(a.some((e=>null==e))||n.some((e=>null==e))||n.forEach(((n,r)=>{t.setUniform1i(n,r),e.bindTexture(a[r],r)})))}function x(e,t,n,a){if(null===a||null==n)return!1;const{info:r}=a;switch(r.type){case f.FLOAT:r.size>1?e.setUniform1fv(t,n):e.setUniform1f(t,n);break;case f.FLOAT_VEC2:e.setUniform2fv(t,n);break;case f.FLOAT_VEC3:e.setUniform3fv(t,n);break;case f.FLOAT_VEC4:e.setUniform4fv(t,n);break;case f.FLOAT_MAT3:e.setUniformMatrix3fv(t,n);break;case f.FLOAT_MAT4:e.setUniformMatrix4fv(t,n);break;case f.INT:r.size>1?e.setUniform1iv(t,n):e.setUniform1i(t,n);break;case f.BOOL:e.setUniform1i(t,n?1:0);break;case f.INT_VEC2:case f.BOOL_VEC2:e.setUniform2iv(t,n);break;case f.INT_VEC3:case f.BOOL_VEC3:e.setUniform3iv(t,n);break;case f.INT_VEC4:case f.BOOL_VEC4:e.setUniform4iv(t,n);break;default:return!1}return!0}export{_ as createColormapTexture,c as createRasterTexture,l as createTransformTexture,T as getBasicGridUniforms,g as getColormapUniforms,p as getCommonUniforms,A as getShadedReliefUniforms,E as getStretchUniforms,h as getUniformLocationInfos,d as setTextures,O as setUniforms};