define(["./when-229515d6","./RuntimeError-608565a6","./WebGLConstants-f63312fc","./createTaskProcessorWorker"],(function(_,R,t,A){"use strict";const e={UNSIGNED_BYTE:t.WebGLConstants.UNSIGNED_BYTE,UNSIGNED_SHORT:t.WebGLConstants.UNSIGNED_SHORT,UNSIGNED_INT:t.WebGLConstants.UNSIGNED_INT,FLOAT:t.WebGLConstants.FLOAT,HALF_FLOAT:t.WebGLConstants.HALF_FLOAT_OES,UNSIGNED_INT_24_8:t.WebGLConstants.UNSIGNED_INT_24_8,UNSIGNED_SHORT_4_4_4_4:t.WebGLConstants.UNSIGNED_SHORT_4_4_4_4,UNSIGNED_SHORT_5_5_5_1:t.WebGLConstants.UNSIGNED_SHORT_5_5_5_1,UNSIGNED_SHORT_5_6_5:t.WebGLConstants.UNSIGNED_SHORT_5_6_5,toWebGLConstant:function(_,R){switch(_){case e.UNSIGNED_BYTE:return t.WebGLConstants.UNSIGNED_BYTE;case e.UNSIGNED_SHORT:return t.WebGLConstants.UNSIGNED_SHORT;case e.UNSIGNED_INT:return t.WebGLConstants.UNSIGNED_INT;case e.FLOAT:return t.WebGLConstants.FLOAT;case e.HALF_FLOAT:return R.webgl2?t.WebGLConstants.HALF_FLOAT:t.WebGLConstants.HALF_FLOAT_OES;case e.UNSIGNED_INT_24_8:return t.WebGLConstants.UNSIGNED_INT_24_8;case e.UNSIGNED_SHORT_4_4_4_4:return t.WebGLConstants.UNSIGNED_SHORT_4_4_4_4;case e.UNSIGNED_SHORT_5_5_5_1:return t.WebGLConstants.UNSIGNED_SHORT_5_5_5_1;case e.UNSIGNED_SHORT_5_6_5:return e.UNSIGNED_SHORT_5_6_5}},isPacked:function(_){return _===e.UNSIGNED_INT_24_8||_===e.UNSIGNED_SHORT_4_4_4_4||_===e.UNSIGNED_SHORT_5_5_5_1||_===e.UNSIGNED_SHORT_5_6_5},sizeInBytes:function(_){switch(_){case e.UNSIGNED_BYTE:return 1;case e.UNSIGNED_SHORT:case e.UNSIGNED_SHORT_4_4_4_4:case e.UNSIGNED_SHORT_5_5_5_1:case e.UNSIGNED_SHORT_5_6_5:case e.HALF_FLOAT:return 2;case e.UNSIGNED_INT:case e.FLOAT:case e.UNSIGNED_INT_24_8:return 4}},validate:function(_){return _===e.UNSIGNED_BYTE||_===e.UNSIGNED_SHORT||_===e.UNSIGNED_INT||_===e.FLOAT||_===e.HALF_FLOAT||_===e.UNSIGNED_INT_24_8||_===e.UNSIGNED_SHORT_4_4_4_4||_===e.UNSIGNED_SHORT_5_5_5_1||_===e.UNSIGNED_SHORT_5_6_5}};var T=Object.freeze(e);const O={DEPTH_COMPONENT:t.WebGLConstants.DEPTH_COMPONENT,DEPTH_STENCIL:t.WebGLConstants.DEPTH_STENCIL,ALPHA:t.WebGLConstants.ALPHA,RGB:t.WebGLConstants.RGB,RGBA:t.WebGLConstants.RGBA,LUMINANCE:t.WebGLConstants.LUMINANCE,LUMINANCE_ALPHA:t.WebGLConstants.LUMINANCE_ALPHA,RGB_DXT1:t.WebGLConstants.COMPRESSED_RGB_S3TC_DXT1_EXT,RGBA_DXT1:t.WebGLConstants.COMPRESSED_RGBA_S3TC_DXT1_EXT,RGBA_DXT3:t.WebGLConstants.COMPRESSED_RGBA_S3TC_DXT3_EXT,RGBA_DXT5:t.WebGLConstants.COMPRESSED_RGBA_S3TC_DXT5_EXT,RGB_PVRTC_4BPPV1:t.WebGLConstants.COMPRESSED_RGB_PVRTC_4BPPV1_IMG,RGB_PVRTC_2BPPV1:t.WebGLConstants.COMPRESSED_RGB_PVRTC_2BPPV1_IMG,RGBA_PVRTC_4BPPV1:t.WebGLConstants.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,RGBA_PVRTC_2BPPV1:t.WebGLConstants.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG,RGBA_ASTC:t.WebGLConstants.COMPRESSED_RGBA_ASTC_4x4_WEBGL,RGB_ETC1:t.WebGLConstants.COMPRESSED_RGB_ETC1_WEBGL,RGB8_ETC2:t.WebGLConstants.COMPRESSED_RGB8_ETC2,RGBA8_ETC2_EAC:t.WebGLConstants.COMPRESSED_RGBA8_ETC2_EAC,RGBA_BC7:t.WebGLConstants.COMPRESSED_RGBA_BPTC_UNORM,componentsLength:function(_){switch(_){case O.RGB:return 3;case O.RGBA:return 4;case O.LUMINANCE_ALPHA:return 2;case O.ALPHA:case O.LUMINANCE:default:return 1}},validate:function(_){return _===O.DEPTH_COMPONENT||_===O.DEPTH_STENCIL||_===O.ALPHA||_===O.RGB||_===O.RGBA||_===O.LUMINANCE||_===O.LUMINANCE_ALPHA||_===O.RGB_DXT1||_===O.RGBA_DXT1||_===O.RGBA_DXT3||_===O.RGBA_DXT5||_===O.RGB_PVRTC_4BPPV1||_===O.RGB_PVRTC_2BPPV1||_===O.RGBA_PVRTC_4BPPV1||_===O.RGBA_PVRTC_2BPPV1||_===O.RGBA_ASTC||_===O.RGB_ETC1||_===O.RGB8_ETC2||_===O.RGBA8_ETC2_EAC||_===O.RGBA_BC7},isColorFormat:function(_){return _===O.ALPHA||_===O.RGB||_===O.RGBA||_===O.LUMINANCE||_===O.LUMINANCE_ALPHA},isDepthFormat:function(_){return _===O.DEPTH_COMPONENT||_===O.DEPTH_STENCIL},isCompressedFormat:function(_){return _===O.RGB_DXT1||_===O.RGBA_DXT1||_===O.RGBA_DXT3||_===O.RGBA_DXT5||_===O.RGB_PVRTC_4BPPV1||_===O.RGB_PVRTC_2BPPV1||_===O.RGBA_PVRTC_4BPPV1||_===O.RGBA_PVRTC_2BPPV1||_===O.RGBA_ASTC||_===O.RGB_ETC1||_===O.RGB8_ETC2||_===O.RGBA8_ETC2_EAC||_===O.RGBA_BC7},isDXTFormat:function(_){return _===O.RGB_DXT1||_===O.RGBA_DXT1||_===O.RGBA_DXT3||_===O.RGBA_DXT5},isPVRTCFormat:function(_){return _===O.RGB_PVRTC_4BPPV1||_===O.RGB_PVRTC_2BPPV1||_===O.RGBA_PVRTC_4BPPV1||_===O.RGBA_PVRTC_2BPPV1},isASTCFormat:function(_){return _===O.RGBA_ASTC},isETC1Format:function(_){return _===O.RGB_ETC1},isETC2Format:function(_){return _===O.RGB8_ETC2||_===O.RGBA8_ETC2_EAC},isBC7Format:function(_){return _===O.RGBA_BC7},compressedTextureSizeInBytes:function(_,R,t){switch(_){case O.RGB_DXT1:case O.RGBA_DXT1:case O.RGB_ETC1:case O.RGB8_ETC2:return Math.floor((R+3)/4)*Math.floor((t+3)/4)*8;case O.RGBA_DXT3:case O.RGBA_DXT5:case O.RGBA_ASTC:case O.RGBA8_ETC2_EAC:return Math.floor((R+3)/4)*Math.floor((t+3)/4)*16;case O.RGB_PVRTC_4BPPV1:case O.RGBA_PVRTC_4BPPV1:return Math.floor((Math.max(R,8)*Math.max(t,8)*4+7)/8);case O.RGB_PVRTC_2BPPV1:case O.RGBA_PVRTC_2BPPV1:return Math.floor((Math.max(R,16)*Math.max(t,8)*2+7)/8);case O.RGBA_BC7:return Math.ceil(R/4)*Math.ceil(t/4)*16;default:return 0}},textureSizeInBytes:function(_,R,t,A){let e=O.componentsLength(_);return T.isPacked(R)&&(e=1),e*T.sizeInBytes(R)*t*A},alignmentInBytes:function(_,R,t){const A=O.textureSizeInBytes(_,R,t,1)%4;return 0===A?4:2===A?2:1},createTypedArray:function(_,R,t,A){let e;const n=T.sizeInBytes(R);e=n===Uint8Array.BYTES_PER_ELEMENT?Uint8Array:n===Uint16Array.BYTES_PER_ELEMENT?Uint16Array:n===Float32Array.BYTES_PER_ELEMENT&&R===T.FLOAT?Float32Array:Uint32Array;return new e(O.componentsLength(_)*t*A)},flipY:function(_,R,t,A,e){if(1===e)return _;const T=O.createTypedArray(R,t,A,e),n=O.componentsLength(R),B=A*n;for(let R=0;R>O,C=R.pixelHeight>>O,K=M*C*n.componentsLength(A);for(let t=0;t0&&C>0&&K>0))throw G.close(),G.delete(),new R.RuntimeError("Invalid KTX2 file");let F,N;const r=A.dataFormatDescriptor[0],i=T.transcoder_texture_format;if(163===r.colorModel)if(e.etc)F=s?n.RGBA8_ETC2_EAC:n.RGB8_ETC2,N=s?i.cTFETC2_RGBA:i.cTFETC1_RGB;else if(e.etc1&&!s)F=n.RGB_ETC1,N=i.cTFETC1_RGB;else if(e.s3tc)F=s?n.RGBA_DXT5:n.RGB_DXT1,N=s?i.cTFBC3_RGBA:i.cTFBC1_RGB;else if(e.pvrtc)F=s?n.RGBA_PVRTC_4BPPV1:n.RGB_PVRTC_4BPPV1,N=s?i.cTFPVRTC1_4_RGBA:i.cTFPVRTC1_4_RGB;else if(e.astc)F=n.RGBA_ASTC,N=i.cTFASTC_4x4_RGBA;else{if(!e.bc7)throw new R.RuntimeError("No transcoding format target available for ETC1S compressed ktx2.");F=n.RGBA_BC7,N=i.cTFBC7_RGBA}else if(166===r.colorModel)if(e.astc)F=n.RGBA_ASTC,N=i.cTFASTC_4x4_RGBA;else if(e.bc7)F=n.RGBA_BC7,N=i.cTFBC7_RGBA;else if(e.s3tc)F=s?n.RGBA_DXT5:n.RGB_DXT1,N=s?i.cTFBC3_RGBA:i.cTFBC1_RGB;else if(e.etc)F=s?n.RGBA8_ETC2_EAC:n.RGB8_ETC2,N=s?i.cTFETC2_RGBA:i.cTFETC1_RGB;else if(e.etc1&&!s)F=n.RGB_ETC1,N=i.cTFETC1_RGB;else{if(!e.pvrtc)throw new R.RuntimeError("No transcoding format target available for UASTC compressed ktx2.");F=s?n.RGBA_PVRTC_4BPPV1:n.RGB_PVRTC_4BPPV1,N=s?i.cTFPVRTC1_4_RGBA:i.cTFPVRTC1_4_RGB}if(!G.startTranscoding())throw G.close(),G.delete(),new R.RuntimeError("startTranscoding() failed");for(let t=0;t>t,C=A.pixelHeight>>t;const T=G.getImageTranscodedSizeInBytes(t,0,0,N.value),n=new Uint8Array(T),K=G.transcodeImage(n,t,0,0,N.value,0,-1,-1);if(!_.defined(K))throw new R.RuntimeError("transcodeImage() failed.");O.push(n.buffer),e[U[0]]={internalFormat:F,width:M,height:C,levelBuffer:n}}G.close(),G.delete()}(e,M,O,E,A,K),K}function P(_){E=_,E.initializeBasis(),self.onmessage=A(L),self.postMessage(!0)}return function(R){const t=R.data.webAssemblyConfig;if(_.defined(t))return require([t.modulePath],(function(R){if(!_.defined(t.wasmBinaryFile))return R().then((function(_){P(_)}));_.defined(R)||(R=self.MSC_TRANSCODER),R(t).then((function(_){P(_)}))}))}}));