Buffer
- class arcade.gl.Buffer(ctx: Context, data: BufferProtocol | None = None, reserve: int = 0, usage: str = 'static')[source]
Bases:
OpenGL buffer object. Buffers store byte data and upload it to graphics memory so shader programs can process the data. They are used for storage of vertex data, element data (vertex indexing), uniform block data etc.
The
data
parameter can be anything that implements the Buffer Protocol.This includes
bytes
,bytearray
,array.array
, and more. You may need to use typing workarounds for non-builtin types. See Writing Raw Bytes to GL Buffers & Textures for more information.Warning
Buffer objects should be created using
arcade.gl.Context.buffer()
- Parameters:
ctx – The context this buffer belongs to
data – The data this buffer should contain. It can be a
bytes
instance or any object supporting the buffer protocol.reserve – Create a buffer of a specific byte size
usage – A hit of this buffer is
static
ordynamic
(can mostly be ignored)
- delete() None [source]
Destroy the underlying OpenGL resource.
Warning
Don’t use this unless you know exactly what you are doing.
- static delete_glo(ctx: Context, glo: gl.GLuint)[source]
Release/delete open gl buffer.
This is automatically called when the object is garbage collected.
- Parameters:
ctx – The context the buffer belongs to
glo – The OpenGL buffer id
- read(size: int = -1, offset: int = 0) bytes [source]
Read data from the buffer.
- Parameters:
size – The bytes to read. -1 means the entire buffer (default)
offset – Byte read offset
- write(data: ByteString | memoryview | array | Array, offset: int = 0)[source]
Write byte data to the buffer from a buffer protocol object.
The
data
value can be anything that implements the Buffer Protocol.This includes
bytes
,bytearray
,array.array
, and more. You may need to use typing workarounds for non-builtin types. See Writing Raw Bytes to GL Buffers & Textures for more information.If the supplied data is larger than the buffer, it will be truncated to fit. If the supplied data is smaller than the buffer, the remaining bytes will be left unchanged.
- Parameters:
data – The byte data to write. This can be bytes or any object supporting the buffer protocol.
offset – The byte offset
- copy_from_buffer(source: Buffer, size=-1, offset=0, source_offset=0)[source]
Copy data into this buffer from another buffer.
- Parameters:
source – The buffer to copy from
size – The amount of bytes to copy
offset – The byte offset to write the data in this buffer
source_offset – The byte offset to read from the source buffer
- orphan(size: int = -1, double: bool = False)[source]
Re-allocate the entire buffer memory. This can be used to resize a buffer or for re-specification (orphan the buffer to avoid blocking).
If the current buffer is busy in rendering operations it will be deallocated by OpenGL when completed.
- Parameters:
size – (optional) New size of buffer. -1 will retain the current size. Takes precedence over
double
parameter if specified.double (optional) – Is passed in with True the buffer size will be doubled from its current size.