GPUCanvasContext¶
- class wgpu.GPUCanvasContext¶
Bases:
objectRepresents a context to configure a canvas and render to it.
Can be obtained via gui.WgpuCanvasInterface.get_context().
The canvas-context plays a crucial role in connecting the wgpu API to the GUI layer, in a way that allows the GUI to be agnostic about wgpu. It combines (and checks) the user’s preferences with the capabilities and preferences of the canvas.
- property canvas¶
The associated canvas object.
- configure(**parameters)¶
Configures the presentation context for the associated canvas. Destroys any textures produced with a previous configuration. This clears the drawing buffer to transparent black.
- Parameters:
device (WgpuDevice) – The GPU device object to create compatible textures for.
format (
enums.TextureFormat) – The format that textures returned byget_current_texture()will have. Must be one of the supported context formats. Can beNoneto use the canvas’ preferred format.usage (
flags.TextureUsage) – DefaultTextureUsage.OUTPUT_ATTACHMENT.view_formats (List[enums.TextureFormat]) – The formats that views created from textures returned by
get_current_texture()may use.color_space (PredefinedColorSpace) – The color space that values written into textures returned by
get_current_texture()should be displayed with. Default “srgb”. Not yet supported.tone_mapping (
enums.CanvasToneMappingMode) – Not yet supported.alpha_mode (
structs.CanvasAlphaMode) – Determines the effect that alpha values will have on the content of textures returned byget_current_texture()when read, displayed, or used as an image source. Default “opaque”.
- get_current_texture()¶
Get the
GPUTexturethat will be composited to the canvas next.
- get_preferred_format(adapter)¶
Get the preferred surface texture format.
- present()¶
Present what has been drawn to the current texture, by compositing it to the canvas. Note that a canvas based on
gui.WgpuCanvasBasewill call this method automatically at the end of each draw event.
- unconfigure()¶
Removes the presentation context configuration. Destroys any textures produced while configured.