从 v4.4.0 开始,没有办法。twgl 只是助手,它并不能做所有事情,所以你总是可以手动完成。
function loadImage(url) {
return new Promise((resolve, reject) => {
const img = new Image();
img.onload = resolve;
img.onerror = reject;
img.src = url;
};
});
function updateSlice(gl, texture, slice, img, options);
const format = options.format || gl.RGBA;
const type = options.type || gl.UNSIGNED.BYTE;
const level = options.level || 0;
gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture);
gl.texSubImage3D(gl.TEXTURE_2D_ARRAY, level, 0, 0, slice, img.width, img.height, 1,
format, type, img);
gl.generateMipmap(gl.TEXTURE_2D_ARRAY);
}
function updateSliceFromImage(gl, texture, slice, url, options) {
loadImage(url)
.then((e) => {
updateSlice(gl, texture, slice, e.target, options);
});
}