webgpu-utils
    Preparing search index...

    Function copySourcesToTexture

    • 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]);

      // fill layer 0, mips 0, 1, 2
      copySourcesToTexture(device, tex_4x4x3_r8_2d, [data25Bytes]);

      // fill layer 0, mips 0, 1, 2, then layer 1, mips 0, 1, 2, then layer 2, mips 0, 1, 2
      copySourcesToTexture(device, tex_4x4x3_r8_2d, [data75Bytes]);

      // (same as previous) fill layer 0, mips 0, 1, 2, then layer 1, mips 0, 1, 2, then layer 2, mips 0, 1, 2
      copySourcesToTexture(device, tex_4x4x3_r8_2d, [data25Bytes, data25bytes, data25Bytes]);

      // fills layer 0, mips 0, layer 1, mips 0, layer 2, mips 0
      copySourcesToTexture(device, tex_4x4x3_r8_2d, [data16Bytes, data16bytes, 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.

      • ????8snorm ????8sint -> Int8Array
      • ????8unorm ????8uint -> Uint8Array
      • ????16snorm ???16sint -> Int16Array
      • ????16unorm ???16uint -> Uint16Array
      • ????32snorm ???32sint -> Int32Array
      • ????32unorm ???32uint -> Uint32Array
      • ????16Float -> Float16Array
      • ????32Float -> Float32Array
      • rgb10a2uint, rgb10a2unorm, rg11b10ufloat, rgb8e5ufloat -> UInt32Array

      Parameters

      Returns void