Appearance
@tmrw-realityos/charm • Docs
@tmrw-realityos/charm / 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
Constructors
new WebGPUFramebuffer()
new WebGPUFramebuffer(
device,width,height):WebGPUFramebuffer
Parameters
• device: GPUDevice
GPU device
• width: number = 1
Initial framebuffer width
• height: number = 1
Initial framebuffer height
Returns
Defined in
packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:31
Properties
name
name:
string=""
Defined in
packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:10
Accessors
height
getheight():number
Returns
number
Defined in
packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:44
width
getwidth():number
Returns
number
Defined in
packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:40
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
• index: number
Color attachment index
• texture: WebGPUTexture
Existing color texture
Returns
void
Defined in
packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:72
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
• texture: WebGPUTexture
Existing texture used for depth stencil attachment
Returns
void
Defined in
packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:53
createColorAttachment()
createColorAttachment(
index,format):WebGPUTexture
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
Defined in
packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:103
createDepthStencil()
createDepthStencil(
format):WebGPUTexture
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
Defined in
packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:132
destroy()
destroy():
void
Destroy all managed resources
Returns
void
Defined in
packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:258
getColorAttachmentTexture()
getColorAttachmentTexture(
index):undefined|WebGPUTexture
Get color attachment
Parameters
• index: number
Attachment index
Returns
undefined | WebGPUTexture
Color attachment texture
Defined in
packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:158
getDepthStencilTexture()
getDepthStencilTexture():
undefined|WebGPUTexture
Get depth stencil texture
Returns
undefined | WebGPUTexture
Depth stencil texture
Defined in
packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:166
getRenderPassDescriptor()
getRenderPassDescriptor():
GPURenderPassDescriptor
Get renderpass descriptor for the current attachments.
Returns
GPURenderPassDescriptor
Renderpass descriptor
Defined in
packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:174
readPixel()
readPixel(
x,y,index,encoder?):Promise<ArrayBuffer>
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
Defined in
packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:190
resize()
resize(
width,height):void
Resize managed textures
Parameters
• width: number
• height: number
Returns
void
Defined in
packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:229
setClearValue()
setClearValue(
index,clearColor):void
Set clear color for an attachment
Parameters
• index: number
Attachment index
• clearColor: GPUColor
Clear color
Returns
void