1 """Array buffer class.
2
3 @todo: Implement slicing to allow for C{glVertexAttribPointer} with C{size}, C{stride}, and C{pointer} parameters.
4
5 @author: Stephan Wenger
6 @date: 2012-02-29
7 """
8
9 import numpy as _np
10
11 import glitter.raw as _gl
12 from glitter.utils import buffer_dimensions_to_primitive, primitive_to_buffer_dimensions
13 from glitter.arrays.basebuffer import BaseBuffer
14
16 _binding = "array_buffer_binding"
17 _target = _gl.GL_ARRAY_BUFFER
18
19 - def _use(self, index, num_components=None, stride=0, first=0):
33
34 - def draw(self, mode=None, count=None, first=0, instances=None):
35 if mode is None:
36 if len(self.shape) > 2:
37 mode = buffer_dimensions_to_primitive.get(self.shape[1], None)
38 else:
39 mode = buffer_dimensions_to_primitive.get(1, None)
40 if mode is None:
41 raise ValueError("must specify mode")
42
43 if count is None:
44 dim = primitive_to_buffer_dimensions.get(mode, None)
45 if dim is not None and len(self.shape) > 2 and self.shape[-2] != dim:
46 raise ValueError("buffer shape does not match mode")
47 count = _np.prod(self.shape[:-1])
48
49 if instances is None:
50 with self:
51 _gl.glDrawArrays(mode._value, first, count)
52 else:
53 with self:
54 _gl.glDrawArraysInstances(mode._value, first, count, instances)
55
56 __all__ = ["ArrayBuffer"]
57