Package glitter :: Package arrays :: Module elementarray
[hide private]
[frames] | no frames]

Source Code for Module glitter.arrays.elementarray

 1  """Element array buffer class. 
 2   
 3  @author: Stephan Wenger 
 4  @date: 2012-02-29 
 5  """ 
 6   
 7  import numpy as _np 
 8   
 9  import glitter.raw as _gl 
10  from glitter.utils import buffer_dimensions_to_primitive, Datatype, coerce_array 
11  from glitter.arrays.basebuffer import BaseBuffer 
12   
13 -class ElementArrayBuffer(BaseBuffer):
14 _binding = "element_array_buffer_binding" 15 _target = _gl.GL_ELEMENT_ARRAY_BUFFER 16
17 - def set_data(self, data=None, shape=None, dtype=None, usage=None):
18 if data is not None: 19 data = coerce_array(data, dtype, force_integer=True, force_unsigned=True) 20 dtype = Datatype.from_numpy(data.dtype) 21 if dtype.is_signed() or not dtype.is_integer(): 22 raise TypeError("%s must be of unsigned integer type" % self.__class__.__name__) 23 super(ElementArrayBuffer, self).set_data(data, shape, dtype, usage)
24
25 - def draw(self, mode=None, count=None, first=0, instances=None):
26 if mode is None: 27 if len(self.shape) >= 2: 28 mode = buffer_dimensions_to_primitive.get(self.shape[-1], None) 29 if mode is None: 30 raise ValueError("must specify mode") 31 if count is None: 32 count = _np.prod(self.shape) 33 if instances is None: 34 with self: 35 _gl.glDrawElements(mode._value, count, self.dtype._as_gl(), first * self.dtype.nbytes) 36 else: 37 with self: 38 _gl.glDrawElementsInstanced(mode._value, count, self.dtype._as_gl(), first * self.dtype.nbytes, instances)
39 40 __all__ = ["ElementArrayBuffer"] 41