MCPcopy Create free account
hub / github.com/vispy/vispy / FunctionChain

Class FunctionChain

vispy/visuals/shaders/function.py:569–749  ·  view source on GitHub ↗

Subclass that generates GLSL code to call Function list in order Functions may be called independently, or composed such that the output of each function provides the input to the next. Parameters ---------- name : str The name of the generated function funcs : list

Source from the content-addressed store, hash-verified

567
568
569class FunctionChain(Function):
570 """Subclass that generates GLSL code to call Function list in order
571
572 Functions may be called independently, or composed such that the
573 output of each function provides the input to the next.
574
575 Parameters
576 ----------
577 name : str
578 The name of the generated function
579 funcs : list of Functions
580 The list of Functions that will be called by the generated GLSL code.
581
582 Examples
583 --------
584 This creates a function chain::
585
586 >>> func1 = Function('void my_func_1() {}')
587 >>> func2 = Function('void my_func_2() {}')
588 >>> chain = FunctionChain('my_func_chain', [func1, func2])
589
590 If *chain* is included in a ModularProgram, it will generate the following
591 output::
592
593 void my_func_1() {}
594 void my_func_2() {}
595
596 void my_func_chain() {
597 my_func_1();
598 my_func_2();
599 }
600
601 The return type of the generated function is the same as the return type
602 of the last function in the chain. Likewise, the arguments for the
603 generated function are the same as the first function in the chain.
604
605 If the return type is not 'void', then the return value of each function
606 will be used to supply the first input argument of the next function in
607 the chain. For example::
608
609 vec3 my_func_1(vec3 input) {return input + vec3(1, 0, 0);}
610 void my_func_2(vec3 input) {return input + vec3(0, 1, 0);}
611
612 vec3 my_func_chain(vec3 input) {
613 return my_func_2(my_func_1(input));
614 }
615 """
616
617 def __init__(self, name=None, funcs=()):
618 # bypass Function.__init__ completely.
619 ShaderObject.__init__(self)
620 if not (name is None or isinstance(name, str)):
621 raise TypeError("Name argument must be string or None.")
622 self._funcs = []
623 self._code = None
624 self._name = name or "chain"
625 self._args = []
626 self._rtype = 'void'

Callers 6

test_FunctionChainFunction · 0.90
add_chainMethod · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by 1

test_FunctionChainFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…