Skip to content

@tmrw-realityos/charm / Exports / WebGPUFramebuffer

Class: WebGPUFramebuffer

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

Table of contents

Constructors

Accessors

Methods

Constructors

constructor

new WebGPUFramebuffer(device, width?, height?): WebGPUFramebuffer

Parameters

NameTypeDefault valueDescription
deviceGPUDeviceundefinedGPU device
widthnumber1Initial framebuffer width
heightnumber1Initial framebuffer height

Returns

WebGPUFramebuffer

Defined in

packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:30

Accessors

height

get height(): number

Returns

number

Defined in

packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:43


width

get width(): number

Returns

number

Defined in

packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:39

Methods

addColorAttachment

addColorAttachment(index, texture): void

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

Parameters

NameTypeDescription
indexnumberColor attachment index
textureWebGPUTextureExisting color texture

Returns

void

Defined in

packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:71


addDepthStencil

addDepthStencil(texture): void

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

Parameters

NameTypeDescription
textureWebGPUTextureExisting texture used for depth stencil attachment

Returns

void

Defined in

packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:52


createColorAttachment

createColorAttachment(index, format?): WebGPUTexture

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

Parameters

NameTypeDefault valueDescription
indexnumberundefinedAttachment index
formatGPUTextureFormat"rgba8unorm"Color texture format

Returns

WebGPUTexture

Defined in

packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:102


createDepthStencil

createDepthStencil(format?): WebGPUTexture

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

Parameters

NameTypeDefault valueDescription
formatGPUTextureFormat"depth24plus"Depth stencil texture format

Returns

WebGPUTexture

Defined in

packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:130


destroy

destroy(): void

Destroy all managed resources

Returns

void

Defined in

packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:244


getColorAttachmentTexture

getColorAttachmentTexture(index): undefined | WebGPUTexture

Get color attachment

Parameters

NameTypeDescription
indexnumberAttachment index

Returns

undefined | WebGPUTexture

Color attachment texture

Defined in

packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:155


getDepthStencilTexture

getDepthStencilTexture(): undefined | WebGPUTexture

Get depth stencil texture

Returns

undefined | WebGPUTexture

Depth stencil texture

Defined in

packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:163


getRenderPassDescriptor

getRenderPassDescriptor(): GPURenderPassDescriptor

Get renderpass descriptor for the current attachments.

Returns

GPURenderPassDescriptor

Renderpass descriptor

Defined in

packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:171


readPixel

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

Read a pixel from a color attachment

Parameters

NameTypeDefault valueDescription
xnumberundefinedPixel x coordinate
ynumberundefinedPixel y coordinate
indexnumber0Attachment index

Returns

Promise<ArrayBuffer>

Pixel color

Defined in

packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:186


resize

resize(width, height): void

Resize managed textures

Parameters

NameType
widthnumber
heightnumber

Returns

void

Defined in

packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:215


setClearValue

setClearValue(index, clearColor): void

Set clear color for an attachment

Parameters

NameTypeDescription
indexnumberAttachment index
clearColorGPUColorClear color

Returns

void

Defined in

packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:90