RenderWindow
Introduction
vtkWebGPURenderWindow is designed to view/render a vtkRenderWindow using the WebGPU API.
Methods
buildPass
Build pass callback invoked by the scene-graph traversal.
| Argument | Type | Required | Description |
|---|---|---|---|
prepass | Yes | Whether this is the pre-pass (true) or post-pass (false). |
captureNextImage
Capture the next rendered frame as an image.
| Argument | Type | Required | Description |
|---|---|---|---|
format | Yes | The image format (default: 'image/png'). | |
opts | Yes | Options for capture. | |
opts.resetCamera | Yes | Whether to reset the camera before capture. | |
opts.size | Yes | Override the render size as [width, height]. | |
opts.scale | Yes | Scale factor for the render size. |
create3DContextAsync
Create the WebGPU 3D context asynchronously. Requests the GPU adapter and device, then configures the canvas context.
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 bound (public) | |
model | Yes | object on which data structure will be bound (protected) | |
initialValues | Yes | (default: {}) |
getCanvas
Get the current canvas element.
getCommandEncoder
Get the WebGPU command encoder for the current frame.
getContainer
Get the current container element.
getContainerSize
Get the size of the container element in pixels.
Returns
| Type | Description |
|---|---|
| [width, height] |
getContext
Get the WebGPU canvas context.
getCurrentTexture
Get the current swap-chain texture from the canvas context.
getCursor
Get the current cursor style.
getDevice
Get the WebGPU device wrapper.
getFramebufferSize
Get the framebuffer size.
Returns
| Type | Description |
|---|---|
| [width, height] |
getInitialized
Get whether the render window has been initialized.
getMultiSample
Get the current MSAA sample count.
getNotifyStartCaptureImage
Get whether image capture notification is enabled.
getPixelsAsync
Read pixels from the current framebuffer asynchronously. Returns an object with colorValues (Uint8ClampedArray), width, and height.
getPresentationFormat
Get the presentation texture format used by the swap chain.
getPropFromID
Get a prop (actor) by its hardware-selection ID.
| Argument | Type | Required | Description |
|---|---|---|---|
id | Yes | The prop ID. |
Returns
| Type | Description |
|---|---|
The matching prop, or null if not found. |
getRenderPasses
Get the render passes.
getSize
Get the current render window size.
Returns
| Type | Description |
|---|---|
| [width, height] |
getUniquePropID
Get a unique prop ID for hardware selection.
getUseBackgroundImage
Get whether a background image is being used.
getUseOffScreen
Get whether off-screen rendering is enabled.
getViewNodeFactory
Get the view-node factory used to create WebGPU scene-graph nodes.
getXrSupported
Get whether XR (WebXR) is supported.
initialize
Initialize the render window. Triggers async GPU adapter/device creation; fires the initialized event on completion.
invokeImageReady
Programmatically fire the imageReady event.
| Argument | Type | Required | Description |
|---|---|---|---|
imageURL | Yes | The image data URL. |
invokeInitialized
Programmatically fire the initialized event.
invokeWindowResizeEvent
Programmatically fire the windowResizeEvent.
| Argument | Type | Required | Description |
|---|---|---|---|
event | Yes | The resize event payload. |
newInstance
Method used to create a new instance of vtkWebGPURenderWindow.
| Argument | Type | Required | Description |
|---|---|---|---|
initialValues | Yes | Initial property values. |
onImageReady
Register a callback for when a captured image is ready.
| Argument | Type | Required | Description |
|---|---|---|---|
callback | Yes | Called with the image data URL string. |
onInitialized
Register a callback for when the render window has finished initializing.
| Argument | Type | Required | Description |
|---|---|---|---|
callback | Yes | Called once GPU context creation is complete. |
onWindowResizeEvent
Register a callback for window resize events.
| Argument | Type | Required | Description |
|---|---|---|---|
callback | Yes | Called with { width, height } when the window is resized. |
recreateSwapChain
Unconfigure and reconfigure the swap chain. Called automatically when the canvas size changes.
releaseGraphicsResources
Release all GPU resources and clean up the rendering context.
setBackgroundImage
Set the background image element.
| Argument | Type | Required | Description |
|---|---|---|---|
img | Yes | The image element. |
setCanvas
Set the canvas element.
| Argument | Type | Required | Description |
|---|---|---|---|
canvas | Yes | The canvas element. |
setContainer
Set the container element for the render window.
| Argument | Type | Required | Description |
|---|---|---|---|
el | Yes | The HTML element to use as the container, or null to detach. |
setContext
Set the WebGPU canvas context.
| Argument | Type | Required | Description |
|---|---|---|---|
context | Yes | The GPU canvas context. |
setCursor
Set the cursor style.
| Argument | Type | Required | Description |
|---|---|---|---|
cursor | Yes | CSS cursor value. |
setDevice
Set the WebGPU device wrapper.
| Argument | Type | Required | Description |
|---|---|---|---|
device | Yes | The device wrapper instance. |
setInitialized
Set the initialized state.
| Argument | Type | Required | Description |
|---|---|---|---|
initialized | Yes | Whether initialized. |
setMultiSample
Controls the number of MSAA samples per pixel.
- Default:
1(no anti-aliasing)
| Argument | Type | Required | Description |
|---|---|---|---|
count | Yes | The sample count (1 or 4). |
Returns
| Type | Description |
|---|---|
true if the value changed, false otherwise. |
setNotifyStartCaptureImage
Set whether image capture notification is enabled.
| Argument | Type | Required | Description |
|---|---|---|---|
notify | Yes | Whether to notify on capture start. |
setRenderPasses
Set the render passes.
| Argument | Type | Required | Description |
|---|---|---|---|
passes | Yes | Array of render passes. |
setSize
Set the size of the render window.
| Argument | Type | Required | Description |
|---|---|---|---|
width | Yes | Width in pixels. | |
height | Yes | Height in pixels. |
setUseBackgroundImage
Enable or disable rendering of a background image behind the scene.
| Argument | Type | Required | Description |
|---|---|---|---|
value | Yes | Whether to use the background image. |
setUseOffScreen
Set whether to use off-screen rendering.
| Argument | Type | Required | Description |
|---|---|---|---|
useOffScreen | Yes | Whether to render off-screen. |
setViewStream
Set a view stream for remote rendering.
| Argument | Type | Required | Description |
|---|---|---|---|
stream | Yes | The view stream instance. |
traverseAllPasses
Traverse all registered render passes.