Package glitter :: Package shaders :: Module attribute
[hide private]
[frames] | no frames]

Source Code for Module glitter.shaders.attribute

  1  """Descriptors for L{ShaderProgram} attributes. 
  2   
  3  End users should typically not need to use this module directly. 
  4   
  5  @bug: Attributes are currently unimplemented. 
  6   
  7  @author: Stephan Wenger 
  8  @date: 2012-02-29 
  9  """ 
 10   
 11  from collections import OrderedDict as _odict 
12 13 -class BaseAttribute(object):
14 pass
15
16 -class Attribute(BaseAttribute):
17 - def __init__(self, name, location, dtype, size, parent):
18 self.name = name 19 self.location = location 20 self.dtype = dtype 21 self.size = size 22 self.parent = parent
23
24 - def __repr__(self):
25 if self.size == 1: 26 return "%s %s;" % (self.dtype, self.name) 27 else: 28 return "%s %s[%d];" % (self.dtype, self.name, self.size)
29
30 - def __str__(self):
31 return "in %r" % self
32
33 - def __get__(self, obj, cls=None):
34 """@todo: Implement this.""" 35 raise NotImplementedError
36
37 - def __set__(self, obj, value):
38 """@todo: Implement this: if the shader is currently bound, set the attribute at once, else store only.""" 39 raise NotImplementedError
40
41 - def _on_bind(self):
42 """@todo: Implement this: call C{glVertexAttrib} with C{index=self._location}.""" 43 pass
44
45 - def _on_release(self):
46 """@todo: Implement this: restore old vertex attrib values if possible.""" 47 pass
48
49 -class AttributeStruct(_odict, BaseAttribute):
50 - def __init__(self, name, parent):
51 super(AttributeStruct, self).__init__() 52 self.name = name 53 self.parent = parent
54
55 - def __repr__(self):
56 return "struct { %s } %s;" % (" ".join(str(value) for value in self.values()), self.name)
57
58 - def __str__(self):
59 return "in %r" % self
60
61 - def __get__(self, obj, cls=None):
62 """@todo: Implement this.""" 63 raise NotImplementedError
64
65 - def __set__(self, obj, value):
66 """@todo: Implement this.""" 67 raise NotImplementedError
68
69 - def _on_bind(self):
70 """@todo: Implement this: call C{glVertexAttrib} with C{index=self._location}.""" 71 pass
72
73 - def _on_release(self):
74 """@todo: Implement this: restore old vertex attrib values if possible.""" 75 pass
76
77 -class AttributeStructArray(_odict, BaseAttribute):
78 - def __init__(self, name, parent):
79 super(AttributeStructArray, self).__init__() 80 self.name = name 81 self.parent = parent
82 83 @property
84 - def size(self):
85 return max(index for index, field in self.keys()) + 1
86
87 - def __repr__(self):
88 unique_values = _odict((field, value) for ((index, field), value) in self.items()) 89 return "struct { %s } %s[%d];" % (" ".join(repr(value) for value in unique_values.values()), self.name, self.size)
90
91 - def __str__(self):
92 return "in %r" % self
93
94 - def __get__(self, obj, cls=None):
95 """@todo: Implement this.""" 96 raise NotImplementedError
97
98 - def __set__(self, obj, value):
99 """@todo: Implement this.""" 100 raise NotImplementedError
101
102 - def _on_bind(self):
103 """@todo: Implement this: call C{glVertexAttrib} with C{index=self._location}.""" 104 pass
105
106 - def _on_release(self):
107 """@todo: Implement this: restore old vertex attrib values if possible.""" 108 pass
109