WgpuCanvasInterface
- class wgpu.gui.WgpuCanvasInterface(*args, **kwargs)
Bases:
objectThe minimal interface to be a valid canvas.
Any object that implements these methods is a canvas that wgpu can work with. The object does not even have to derive from this class.
In most cases it’s more convenient to subclass
WgpuCanvasBase.- get_context(kind='wgpu')
Get the
GPUCanvasContextobject corresponding to this canvas.The context is used to obtain a texture to render to, and to present that texture to the canvas. This class provides a default implementation to get the appropriate context.
- get_physical_size()
Get the physical size of the canvas in integer pixels.
- get_present_methods()
Get info on the present methods supported by this canvas.
Must return a small dict, used by the canvas-context to determine how the rendered result will be presented to the canvas. This method is only called once, when the context is created.
Each supported method is represented by a field in the dict. The value is another dict with information specific to that present method. A canvas backend must implement at least either “screen” or “bitmap”.
With method “screen”, the context will render directly to a surface representing the region on the screen. The sub-dict should have a
windowfield containing the window id. On Linux there should also beplatformfield to distinguish between “wayland” and “x11”, and adisplayfield for the display id. This information is used by wgpu to obtain the required surface id.With method “bitmap”, the context will present the result as an image bitmap. On GPU-based contexts, the result will first be rendered to an offscreen texture, and then downloaded to RAM. The sub-dict must have a field ‘formats’: a list of supported image formats. Examples are “rgba-u8” and “i-u8”. A canvas must support at least “rgba-u8”. Note that srgb mapping is assumed to be handled by the canvas.
- present_image(image, **kwargs)
Consume the final rendered image.
This is called when using the “bitmap” method, see
get_present_methods(). Canvases that don’t support offscreen rendering don’t need to implement this method.