def __init__(self, size, chunk_size, ctype='float'): """Create a new buffer of n chunks. Parameters: size: number of chunks chunk_size: size of each chunk ctype: string of the C type to use (defaults to float) """ self.count = 0 # current number of chunks self.size = size # max number of chunks self.chunk_size = chunk_size # size of chunks self.ctype = ctype self.data = self._allocate(size) self.ctype_size = sizeof(self.data[0:1])
def load(self, data, size=None): """Data is cffi array""" self.bind() if size is None: # ffi's sizeof understands arrays size = sizeof(data) if size == self.buffer_size: # same size - no need to allocate new buffer, just copy glBufferSubData(self.array_type, 0, size, to_raw_pointer(data)) else: # buffer size has changed - need to allocate new buffer in the GPU glBufferData(self.array_type, size, to_raw_pointer(data), self.draw_type) self.buffer_size = size self.unbind()
def load(self, data, size=None): """Data is cffi array""" self.bind() if size is None: # ffi's sizeof understands arrays size = sizeof(data) if size == self.buffer_size: # same size - no need to allocate new buffer, just copy glBufferSubData( self.array_type, 0, size, to_raw_pointer(data) ) else: # buffer size has changed - need to allocate new buffer in the GPU glBufferData( self.array_type, size, to_raw_pointer(data), self.draw_type ) self.buffer_size = size self.unbind()