pygfx.resources.Buffer¶
- class pygfx.resources.Buffer(data=None, *, nbytes=None, nitems=None, format=None)¶
Bases:
Resource
A contiguous piece of GPU memory.
Buffers can be used as index buffer, vertex buffer, uniform buffer, or storage buffer. You can provide (and update data for it), or use it as a placeholder for a buffer with no representation on the CPU.
- Parameters:
data (array) – The initial data of the array data. It must support the buffer-protocol, (e.g. a bytes or numpy array). If None, nbytes and nitems must be provided.
nbytes (int) – The size of the buffer in bytes. Ignored if
data
is used.nitems (int) – The number of elements in the buffer. Ignored if
data
is used.format (str) – A format string describing the buffer layout when used as a vertex buffer. If None, this is automatically set from the data. This must be a pygfx format specifier, e.g. “3xf4”, but can also be a format specific to the render backend if necessary (e.g. from
wgpu.VertexFormat
).
- property rev¶
An integer that is increased when update_range() is called.
- property data¶
The data for this buffer. Can be None if the data only exists on the GPU.
Note: the data is the same reference that was given to instantiate this object, but this may change.
- property mem¶
The data for this buffer as a memoryview. Can be None if the data only exists on the GPU.
- property nbytes¶
The number of bytes in the buffer.
- property nitems¶
The number of items in the buffer.
- property itemsize¶
The number of bytes for a single item.
- property format¶
The buffer format.
Usually a pygfx format specifier (e.g. u2 for scalar uint16, or 3xf4 for 3xfloat32), but can also be a overridden to a backend-specific format. Can also be None e.g. for uniform buffers.
- property draw_range¶
The range to data (origin, size) expressed in items.
- update_range(offset=0, size=1125899906842624)¶
Mark a certain range of the data for upload to the GPU. The offset and size are expressed in integer number of elements.