RenderTexture2D
An offscreen render target that can be drawn into and then sampled as a regular texture. Both RenderSurface and RenderTexture2D implement the RenderDestination interface.
Creating
Section titled “Creating”import { RenderTexture2D } from 'webgpu-spritebatch'
const scene = RenderTexture2D.create(surface, { width: 320, height: 180 })Members
Section titled “Members”| Member | Type | Description |
|---|---|---|
texture | Texture2D | The underlying texture — pass to batch.draw() |
width / height | number | Texture dimensions in pixels |
format | GPUTextureFormat | Color texture format |
colorView / depthView | GPUTextureView | Render attachment views |
Methods
Section titled “Methods”static create(surface, options)
Section titled “static create(surface, options)”Create a render texture with explicit dimensions.
const rt = RenderTexture2D.create(surface, { width: 640, height: 360 })clear(options?)
Section titled “clear(options?)”Clear color and depth. clearColor defaults to transparent.
scene.clear({ clearColor: Color.transparent })resize(width, height)
Section titled “resize(width, height)”Recreate at a new size.
scene.resize(640, 360)resizeToSurface(surface?)
Section titled “resizeToSurface(surface?)”Resize to match the surface’s physical dimensions.
scene.resizeToSurface()destroy()
Section titled “destroy()”Release GPU textures.
scene.destroy()