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.Program(vert=None, frag=None, count=0)¶
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_dataand
program['u_color'] = (1, 0, 0).
The vertex shader to be used by this program
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'] = Xwill be combined into a structured vbo with interleaved elements, which is more efficient than having one vbo per attribute.
If several shaders are specified, only one can contain the main function. OpenGL ES 2.0 does not support a list of shaders.
Bind a VertexBuffer that has structured data
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.
- modestr | GL_ENUM
‘points’, ‘lines’, ‘line_strip’, ‘line_loop’, ‘lines_adjacency’, ‘line_strip_adjacency’, ‘triangles’, ‘triangle_strip’, or ‘triangle_fan’.
Array of indices to draw.
Check error after draw.
- set_shaders(vert, frag, geom=None, update_variables=True)¶
Set the vertex and fragment shaders.
Source code for vertex shader.
Source code for fragment shaders.
- geomstr (optional)
Source code for geometry shader.
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.
Each variable is represented as a tuple (kind, type, name), where kind is ‘attribute’, ‘uniform’, ‘uniform_array’, ‘varying’ or ‘const’.