GPUTexture: label property

Khả dụng hạn chế

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.

Thuộc tính label của giao diện GPUTexture cung cấp một 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.

Có thể đặt giá trị này bằng cách cung cấp thuộc tính label trong đối tượng descriptor truyền vào lời gọi GPUDevice.createTexture() ban đầu, hoặc bạn có thể lấy và đặt trực tiếp trên đối tượng GPUTexture.

Giá trị

Một chuỗi. Nếu chưa được đặt như mô tả ở trên, giá trị sẽ là chuỗi rỗng.

Ví dụ

Đặt và lấy nhãn qua GPUTexture.label:

js
// …

const depthTexture = device.createTexture({
  size: [canvas.width, canvas.height],
  format: "depth24plus",
  usage: GPUTextureUsage.RENDER_ATTACHMENT,
});

depthTexture.label = "my_texture";

console.log(depthTexture.label); // "my_texture"

Đặt nhãn qua lời gọi GPUDevice.createTexture() ban đầu, rồi lấy qua GPUTexture.label:

js
// …

const depthTexture = device.createTexture({
  size: [canvas.width, canvas.height],
  format: "depth24plus",
  usage: GPUTextureUsage.RENDER_ATTACHMENT,
  label: "my_texture",
});

console.log(depthTexture.label); // "my_texture"

Thông số kỹ thuật

Thông số kỹ thuật
WebGPU
# dom-gpuobjectbase-label

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

Xem thêm