1答案
函数loadImage(url){ return new Promise((resolve,reject)=>{ const img=新图像(); img.onload=解析; img.onerror=拒绝; img.src=url; }; }); 函数updateSlice(gl、texture、slice、img、options); const format=options.format | | gl.RGBA; const type=options.type | | gl.UNSIGNED。 字节; 常量级别=options.level |0; gl.bindTexture(gl.TEXTURE_2D_ARRAY,纹理); gl.texSubImage3D(gl.TEXTURE_2D_ARRAY,级别,0,0,切片,img.width,img.height,1, 格式、类型、img); gl.生成位图(gl.TEXTURE_2D_ARRAY); } 函数updateSliceFromImage(gl、texture、slice、url、options){ 加载图像(url) 然后(e)=>{ updateSlice(gl,纹理,切片,e.target,选项); }); }