@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 2.17 kB
JavaScript
import{extends as e}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import{ADDRESS_CLAMP_TO_EDGE as t,ADDRESS_REPEAT as r,PIXELFORMAT_DXT1 as s,PIXELFORMAT_DXT3 as a,PIXELFORMAT_DXT5 as n,PIXELFORMAT_ETC1 as l,PIXELFORMAT_ETC2_RGB as i,PIXELFORMAT_ETC2_RGBA as o,PIXELFORMAT_PVRTC_4BPP_RGB_1 as p,PIXELFORMAT_PVRTC_2BPP_RGB_1 as m,PIXELFORMAT_PVRTC_4BPP_RGBA_1 as u,PIXELFORMAT_PVRTC_2BPP_RGBA_1 as f,PIXELFORMAT_RGB8 as c,PIXELFORMAT_RGBA8 as h,PIXELFORMAT_SRGB as d,PIXELFORMAT_SRGBA as b,PIXELFORMAT_111110F as g,PIXELFORMAT_RGB16F as x,PIXELFORMAT_RGBA16F as y}from"../../../platform/graphics/constants.js";import{Texture as v}from"../../../platform/graphics/texture.js";import{Asset as O}from"../../asset/asset.js";import{TextureParser as w}from"./texture.js";const A=[1481919403,3140563232,169478669],F={33776:s,33778:a,33779:n,36196:l,37492:i,37496:o,35840:p,35841:m,35842:u,35843:f,32849:c,32856:h,35905:d,35907:b,35898:g,34843:x,34842:y};class j extends w{constructor(e){super(),this.maxRetries=0}load(e,t,r){O.fetchArrayBuffer(e.load,t,r,this.maxRetries)}open(s,a,n,l={}){const i=this.parse(a);if(!i)return null;const o=new v(n,e({name:s,addressU:i.cubemap?t:r,addressV:i.cubemap?t:r,width:i.width,height:i.height,format:i.format,cubemap:i.cubemap,levels:i.levels},l));return o.upload(),o}parse(e){const t=new Uint32Array(e);if(A[0]!==t[0]||A[1]!==t[1]||A[2]!==t[2])return null;const r={endianness:t[3],glType:t[4],glTypeSize:t[5],glFormat:t[6],glInternalFormat:t[7],glBaseInternalFormat:t[8],pixelWidth:t[9],pixelHeight:t[10],pixelDepth:t[11],numberOfArrayElements:t[12],numberOfFaces:t[13],numberOfMipmapLevels:t[14],bytesOfKeyValueData:t[15]};if(r.pixelDepth>1)return null;if(0!==r.numberOfArrayElements)return null;const s=F[r.glInternalFormat];if(void 0===s)return null;let a=16+r.bytesOfKeyValueData/4;const n=r.numberOfFaces>1,l=[];for(let m=0;m<(r.numberOfMipmapLevels||1);m++){const r=t[a++];n&&l.push([]);const u=n?l[m]:l;for(let t=0;t<(n?6:1);++t)u.push((i=e,o=4*a,p=r,s===g?new Uint32Array(i,o,p/4):new Uint8Array(i,o,p))),a+=r+3>>2}var i,o,p;return{format:s,width:r.pixelWidth,height:r.pixelHeight,levels:l,cubemap:n}}}export{j as KtxParser};