ProteinMotion
Reference navigation
On this page

CLASS · v0.9.1

Renderer

Render protein and annotation objects with a reusable GPU renderer.

python
from proteinmotion.renderer import Renderer

Constructor

python
Renderer(width=1920, height=1080, *, msaa=4, require_metal=None, readback_format='rgba')

Parameters

ParameterDefaultDescription
width1920Image width in pixels.
height1080Image height in pixels.
msaakeyword only4Multisample count: 1 or 4.
require_metalkeyword onlyNoneRequire the Metal backend. None requires Metal on macOS and requests a high-performance adapter elsewhere.
readback_formatkeyword only'rgba'"rgba" for image arrays or "nv12" for video encoding.

Notes

Use a with block to release resources. draw() submits GPU work without readback. render() returns one completed frame. enqueue() and drain() overlap GPU rendering and CPU encoding.

Attributes

NameDescription
adapter_infoGPU adapter and backend information.

Methods and properties

NameDescription
draw()methodDraw a GPU frame without copying pixels to the CPU.
enqueue()methodSubmit a frame and retrieve the oldest completed readback when the pipeline is full.
drain()methodYield all remaining queued frame arrays in submission order.
render()methodDraw one frame and wait for its pixel readback.
close()methodRelease GPU buffers and renderer resources.
__enter__()methodEnter a with Renderer(...) context.
__exit__()methodClose renderer resources on context exit.
python
Renderer.draw(proteins, camera, background)

Draw a GPU frame without copying pixels to the CPU.

ParameterDefaultDescription
proteinsRequiredProtein or annotation objects to add or render.
cameraRequiredCamera used to project or frame objects.
backgroundRequiredThree RGB floats in [0, 1], such as scene.background.

Returns: None

python
Renderer.enqueue(proteins, camera, background)

Submit a frame and retrieve the oldest completed readback when the pipeline is full.

ParameterDefaultDescription
proteinsRequiredProtein or annotation objects to add or render.
cameraRequiredCamera used to project or frame objects.
backgroundRequiredThree RGB floats in [0, 1], such as scene.background.

Returns: Frame array, or None while the readback pipeline fills.

python
Renderer.drain()

Yield all remaining queued frame arrays in submission order.

Returns: Iterator of frame arrays.

python
Renderer.render(proteins, camera, background)

Draw one frame and wait for its pixel readback.

ParameterDefaultDescription
proteinsRequiredProtein or annotation objects to add or render.
cameraRequiredCamera used to project or frame objects.
backgroundRequiredThree RGB floats in [0, 1], such as scene.background.

Returns: RGBA uint8 array or NV12 array, according to readback_format.

python
Renderer.close()

Release GPU buffers and renderer resources.

Returns: None

python
Renderer.__enter__()

Enter a with Renderer(...) context.

Returns: The renderer.

python
Renderer.__exit__(*args)

Close renderer resources on context exit.

ParameterDefaultDescription
*argsException information supplied by the context manager.

Returns: None