@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.57 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import t from"../../core/Error.js";import e from"../../core/Logger.js";import{PixelType as n,PixelFormat as r,SizedPixelFormat as i,SizedDepthStencilFormat as o,SizedDepthFormat as a,UnsizedDepthFormat as u,TextureType as l,TextureSamplingMode as c,CompressedTextureFormat as s}from"./enums.js";const h=()=>e.getLogger("esri/views/webgl/textureUtils");function m(t){const{width:e,height:n,depth:r}=t;(null!=e&&e<0||null!=n&&n<0||null!=r&&r<0)&&h().error("Negative dimension parameters are not allowed!");const{internalFormat:i}=t;if(i&&(f(i)||E(i))){const{linearFilterDepth:e,compareEnabled:n,samplingMode:r,hasMipmap:i}=t;i&&h().error("Depth textures cannot have mipmaps"),e?r!==c.LINEAR&&r!==c.NEAREST&&h().error("Depth textures cannot sample mipmaps"):(r!==c.NEAREST&&h().error("Depth textures without filtering must use NEAREST filtering"),n&&h().error("Depth textures without filtering cannot use compare function"))}}function p(t){return t in i}function f(t){return t in a}function E(t){return t in o}function d(t){return null!=t&&t in s}function T(t){return null!=t&&"type"in t&&"compressed"===t.type}function g(t){return d(t.descriptor.internalFormat)}function R(t){return null!=t&&"byteLength"in t}function w(t){return null!=t&&!T(t)&&!R(t)}function D(t){return t===l.TEXTURE_3D||t===l.TEXTURE_2D_ARRAY}function F(t,e,n,r=1){let i=Math.max(e,n);return t===l.TEXTURE_3D&&(i=Math.max(i,r)),Math.floor(Math.log2(i))+1}function N(e){if(null!=e.internalFormat)return e.internalFormat;switch(e.dataType){case n.FLOAT:switch(e.pixelFormat){case r.RGBA:return i.RGBA32F;case r.RGB:return i.RGB32F;default:throw new t("texture:unknown-format","Unable to derive format")}case n.UNSIGNED_BYTE:switch(e.pixelFormat){case r.RGBA:return i.RGBA8;case r.RGB:return i.RGB8}}const{pixelFormat:l}=e;return e.internalFormat=l===u.DEPTH_STENCIL?o.DEPTH24_STENCIL8:l===u.DEPTH_COMPONENT?a.DEPTH_COMPONENT24:l,e.internalFormat}function x(t){let e="width"in t?t.width:t.codedWidth,n="height"in t?t.height:t.codedHeight;const r=1;return t instanceof HTMLVideoElement&&(e=t.videoWidth,n=t.videoHeight),{width:e,height:n,depth:r}}export{F as calcMipmapLevels,N as deriveInternalFormat,x as getDimensions,D as is3DTarget,R as isArrayBufferView,T as isCompressedData,d as isCompressedFormat,g as isCompressedTexture,f as isSizedDepthFormat,E as isSizedDepthStencilFormat,p as isSizedPixelFormat,w as isTexImageSource,m as validateTexture};