Copies a an array of "sources" (Video, Canvas, OffscreenCanvas, ImageBitmap, Array, TypedArray)
to a texture and then optionally generates mip levels
Note that if the source is a TypeArray, then it will try to upload mips levels, then layers.
So, imagine you have a 4x4x3 2d-array r8unorm texture. If you pass in 16 bytes (4x4) it will
set mip level 0 layer 0 (4x4). If you pass in 24 bytes it will set mip level 0 layer 0(4x4)
and mip level 1 layer 0 (2x2). If you pass in 25 bytes it will set mip level 0, 1, 2, layer 0
If you pass in 75 bytes it would do all layers, all mip levels.
Note that for 3d textures there are no "layers" from the POV of this function. There is mip level 0 (which is a cube)
and mip level 1 (which is a cube). So a '3d' 4x4x3 r8unorm texture, you're expected to provide 48 bytes for mip level 0
where as for '2d' 4x4x3 you're expected to provide 16 bytes for mip level 0 layer 0. If you want to provide data
to each layer separately then pass them in as an array
// fill layer 0, mips 0 copySourcesToTexture(device, tex_4x4x3_r8_2d, [data16Bytes]);
This also works for compressed textures, so you can load an entire compressed texture, all mips, all layers in one call.
See texture-utils-tests.js for examples.
If the source is an Array is it converted to a typed array that matches the format.
Copies a an array of "sources" (Video, Canvas, OffscreenCanvas, ImageBitmap, Array, TypedArray) to a texture and then optionally generates mip levels
Note that if the source is a
TypeArray
, then it will try to upload mips levels, then layers. So, imagine you have a 4x4x3 2d-array r8unorm texture. If you pass in 16 bytes (4x4) it will set mip level 0 layer 0 (4x4). If you pass in 24 bytes it will set mip level 0 layer 0(4x4) and mip level 1 layer 0 (2x2). If you pass in 25 bytes it will set mip level 0, 1, 2, layer 0 If you pass in 75 bytes it would do all layers, all mip levels.Note that for 3d textures there are no "layers" from the POV of this function. There is mip level 0 (which is a cube) and mip level 1 (which is a cube). So a '3d' 4x4x3 r8unorm texture, you're expected to provide 48 bytes for mip level 0 where as for '2d' 4x4x3 you're expected to provide 16 bytes for mip level 0 layer 0. If you want to provide data to each layer separately then pass them in as an array
This also works for compressed textures, so you can load an entire compressed texture, all mips, all layers in one call. See texture-utils-tests.js for examples.
If the source is an
Array
is it converted to a typed array that matches the format.Int8Array
Uint8Array
Int16Array
Uint16Array
Int32Array
Uint32Array
Float16Array
Float32Array
UInt32Array