GPUTexture

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Note: This feature is available in Web Workers.

Giao diện GPUTexture thuộc WebGPU API đại diện cho một container dùng để lưu trữ các mảng dữ liệu 1D, 2D hoặc 3D, chẳng hạn như hình ảnh, để sử dụng trong các thao tác kết xuất GPU.

Một thực thể đối tượng GPUTexture được tạo bằng phương thức GPUDevice.createTexture().

Thuộc tính phiên bản

depthOrArrayLayers Read only

Một số đại diện cho chiều sâu hoặc số lớp của GPUTexture (pixel hoặc số lớp).

dimension Read only

Một giá trị liệt kê đại diện cho kích thước của tập hợp texel cho mỗi subresource của GPUTexture.

format Read only

Một giá trị liệt kê đại diện cho định dạng của GPUTexture. Xem phần Texture formats của thông số kỹ thuật để biết tất cả các giá trị có thể. Xem thêm Tier 1 and Tier 2 texture formats.

height Read only

Một số đại diện cho chiều cao của GPUTexture tính bằng pixel.

label

Một chuỗi cung cấp nhãn có thể dùng để nhận diện đối tượng, ví dụ trong thông báo GPUError hoặc cảnh báo console.

mipLevelCount Read only

Một số đại diện cho số lượng mip level của GPUTexture.

sampleCount Read only

Một số đại diện cho số mẫu (sample count) của GPUTexture.

usage Read only

Các bitwise flags đại diện cho các cách sử dụng được phép của GPUTexture.

width Read only

Một số đại diện cho chiều rộng của GPUTexture tính bằng pixel.

Phương thức phiên bản

createView()

Tạo một GPUTextureView đại diện cho một view cụ thể của GPUTexture.

destroy()

Hủy GPUTexture.

Ví dụ

Trong mẫu WebGPU Textured Cube sample, một kết cấu dùng cho các mặt của hình khối lập phương được tạo bằng cách:

js
// …
let cubeTexture;
{
  const img = document.createElement("img");

  img.src = new URL(
    "../../../assets/img/Di-3d.png",
    import.meta.url,
  ).toString();

  await img.decode();

  const imageBitmap = await createImageBitmap(img);

  cubeTexture = device.createTexture({
    size: [imageBitmap.width, imageBitmap.height, 1],
    format: "rgba8unorm",
    usage:
      GPUTextureUsage.TEXTURE_BINDING |
      GPUTextureUsage.COPY_DST |
      GPUTextureUsage.RENDER_ATTACHMENT,
  });

  device.queue.copyExternalImageToTexture(
    { source: imageBitmap },
    { texture: cubeTexture },
    [imageBitmap.width, imageBitmap.height],
  );
}
// …

Thông số kỹ thuật

Specification
WebGPU
# gputexture

Tương thích trình duyệt

Xem thêm