@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
- addColorAttachment
- addDepthStencil
- createColorAttachment
- createDepthStencil
- destroy
- getColorAttachmentTexture
- getDepthStencilTexture
- getRenderPassDescriptor
- readPixel
- resize
- setClearValue
Constructors
constructor
• new WebGPUFramebuffer(device, width?, height?): WebGPUFramebuffer
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
device | GPUDevice | undefined | GPU device |
width | number | 1 | Initial framebuffer width |
height | number | 1 | Initial framebuffer height |
Returns
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
| Name | Type | Description |
|---|---|---|
index | number | Color attachment index |
texture | WebGPUTexture | Existing 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
| Name | Type | Description |
|---|---|---|
texture | WebGPUTexture | Existing 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
| Name | Type | Default value | Description |
|---|---|---|---|
index | number | undefined | Attachment index |
format | GPUTextureFormat | "rgba8unorm" | Color texture format |
Returns
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
| Name | Type | Default value | Description |
|---|---|---|---|
format | GPUTextureFormat | "depth24plus" | Depth stencil texture format |
Returns
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
| Name | Type | Description |
|---|---|---|
index | number | Attachment 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
| Name | Type | Default value | Description |
|---|---|---|---|
x | number | undefined | Pixel x coordinate |
y | number | undefined | Pixel y coordinate |
index | number | 0 | Attachment 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
| Name | Type |
|---|---|
width | number |
height | number |
Returns
void
Defined in
packages/charm/src/graphics/WebGPU/WebGPUFramebuffer.ts:215
setClearValue
▸ setClearValue(index, clearColor): void
Set clear color for an attachment
Parameters
| Name | Type | Description |
|---|---|---|
index | number | Attachment index |
clearColor | GPUColor | Clear color |
Returns
void