Demonstrate how a transform would work.
()
| 83 | |
| 84 | |
| 85 | def test_example2(): |
| 86 | """Demonstrate how a transform would work.""" |
| 87 | vert_template = Function(""" |
| 88 | void main(void) |
| 89 | { |
| 90 | gl_Position = $position; |
| 91 | } |
| 92 | """) |
| 93 | |
| 94 | transformScale = Function(""" |
| 95 | vec4 transform_scale(vec4 pos) |
| 96 | { |
| 97 | pos.xyz *= $scale; |
| 98 | return pos; |
| 99 | } |
| 100 | """) |
| 101 | |
| 102 | class Transform(object): |
| 103 | def __init__(self): |
| 104 | # Equivalent methods to create new function object |
| 105 | self.func = Function(transformScale) |
| 106 | self.func['scale'] = 'uniform float' |
| 107 | # self.func = Function(transformScale) |
| 108 | |
| 109 | def set_scale(self, scale): |
| 110 | self.func['scale'].value = scale |
| 111 | |
| 112 | transforms = [Transform(), Transform(), Transform()] |
| 113 | |
| 114 | code = Function(vert_template) |
| 115 | ob = Variable('attribute vec3 a_position') |
| 116 | for trans in transforms: |
| 117 | ob = trans.func(ob) |
| 118 | code['position'] = ob |
| 119 | print(code) |
| 120 | |
| 121 | # Tests |
| 122 |