GPUTexture

class

class GPUTexture implements GPUObjectBase

Represents 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: string

width

readonly width: number

height

readonly height: number

depthOrArrayLayers

readonly depthOrArrayLayers: number

mipLevelCount

readonly mipLevelCount: number

sampleCount

readonly sampleCount: number

dimension

readonly dimension: GPUTextureDimension

format

readonly format: GPUTextureFormat

usage

readonly usage: GPUFlagsConstant

Methods

createView

createView(descriptor?: GPUTextureViewDescriptor): GPUTextureView

destroy

destroy(): undefined