GPUTexture
class
class GPUTexture implements GPUObjectBaseRepresents a texture (image) in GPU memory.
Example
// Create a texture to render to
const texture = device.createTexture({
label: "Output Texture",
size: { width: 640, height: 480 },
format: "rgba8unorm",
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING,
});
// Get a view of the texture (needed for most operations)
const textureView = texture.createView();
// When the texture is no longer needed
texture.destroy();
// Example: Creating a depth texture
const depthTexture = device.createTexture({
size: { width: 640, height: 480 },
format: "depth24plus",
usage: GPUTextureUsage.RENDER_ATTACHMENT,
});
Properties
label
label: stringwidth
readonly width: numberheight
readonly height: numberdepthOrArrayLayers
readonly depthOrArrayLayers: numbermipLevelCount
readonly mipLevelCount: numbersampleCount
readonly sampleCount: numberdimension
readonly dimension: GPUTextureDimensionformat
readonly format: GPUTextureFormatusage
readonly usage: GPUFlagsConstantMethods
createView
createView(descriptor?: GPUTextureViewDescriptor): GPUTextureViewdestroy
destroy(): undefined