vispy.gloo.program module#

Implementation of a GL Program object.

This class parses the source code to obtain the names and types of uniforms, attributes, varyings and constants. This information is used to provide the user with a natural way to set variables.

Gloo vs GLIR#

Done in this class:
  • Check the data shape given for uniforms and attributes

  • Convert uniform data to array of the correct type

  • Check whether any variables are set that are not present in source code

Done by GLIR:
  • Check whether a set uniform/attribute is not active (a warning is given)

  • Check whether anactive attribute or uniform is not set (a warning is given)

class vispy.gloo.program.FragmentShader(code=None)#

Bases: Shader

class vispy.gloo.program.GeometryShader(code=None)#

Bases: Shader

class vispy.gloo.program.Program(vert=None, frag=None, count=0)#

Bases: GLObject

Shader program object

A Program is an object to which shaders can be attached and linked to create the final program.

Uniforms and attributes can be set using indexing: e.g. program['a_pos'] = pos_data and program['u_color'] = (1, 0, 0).

Parameters:
vertstr

The vertex shader to be used by this program

fragstr

The fragment shader to be used by this program

countint (optional)

The program will prepare a structured vertex buffer of count vertices. All attributes set using prog['attr'] = X will be combined into a structured vbo with interleaved elements, which is more efficient than having one vbo per attribute.

Notes

If several shaders are specified, only one can contain the main function. OpenGL ES 2.0 does not support a list of shaders.

bind(data)#

Bind a VertexBuffer that has structured data

Parameters:
dataVertexBuffer

The vertex buffer to bind. The field names of the array are mapped to attribute names in GLSL.

draw(mode='triangles', indices=None, check_error=True)#

Draw the attribute arrays in the specified mode.

Parameters:
modestr | GL_ENUM

‘points’, ‘lines’, ‘line_strip’, ‘line_loop’, ‘lines_adjacency’, ‘line_strip_adjacency’, ‘triangles’, ‘triangle_strip’, or ‘triangle_fan’.

indicesarray

Array of indices to draw.

check_error:

Check error after draw.

set_shaders(vert, frag, geom=None, update_variables=True)#

Set the vertex and fragment shaders.

Parameters:
vertstr

Source code for vertex shader.

fragstr

Source code for fragment shaders.

geomstr (optional)

Source code for geometry shader.

update_variablesbool

If True, then process any pending variables immediately after setting shader code. Default is True.

property shaders#

All currently attached shaders

property variables#

A list of the variables in use by the current program

The list is obtained by parsing the GLSL source code.

Returns:
variableslist

Each variable is represented as a tuple (kind, type, name), where kind is ‘attribute’, ‘uniform’, ‘uniform_array’, ‘varying’ or ‘const’.

class vispy.gloo.program.Shader(code=None)#

Bases: GLObject

property code#
class vispy.gloo.program.VertexShader(code=None)#

Bases: Shader