files/en-us/web/api/gputexture/index.md
{{APIRef("WebGPU API")}}{{SecureContext_Header}}{{AvailableInWorkers}}
The GPUTexture interface of the {{domxref("WebGPU API", "WebGPU API", "", "nocode")}} 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 {{domxref("GPUDevice.createTexture()")}} method.
{{InheritanceDiagram}}
GPUTexture (pixels, or number of layers).GPUTexture subresource.GPUTexture. See the Texture formats section of the specification for all the possible values. Also see Tier 1 and Tier 2 texture formats.GPUTexture in pixels.GPUTexture.GPUTexture.GPUTexture.GPUTexture in pixels.GPUTexture.GPUTexture.In the WebGPU samples Textured Cube sample, a texture to use on the faces of a cube is created by:
GPUTexture using createTexture().// …
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}}
{{Compat}}