wgpu.GPUCanvasContext

class wgpu.GPUCanvasContext

Bases: object

Represents a context to configure a canvas.

Is also used to obtain the texture to render to.

Can be obtained via gui.WgpuCanvasInterface.get_context().

property canvas

The associated canvas object.

configure(**parameters)

Configures the presentation context for the associated canvas. Destroys any textures produced with a previous configuration.

Parameters:
  • device (WgpuDevice) – The GPU device object.

  • format (enums.TextureFormat) – The texture format, e.g. “bgra8unorm-srgb”. Default uses the preferred_format.

  • usage (flags.TextureUsage) – Default TextureUsage.OUTPUT_ATTACHMENT.

  • color_space (PredefinedColorSpace) – Default “srgb”.

  • alpha_mode (enums.CanvasAlphaMode) – Default opaque.

get_current_texture()

Get the GPUTexture that will be composited to the canvas by the context next.

NOTE: for the time being, this could return a GPUTextureView instead.

get_preferred_format(adapter)

Get the preferred swap chain format.

present()

Present what has been drawn to the current texture, by compositing it to the canvas. Note that a canvas based on gui.WgpuCanvasBase will call this method automatically at the end of each draw event.

unconfigure()

Removes the presentation context configuration. Destroys any textures produced while configured.