Working with OpenGL often needs the use of large buffer (like textures, vbos, etc).
It is often more convenient and efficient to work with such buffers using other modules such as numpy, array, or ctypes.
When starting a bgl.Buffer, reading and copying large buffers, even more as a sequence, is inefficient and may even freeze the execution of a code for an inconvenient time.
This patch allows to access the buffer of an object with buffer interface, directly and without intermediate copying.
>>> import numpy as np >>> import bgl >>> a = np.arange(10, dtype = 'i4') >>> buf = bgl.Buffer(bgl.GL_INT, a.shape, a) >>> buf Buffer(GL_INT, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> a = 10 >>> buf Buffer(GL_INT, [10, 1, 2, 3, 4, 5, 6, 7, 8, 9])