web api interface
GPUTexture
Secure contextAvailable in workers
The GPUTexture interface of the WebGPU API represents a container used to store 1D, 2D, or 3D arrays of data, such as images, to use in GPU rendering operations.
A GPUTexture object instance is created using the createTexture() method.
Instance properties
depthOrArrayLayersRead only- : A number representing the depth or layer count of the
GPUTexture(pixels, or number of layers).
- : A number representing the depth or layer count of the
dimensionRead only- : An enumerated value representing the dimension of the set of texels for each
GPUTexturesubresource.
- : An enumerated value representing the dimension of the set of texels for each
formatRead only- : An enumerated value representing the format of the
GPUTexture. See the Texture formats section of the specification for all the possible values. Also see Tier 1 and Tier 2 texture formats.
- : An enumerated value representing the format of the
heightRead only- : A number representing the height of the
GPUTexturein pixels.
- : A number representing the height of the
label- : A string providing a label that can be used to identify the object, for example in
GPUErrormessages or console warnings.
- : A string providing a label that can be used to identify the object, for example in
mipLevelCountRead only- : A number representing the number of mip levels of the
GPUTexture.
- : A number representing the number of mip levels of the
sampleCountRead only- : A number representing the sample count of the
GPUTexture.
- : A number representing the sample count of the
usageRead only- : The bitwise flags representing the allowed usages of the
GPUTexture.
- : The bitwise flags representing the allowed usages of the
widthRead only- : A number representing the width of the
GPUTexturein pixels.
- : A number representing the width of the
Instance methods
createView()- : Creates a
GPUTextureViewrepresenting a specific view of theGPUTexture.
- : Creates a
destroy()- : Destroys the
GPUTexture.
- : Destroys the
Examples
In the WebGPU samples Textured Cube sample, a texture to use on the faces of a cube is created by:
- Loading the image into an
HTMLImageElementand creating an image bitmap usingcreateImageBitmap(). - Creating a new
GPUTextureusingcreateTexture(). - Copying the image bitmap into the texture using
copyExternalImageToTexture().
// …
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],
);
}
// …
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.
See also
- The WebGPU API