Skip to content

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.

import { RenderTexture2D } from 'webgpu-spritebatch'
const scene = RenderTexture2D.create(surface, { width: 320, height: 180 })
MemberTypeDescription
textureTexture2DThe underlying texture — pass to batch.draw()
width / heightnumberTexture dimensions in pixels
formatGPUTextureFormatColor texture format
colorView / depthViewGPUTextureViewRender attachment views

Create a render texture with explicit dimensions.

const rt = RenderTexture2D.create(surface, { width: 640, height: 360 })

Clear color and depth. clearColor defaults to transparent.

scene.clear({ clearColor: Color.transparent })

Recreate at a new size.

scene.resize(640, 360)

Resize to match the surface’s physical dimensions.

scene.resizeToSurface()

Release GPU textures.

scene.destroy()