RenderWindow
Introduction
WebGPU rendering window
vtkWebGPURenderWindow is designed to view/render a vtkRenderWindow with the WebGPU backend. It owns the canvas, the adapter and the device, and it reacquires them when the device is lost.
Methods
buildPass
Builds myself: adopt the renderers of the renderable as children and, on the second visit, create the command encoder of the frame.
| Argument | Type | Required | Description |
|---|---|---|---|
prepass | Boolean | Yes |
captureNextImage
Capture a screenshot of the contents of this render window. The options object can include a size array ([w, h]) or a scale floating point value, as well as a resetCamera boolean. Returns a promise that resolves to the captured screenshot, or null when the render window was already deleted.
| Argument | Type | Required | Description |
|---|---|---|---|
format | String | Yes | |
options | IWebGPUCaptureOptions | Yes |
colorBufferWidth
The width, in texels, of the readback buffer. Rounded up so that a row is a multiple of 256 bytes, as WebGPU requires.
colorValues
The RGBA values of the image, tightly packed at width texels per row.
create3DContextAsync
Request the adapter and the device, watch the device for loss, and get the WebGPU context of the canvas. Resolves once the context is ready, or early when the render window was deleted while waiting.
createSelector
Create a hardware selector bound to this render window.
extend
Method used to decorate a given object (publicAPI+model) with vtkWebGPURenderWindow characteristics.
| Argument | Type | Required | Description |
|---|---|---|---|
publicAPI | Yes | object on which methods will be bounds (public) | |
model | Yes | object on which data structure will be bounds (protected) | |
initialValues | IWebGPURenderWindowInitialValues | No | (default: {}) |
getCanvas
Get the canvas rendered into.
getCommandEncoder
Get the command encoder of the frame being built.
getContainer
Get the container element.
getContainerSize
Get the size of the container element, falling back to the size of the render window when there is no container.
getContext
Get the WebGPU context of the canvas.
getCurrentTexture
Get the texture the canvas context is presenting this frame.
getCursor
Get the CSS cursor of the container.
getDevice
Get the device this render window renders with.
getDeviceLostInfo
Get the information of the last device loss, or null when the device was never lost or was reacquired.
getFramebufferSize
Get the frame buffer size.
getInitialized
Whether the device and the canvas context are ready.
getMultiSample
Get the number of samples per pixel.
getNotifyStartCaptureImage
Whether the image ready event fires once the frame is done.
getPixelsAsync
Read the color texture of the forward pass back into a tightly packed RGBA array.
getPresentationFormat
Get the texture format the canvas context is configured with.
getPropFromID
Get the view node of the prop holding an id, or null when none does.
| Argument | Type | Required | Description |
|---|---|---|---|
id | Number | Yes |
getRenderPasses
Get the render passes traversed on every render.
getSize
getSizeByReference
getUniquePropID
Get an id no other prop of this render window uses, for hardware selection.
getUseBackgroundImage
Whether the background image is attached to the container.
getUseOffScreen
Whether the canvas is hidden.
getViewNodeFactory
Get the factory creating the WebGPU view nodes of this render window.
getWebGPUConfiguration
Get the configuration that supplies the adapter and device.
getXrSupported
initialize
Start acquiring the adapter, the device and the canvas context, unless that is already under way. The initialized event fires once they are available.
invokeDeviceLost
Call any registered callbacks with the reason the device was lost.
| Argument | Type | Required | Description |
|---|---|---|---|
event | IWebGPUDeviceLostEvent | Yes |
invokeImageReady
Call any registered callbacks with the captured image URL.
| Argument | Type | Required | Description |
|---|---|---|---|
imageURL | String | Yes |
invokeInitialized
Call any registered callbacks once the device and the context are ready.
invokeWindowResizeEvent
Call any registered callbacks whenever setSize() changes the size.
| Argument | Type | Required | Description |
|---|---|---|---|
size | IWebGPUWindowResizeEvent | Yes |
newInstance
Method used to create a new instance of vtkWebGPURenderWindow.
| Argument | Type | Required | Description |
|---|---|---|---|
initialValues | IWebGPURenderWindowInitialValues | No | for pre-setting some of its content |
onDeviceLost
Register a callback to be called whenever the device is lost.
| Argument | Type | Required | Description |
|---|---|---|---|
callback | Yes |
onImageReady
Register a callback to be called whenever a captured image becomes ready.
| Argument | Type | Required | Description |
|---|---|---|---|
callback | Yes |
onInitialized
Register a callback to be called once the device and the context are ready.
| Argument | Type | Required | Description |
|---|---|---|---|
callback | Yes |
onWindowResizeEvent
Register a callback to be called whenever setSize() changes the size.
| Argument | Type | Required | Description |
|---|---|---|---|
callback | Yes |
recoverable
False when the device was lost because it was destroyed, in which case no new device is acquired.
recreateSwapChain
Reconfigure the canvas context for the current device and size.
releaseGraphicsResources
Release the resources of the render passes and of every view node, and drop the adapter, device and context. The render window initializes again on the next traversal.
setBackgroundImage
| Argument | Type | Required | Description |
|---|---|---|---|
img | HTMLImageElement | Yes | The background image. |
setCanvas
| Argument | Type | Required | Description |
|---|---|---|---|
canvas | HTMLCanvasElement | Yes |
setContainer
Move the canvas into a container element.
| Argument | Type | Required | Description |
|---|---|---|---|
el | HTMLElement | Yes | The container element. |
setContext
| Argument | Type | Required | Description |
|---|---|---|---|
context | GPUCanvasContext | Yes |
setCursor
| Argument | Type | Required | Description |
|---|---|---|---|
cursor | String | Yes |
setInitialized
| Argument | Type | Required | Description |
|---|---|---|---|
initialized | Boolean | Yes |
setMultiSample
Set the number of samples per pixel. Supported values are 1 and 4.
setNotifyStartCaptureImage
| Argument | Type | Required | Description |
|---|---|---|---|
notifyStartCaptureImage | Boolean | Yes |
setRenderPasses
| Argument | Type | Required | Description |
|---|---|---|---|
renderPasses | Array[vtkRenderPass] | Yes |
setSize
| Argument | Type | Required | Description |
|---|---|---|---|
x | Number | Yes | |
y | Number | Yes |
setSize
Sets the pixel width and height of the rendered image, and fires the windowResizeEvent when they changed.
| Argument | Type | Required | Description |
|---|---|---|---|
size | Vector2 | Yes |
setSizeFrom
| Argument | Type | Required | Description |
|---|---|---|---|
size | Vector2 | Yes |
setUseBackgroundImage
Add or remove the background image from the container.
| Argument | Type | Required | Description |
|---|---|---|---|
value | Boolean | Yes |
setUseOffScreen
| Argument | Type | Required | Description |
|---|---|---|---|
useOffScreen | Boolean | Yes |
setViewStream
| Argument | Type | Required | Description |
|---|---|---|---|
stream | vtkViewStream | Yes | The vtkViewStream instance. |
setWebGPUConfiguration
Set the configuration before initialization. Passing null creates an internally owned configuration.
traverseAllPasses
Traverse the render passes, submitting the command encoder of the frame when they are done. Queues the traversal until the device is available when the render window is not initialized yet.