Shader / Program (Base)

class arcade.gl.Program(ctx: Context, *, varyings_capture_mode: str = 'interleaved')[source]

Bases: ABC

Compiled and linked shader program.

Currently supports

  • vertex shader

  • fragment shader

  • geometry shader

  • tessellation control shader

  • tessellation evaluation shader

Transform feedback also supported when output attributes names are passed in the varyings parameter.

The best way to create a program instance is through arcade.gl.Context.program()

Parameters:
  • ctx – The context this program belongs to

  • vertex_shader – Vertex shader source

  • fragment_shader – Fragment shader source

  • geometry_shader – Geometry shader source

  • tess_control_shader – Tessellation control shader source

  • tess_evaluation_shader – Tessellation evaluation shader source

  • varyings – List of out attributes used in transform feedback.

  • varyings_capture_mode – The capture mode for transforms. "interleaved" means all out attribute will be written to a single buffer. "separate" means each out attribute will be written separate buffers. Based on these settings the transform() method will accept a single buffer or a list of buffer.

attribute_key: str
property ctx: Context

The context this program belongs to.

abstract property attributes: Iterable

List of attribute information.

abstract property varyings: list[str]

Out attributes names used in transform feedback.

abstract property out_attributes: list[str]

Out attributes names used in transform feedback.

Alias for varyings.

abstract property varyings_capture_mode: str

Get the capture more for transform feedback (single, multiple).

This is a read only property since capture mode can only be set before the program is linked.

abstract property geometry_input: int

The geometry shader’s input primitive type.

This an be compared with GL_TRIANGLES, GL_POINTS etc. and is queried when the program is created.

abstract property geometry_output: int

The geometry shader’s output primitive type.

This an be compared with GL_TRIANGLES, GL_POINTS etc. and is queried when the program is created.

abstract property geometry_vertices: int

The maximum number of vertices that can be emitted. This is queried when the program is created.

abstract delete()[source]

Destroy the underlying OpenGL resource.

Don’t use this unless you know exactly what you are doing.

abstract 🧙 self[item][source]

Get a uniform or uniform block

abstract 🧙 self[key] = value[source]

Set a uniform value.

Example:

program['color'] = 1.0, 1.0, 1.0, 1.0
program['mvp'] = projection @ view @ model
Parameters:
  • key – The uniform name

  • value – The uniform value

abstract set_uniform_safe(name: str, value: Any)[source]

Safely set a uniform catching KeyError.

Parameters:
  • name – The uniform name

  • value – The uniform value

abstract set_uniform_array_safe(name: str, value: list[Any])[source]

Safely set a uniform array.

Arrays can be shortened by the glsl compiler not all elements are determined to be in use. This function checks the length of the actual array and sets a subset of the values if needed. If the uniform don’t exist no action will be done.

Parameters:
  • name – Name of uniform

  • value – List of values

abstract use()[source]

Activates the shader.

This is normally done for you automatically.