Skip to content

@tmrw-realityos/charm


@tmrw-realityos/charm / WebGPUFramebuffer

Class: WebGPUFramebuffer

Defined in: packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:9

Framebuffer class This class helps with some of the common actions when rendering to a texture Like configuring it, generating the renderPassDescriptor, or even reading the pixels back to CPU

Constructors

new WebGPUFramebuffer()

new WebGPUFramebuffer(device, width, height): WebGPUFramebuffer

Defined in: packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:31

Parameters

device

GPUDevice

GPU device

width

number = 1

Initial framebuffer width

height

number = 1

Initial framebuffer height

Returns

WebGPUFramebuffer

Properties

name

name: string = ""

Defined in: packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:10

Accessors

height

Get Signature

get height(): number

Defined in: packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:44

Returns

number


width

Get Signature

get width(): number

Defined in: packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:40

Returns

number

Methods

addColorAttachment()

addColorAttachment(index, texture): void

Defined in: packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:72

Add an external texture as color attachment. The texture will not be managed, i.e. resized and destroyed by the framebuffer.

Parameters

index

number

Color attachment index

texture

WebGPUTexture

Existing color texture

Returns

void


addDepthStencil()

addDepthStencil(texture): void

Defined in: packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:53

Add an external texture as depth stencil attachment. The texture will not be managed, i.e. resized and destroyed by the framebuffer.

Parameters

texture

WebGPUTexture

Existing texture used for depth stencil attachment

Returns

void


createColorAttachment()

createColorAttachment(index, format): WebGPUTexture

Defined in: packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:103

Create a color attachment. The texture will be managed, i.e. resized and destroyed by the framebuffer.

Parameters

index

number

Attachment index

format

GPUTextureFormat = "rgba8unorm"

Color texture format

Returns

WebGPUTexture


createDepthStencil()

createDepthStencil(format): WebGPUTexture

Defined in: packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:132

Create a depth stencil attachment. The texture will be managed, i.e. resized and destroyed by the framebuffer.

Parameters

format

GPUTextureFormat = "depth24plus"

Depth stencil texture format

Returns

WebGPUTexture


destroy()

destroy(): void

Defined in: packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:257

Destroy all managed resources

Returns

void


getColorAttachmentTexture()

getColorAttachmentTexture(index): undefined | WebGPUTexture

Defined in: packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:158

Get color attachment

Parameters

index

number

Attachment index

Returns

undefined | WebGPUTexture

Color attachment texture


getDepthStencilTexture()

getDepthStencilTexture(): undefined | WebGPUTexture

Defined in: packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:166

Get depth stencil texture

Returns

undefined | WebGPUTexture

Depth stencil texture


getRenderPassDescriptor()

getRenderPassDescriptor(): GPURenderPassDescriptor

Defined in: packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:174

Get renderpass descriptor for the current attachments.

Returns

GPURenderPassDescriptor

Renderpass descriptor


readPixel()

readPixel(x, y, index, encoder?): Promise<ArrayBuffer>

Defined in: packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:190

Read a pixel from a color attachment

Parameters

x

number

Pixel x coordinate

y

number

Pixel y coordinate

index

number = 0

Attachment index

encoder?

GPUCommandEncoder

Command encoder where to queue commands, otherwise a new one is created

Returns

Promise<ArrayBuffer>

Pixel color


resize()

resize(width, height): void

Defined in: packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:228

Resize managed textures

Parameters

width

number

height

number

Returns

void


setClearValue()

setClearValue(index, clearColor): void

Defined in: packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:91

Set clear color for an attachment

Parameters

index

number

Attachment index

clearColor

GPUColor

Clear color

Returns

void