createTextureWithData

import { createTextureWithData } from "jsr:@ende/webgpu";

function

function createTextureWithData(device: GPUDevice, descriptor: GPUTextureDescriptor, data: Uint8Array_): GPUTexture

Create a GPUTexture with data.

device: GPUDevice

The device to create the texture with.

descriptor: GPUTextureDescriptor

The texture descriptor to create the texture with.

data: Uint8Array_

The data to write to the texture.

Returns

The newly created texture.

Example: Usage

import { createTextureWithData } from "@ende/webgpu/texture-with-data";

const adapter = await navigator.gpu.requestAdapter();
const device = await adapter?.requestDevice()!;

createTextureWithData(device, {
  format: "bgra8unorm-srgb",
  size: {
    width: 3,
    height: 2,
  },
  usage: GPUTextureUsage.COPY_SRC,
}, new Uint8Array([1, 1, 1, 1, 1, 1, 1]));

Source