vispy.visuals.shaders.compiler module#

class vispy.visuals.shaders.compiler.Compiler(namespace=None, **shaders)#

Bases: object

Compiler is used to convert Function and Variable instances into ready-to-use GLSL code. This class handles name mangling to ensure that there are no name collisions amongst global objects. The final name of each object may be retrieved using Compiler.__getitem__(obj).

Accepts multiple root Functions as keyword arguments. compile() then returns a dict of GLSL strings with the same keys.

Example:

# initialize with two main functions
compiler = Compiler(vert=v_func, frag=f_func)

# compile and extract shaders
code = compiler.compile()
v_code = code['vert']
f_code = code['frag']

# look up name of some object
name = compiler[obj]
compile(pretty=True)#

Compile all code and return a dict {name: code} where the keys are determined by the keyword arguments passed to __init__().

Parameters:
prettybool

If True, use a slower method to mangle object names. This produces GLSL that is more readable. If False, then the output is mostly unreadable GLSL, but is about 10x faster to compile.