Skip to main content
Home

@std/webgpu@0.224.8
Built and signed on GitHub Actions

UNSTABLE: Utilities for working with the Web GPU API

This package works with Deno, BrowsersIt is unknown whether this package works with Bun
This package works with Deno
It is unknown whether this package works with Bun
This package works with Browsers
JSR Score
100%
Published
3 months ago (0.224.8)
function createCapture
createCapture(
device: GPUDevice,
width: number,
height: number,
): CreateCapture

Creates a texture and buffer to use as a capture.

Examples

Usage

import { createCapture } from "@std/webgpu/create-capture";
import { getRowPadding } from "@std/webgpu/row-padding";

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

const dimensions = {
  width: 200,
  height: 200,
};

const { texture, outputBuffer } = createCapture(device, dimensions.width, dimensions.height);

const encoder = device.createCommandEncoder();
encoder.beginRenderPass({
  colorAttachments: [
    {
      view: texture.createView(),
      storeOp: "store",
      loadOp: "clear",
      clearValue: [1, 0, 0, 1],
    },
  ],
}).end();

const { padded } = getRowPadding(dimensions.width);

encoder.copyTextureToBuffer(
  {
    texture,
  },
  {
    buffer: outputBuffer,
    bytesPerRow: padded,
  },
  dimensions,
);

device.queue.submit([encoder.finish()]);

// outputBuffer contains the raw image data, can then be used
// to save as png or other formats.

Parameters

device: GPUDevice

The device to use for creating the capture.

width: number

The width of the capture texture.

height: number

The height of the capture texture.

Return Type

The texture to render to and buffer to read from.

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/webgpu

Import symbol

import { createCapture } from "@std/webgpu/create-capture";
or

Import directly with a jsr specifier

import { createCapture } from "jsr:@std/webgpu/create-capture";

Add Package

bunx jsr add @std/webgpu

Import symbol

import { createCapture } from "@std/webgpu/create-capture";