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.
| Property | Type | Default | Description |
|---|---|---|---|
id? | string | autogenerated | Optional human-readable identifier. When omitted, a unique identifier is generated. |
handle? | unknown | undefined | Existing backend handle to wrap instead of creating a new one. |
userData? | Record<string, unknown> | undefined | Application 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 fordestroy().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.