This post from the numpy list shows you how to turn a ctypes c_void_p into a numpy array. The glMapBuffer() function maps your currently-bound array into a void * which you can access directly... combining the two:
def map_buffer( vbo, access=GL_READ_WRITE ): """Map the given buffer into a numpy array...""" func = ctypes.pythonapi.PyBuffer_FromMemory func.restype = ctypes.py_object vp = glMapBuffer( vbo.target, access ) buffer = func( ctypes.c_void_p(vp), vbo.size ) array = frombuffer( buffer, 'B' ) return array
You have to call vbo.bind() before you call map_buffer(), and you need to do a glUnmapBuffer() before you do vbo.unbind(). You can use array.view() to get a different data-type in the array, and reshape() to get a different data-shape. Will have to think about making a wrapped version of something like this available on the vbo objects, AFAIK only ctypes arrays and numpy arrays (of the current formats supported) will support this kind of behaviour, but even with those restrictions it might be useful.
Fixed an API bug in the glBufferData() calls as well (this post's code is from the test script for that), fix should show up in the next release.
Pingbacks are closed.