WgpuOffscreenCanvasBase

class wgpu.gui.WgpuOffscreenCanvasBase(*args, **kwargs)

Bases: WgpuCanvasBase

Base class for off-screen canvases.

It provides a custom context that renders to a texture instead of a surface/screen. On each draw the resulting image is passes as a texture to the present() method. Subclasses should (at least) implement present()

get_context(kind='webgpu')

Get the GPUCanvasContext object to obtain a texture to render to.

get_preferred_format()

Get the preferred format for this canvas.

This method can be overloaded to control the used texture format. The default is “rgba8unorm-srgb”.

get_surface_info()

This canvas does not correspond to an on-screen window.

present(texture)

Method that gets called at the end of each draw event.

The rendered image is represented by the texture argument. Subclasses should overload this method and use the texture to process the rendered image.

The texture is a new object at each draw, but is not explicitly destroyed, so it can be used e.g. as a texture binding (subject to set TextureUsage).