thorvg_python.canvas.gl

Classes

GlCanvas

GlCanvas API

Module Contents

class thorvg_python.canvas.gl.GlCanvas(engine: thorvg_python.engine.Engine, op: thorvg_python.base.EngineOption, canvas: thorvg_python.base.CanvasPointer | None = None)

Bases: thorvg_python.canvas.Canvas

GlCanvas API

A module for rendering the graphical elements using the opengl engine.

Warning

The thorvg library bundled with precompiled wheel was not compiled with Gl support You will have to load your own thorvg library compiled with Gl support with Engine(thorvg_lib_path=”…”)

engine
thorvg_lib
_create(op: thorvg_python.base.EngineOption) thorvg_python.base.CanvasPointer

Creates a new OpenGL/ES Canvas object with optional rendering engine settings.

This method generates a OpenGL/ES canvas instance that can be used for drawing vector graphics. It accepts an optional parameter op to choose between different rendering engine behaviors.

Parameters:
op : thorvg_python.engine.EngineOption

The rendering engine option.

Returns:

A new CanvasPointer object.

Return type:

thorvg_python.base.CanvasPointer

Note

Currently, it does not support EngineOption.SMART_RENDER. The request will be ignored.

Note

You need not call this method as it is auto called when initializing GlCanvas().

See also

EngineOption

Added in version 1.0.

set_target(display: Any, surface: Any, context: Any, _id: int, w: int, h: int, cs: thorvg_python.base.Colorspace = Colorspace.ABGR8888) tuple[thorvg_python.base.Result]

Sets the drawing target for rasterization.

This function specifies the drawing target where the rasterization will occur. It can target a specific framebuffer object (FBO) or the main surface.

Parameters:
display : Any

The platform-specific display handle (EGLDisplay for EGL). Set None for other systems.

surface : Any

The platform-specific surface handle (EGLSurface for EGL, HDC for WGL). Set None for other systems.

context : Any

The OpenGL context to be used for rendering on this canvas.

_id : int

The GL target ID, usually indicating the FBO ID. A value of 0 specifies the main surface.

w : int

The width (in pixels) of the raster image.

h : int

The height (in pixels) of the raster image.

cs : ColorSpace

Specifies how the pixel values should be interpreted. Currently, it only allows Colorspace.ABGR8888S as GL_RGBA8.

Returns:

  • Result.INSUFFICIENT_CONDITION If the canvas is currently rendering. Ensure that Canvas.sync() has been called before setting a new target.

  • Result.NOT_SUPPORTED In case the gl engine is not supported.

Return type:

thorvg_python.base.Result

Note

If display and surface are not provided, the ThorVG GL engine assumes that the appropriate OpenGL context is already current and will not attempt to bind a new one.

See also

Canvas.sync()

Added in version 1.0.