GLShader

class GLShader(**properties: Any)

Superclasses: Object

Constructors:

GLShader(**properties)
new_from_bytes(sourcecode:GLib.Bytes) -> Gsk.GLShader
new_from_resource(resource_path:str) -> Gsk.GLShader

Constructors

class GLShader
classmethod new_from_bytes(sourcecode: Bytes) GLShader

Creates a GskGLShader that will render pixels using the specified code.

Parameters:

sourcecode – GLSL sourcecode for the shader, as a GBytes

classmethod new_from_resource(resource_path: str) GLShader

Creates a GskGLShader that will render pixels using the specified code.

Parameters:

resource_path – path to a resource that contains the GLSL sourcecode for the shader

Methods

class GLShader
compile(renderer: Renderer) bool

Tries to compile the shader for the given renderer.

If there is a problem, this function returns False and reports an error. You should use this function before relying on the shader for rendering and use a fallback with a simpler shader or without shaders if it fails.

Note that this will modify the rendering state (for example change the current GL context) and requires the renderer to be set up. This means that the widget has to be realized. Commonly you want to call this from the realize signal of a widget, or during widget snapshot.

Parameters:

renderer – a GskRenderer

find_uniform_by_name(name: str) int

Looks for a uniform by the name name, and returns the index of the uniform, or -1 if it was not found.

Parameters:

name – uniform name

get_arg_bool(args: Bytes, idx: int) bool

Gets the value of the uniform idx in the args block.

The uniform must be of bool type.

Parameters:
  • args – uniform arguments

  • idx – index of the uniform

get_arg_float(args: Bytes, idx: int) float

Gets the value of the uniform idx in the args block.

The uniform must be of float type.

Parameters:
  • args – uniform arguments

  • idx – index of the uniform

get_arg_int(args: Bytes, idx: int) int

Gets the value of the uniform idx in the args block.

The uniform must be of int type.

Parameters:
  • args – uniform arguments

  • idx – index of the uniform

get_arg_uint(args: Bytes, idx: int) int

Gets the value of the uniform idx in the args block.

The uniform must be of uint type.

Parameters:
  • args – uniform arguments

  • idx – index of the uniform

get_arg_vec2(args: Bytes, idx: int, out_value: Vec2) None

Gets the value of the uniform idx in the args block.

The uniform must be of vec2 type.

Parameters:
  • args – uniform arguments

  • idx – index of the uniform

  • out_value – location to store the uniform value in

get_arg_vec3(args: Bytes, idx: int, out_value: Vec3) None

Gets the value of the uniform idx in the args block.

The uniform must be of vec3 type.

Parameters:
  • args – uniform arguments

  • idx – index of the uniform

  • out_value – location to store the uniform value in

get_arg_vec4(args: Bytes, idx: int, out_value: Vec4) None

Gets the value of the uniform idx in the args block.

The uniform must be of vec4 type.

Parameters:
  • args – uniform arguments

  • idx – index of the uniform

  • out_value – location to store set the uniform value in

get_args_size() int

Get the size of the data block used to specify arguments for this shader.

get_n_textures() int

Returns the number of textures that the shader requires.

This can be used to check that the a passed shader works in your usecase. It is determined by looking at the highest u_textureN value that the shader defines.

get_n_uniforms() int

Get the number of declared uniforms for this shader.

get_resource() str | None

Gets the resource path for the GLSL sourcecode being used to render this shader.

get_source() Bytes

Gets the GLSL sourcecode being used to render this shader.

get_uniform_name(idx: int) str

Get the name of the declared uniform for this shader at index idx.

Parameters:

idx – index of the uniform

get_uniform_offset(idx: int) int

Get the offset into the data block where data for this uniforms is stored.

Parameters:

idx – index of the uniform

get_uniform_type(idx: int) GLUniformType

Get the type of the declared uniform for this shader at index idx.

Parameters:

idx – index of the uniform

Properties

class GLShader
props.resource: str

Resource containing the source code for the shader.

If the shader source is not coming from a resource, this will be None.

props.source: Bytes