/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import t from"../../core/Error.js";import e from"../../core/Logger.js";import{hasValue as r}from"../../core/object.js";import{PixelType as n,SizedPixelFormat as o,SizedDepthStencilFormat as i,SizedDepthFormat as u,CompressedTextureFormat as a,sizedPixelFormatValues as l}from"./enums.js";const c=()=>e.getLogger("esri/views/webgl/textureUtils");function s(t){const{width:e,height:r,depth:n}=t;(null!=e&&e<0||null!=r&&r<0||null!=n&&n<0)&&c().error("Negative dimension parameters are not allowed!");const{internalFormat:o}=t;if(o&&(p(o)||f(o))){const{linearFilterDepth:e,compareEnabled:r,samplingMode:n,hasMipmap:o}=t;o&&c().error("Depth textures cannot have mipmaps"),e?9729!==n&&9728!==n&&c().error("Depth textures cannot sample mipmaps"):(9728!==n&&c().error("Depth textures without filtering must use NEAREST filtering"),r&&c().error("Depth textures without filtering cannot use compare function"))}}function h(t){return m(t)||p(t)||f(t)}function m(t){return l.includes(t)}function p(t){return r(u,t)}function f(t){return r(i,t)}function d(t){return null!=t&&r(a,t)}function g(t){return null!=t&&"type"in t&&"compressed"===t.type}function w(t){return null!=t&&"byteLength"in t}function x(t){return null!=t&&!g(t)&&!w(t)}function F(t){return 32879===t||35866===t}function E(t,e,r,n=1){let o=Math.max(e,r);return 32879===t&&(o=Math.max(o,n)),Math.floor(Math.log2(o))+1}function T(e){if(null!=e.internalFormat)return e.internalFormat;switch(e.dataType){case n.FLOAT:switch(e.pixelFormat){case 6408:return o.RGBA32F;case 6407:return o.RGB32F;default:throw new t("texture:unknown-format","Unable to derive format")}case n.UNSIGNED_BYTE:switch(e.pixelFormat){case 6408:return o.RGBA8;case 6407:return o.RGB8}}const{pixelFormat:r}=e;return e.internalFormat=34041===r?i.DEPTH24_STENCIL8:6402===r?u.DEPTH_COMPONENT24:r,e.internalFormat}function D(t){let e="width"in t?t.width:t.codedWidth,r="height"in t?t.height:t.codedHeight;const n=1;return t instanceof HTMLVideoElement&&(e=t.videoWidth,r=t.videoHeight),{width:e,height:r,depth:n}}export{E as calcMipmapLevels,T as deriveInternalFormat,D as getDimensions,F as is3DTarget,w as isArrayBufferView,g as isCompressedData,d as isCompressedFormat,m as isSizedColorFormat,p as isSizedDepthFormat,f as isSizedDepthStencilFormat,h as isSizedPixelFormat,x as isTexImageSource,s as validateTexture};
