Convert *obj* to a new ShaderObject. If the output is a Variable with no name, then set its name using *ref*.
(self, obj, ref=None)
| 21 | |
| 22 | @classmethod |
| 23 | def create(self, obj, ref=None): |
| 24 | """Convert *obj* to a new ShaderObject. If the output is a Variable |
| 25 | with no name, then set its name using *ref*. |
| 26 | """ |
| 27 | if isinstance(ref, Variable): |
| 28 | ref = ref.name |
| 29 | elif isinstance(ref, str) and ref.startswith('gl_'): |
| 30 | # gl_ names not allowed for variables |
| 31 | ref = ref[3:].lower() |
| 32 | |
| 33 | # Allow any type of object to be converted to ShaderObject if it |
| 34 | # provides a magic method: |
| 35 | if hasattr(obj, '_shader_object'): |
| 36 | obj = obj._shader_object() |
| 37 | |
| 38 | if isinstance(obj, ShaderObject): |
| 39 | if isinstance(obj, Variable) and obj.name is None: |
| 40 | obj.name = ref |
| 41 | elif isinstance(obj, str): |
| 42 | obj = TextExpression(obj) |
| 43 | else: |
| 44 | obj = Variable(ref, obj) |
| 45 | # Try prepending the name to indicate attribute, uniform, varying |
| 46 | if obj.vtype and obj.vtype[0] in 'auv': |
| 47 | obj.name = obj.vtype[0] + '_' + obj.name |
| 48 | |
| 49 | return obj |
| 50 | |
| 51 | def __init__(self): |
| 52 | # objects that must be declared before this object's definition. |
no test coverage detected