def copy_data_to_pbo(pbo, data, *, mapped_array=None):
    'Allocate or update data stored in a pixel buffer object'
    (width, height) = data.shape
    with bind(pbo):
        if (pbo.isCreated() and (mapped_array is not None)):
            mapped_array[:] = data.reshape((width, height))
            return mapped_array
    full_size = data.nbytes
    pointer_type = np.ctypeslib.ndpointer(dtype=data.dtype, shape=(width, height), ndim=data.ndim)
    pbo.create()
    with bind(pbo):
        pbo.allocate(data, full_size)
        ptr = pbo.map(QOpenGLBuffer.WriteOnly)
        assert (ptr is not None), 'Failed to map pixel buffer array'
        pointer_type = np.ctypeslib.ndpointer(dtype=data.dtype, shape=(width, height), ndim=data.ndim)
        mapped_array = np.ctypeslib.as_array(pointer_type(int(ptr)))
        pbo.unmap()
        mapped_array[:] = data.reshape((width, height))
    return mapped_array
Allocate or update data stored in a pixel buffer object
def copy_data_to_pbo(pbo, data, *, mapped_array=None):
    
    (width, height) = data.shape
    with bind(pbo):
        if (pbo.isCreated() and (mapped_array is not None)):
            mapped_array[:] = data.reshape((width, height))
            return mapped_array
    full_size = data.nbytes
    pointer_type = np.ctypeslib.ndpointer(dtype=data.dtype, shape=(width, height), ndim=data.ndim)
    pbo.create()
    with bind(pbo):
        pbo.allocate(data, full_size)
        ptr = pbo.map(QOpenGLBuffer.WriteOnly)
        assert (ptr is not None), 'Failed to map pixel buffer array'
        pointer_type = np.ctypeslib.ndpointer(dtype=data.dtype, shape=(width, height), ndim=data.ndim)
        mapped_array = np.ctypeslib.as_array(pointer_type(int(ptr)))
        pbo.unmap()
        mapped_array[:] = data.reshape((width, height))
    return mapped_array