Skip to main content

Resource

Resource is the abstract base class for GPU objects created by a Device. It standardizes common fields such as identifiers and backend handles that are shared across buffers, textures, passes, and similar GPU resources.

Types

ResourceProps

ResourceProps define the shared configuration for all resources. These fields are inherited by every resource-specific props type.

PropertyTypeDefaultDescription
id?stringautogeneratedOptional human-readable identifier. When omitted, a unique identifier is generated.
handle?unknownundefinedExisting backend handle to wrap instead of creating a new one.
userData?Record<string, unknown>undefinedApplication data stored on the resource instance.

Members

  • id: string – Debug-friendly identifier assigned at creation.
  • device: Device – Device that owns the resource.
  • handle: unknown – Backend object handle (WebGL object or WebGPU handle).
  • props: ResourceProps – Initialization properties, normalized with defaults.
  • userData: Record<string, unknown> – Application-defined metadata for the resource.

Methods

  • destroy() – Releases GPU memory and attached resources.
  • delete() – Deprecated alias for destroy().
  • attachResource(resource) / detachResource(resource) – Manage owned child resources that are auto-destroyed with the parent.
  • destroyAttachedResource(resource) / destroyAttachedResources() – Destroy owned resources.

Resource subclasses may add lifecycle hooks or tracking to align with the underlying WebGPU or WebGL implementation.