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

Method create

vispy/visuals/shaders/shader_object.py:23–49  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 2

__setitem__Method · 0.45
__init__Method · 0.45

Calls 3

TextExpressionClass · 0.85
VariableClass · 0.85
_shader_objectMethod · 0.80

Tested by

no test coverage detected