Buffer#

class arcade.gl.Buffer(ctx: Context, data: Optional[Any] = None, reserve: int = 0, usage: str = 'static')[source]#

Bases: object

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.

Buffer objects should be created using arcade.gl.Context.buffer()

Parameters
  • ctx (Context) – The context this buffer belongs to

  • data (Any) – The data this buffer should contain. It can be bytes or any object supporting the buffer protocol.

  • reserve (int) – Create a buffer of a specific byte size

  • usage (str) – A hit of this buffer is static or dynamic (can mostly be ignored)

property size: int#

The byte size of the buffer.

Type

int

property ctx: Context#

The context this resource belongs to.

Type

arcade.gl.Context

property glo: ctypes.c_uint#

The OpenGL resource id

Type

gl.GLuint

delete()[source]#

Destroy the underlying OpenGL resource. Don’t use this unless you know exactly what you are doing.

static delete_glo(ctx: Context, glo: ctypes.c_uint)[source]#

Release/delete open gl buffer. This is automatically called when the object is garbage collected.

read(size: int = - 1, offset: int = 0) bytes[source]#

Read data from the buffer.

Parameters
  • size (int) – The bytes to read. -1 means the entire buffer (default)

  • offset (int) – Byte read offset

Return type

bytes

write(data: Any, offset: int = 0)[source]#

Write byte data to the buffer.

Parameters
  • data (bytes) – The byte data to write. This can be bytes or any object supporting the buffer protocol.

  • offset (int) – The byte offset

copy_from_buffer(source: arcade.gl.buffer.Buffer, size=- 1, offset=0, source_offset=0)[source]#

Copy data into this buffer from another buffer

Parameters
  • source (Buffer) – The buffer to copy from

  • size (int) – The amount of bytes to copy

  • offset (int) – The byte offset to write the data in this buffer

  • source_offset (int) – 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 (int) – New size of buffer. -1 will retain the current size.

  • double (bool) – Is passed in with True the buffer size will be doubled

bind_to_uniform_block(binding: int = 0, offset: int = 0, size: int = - 1)[source]#

Bind this buffer to a uniform block location. In most cases it will be sufficient to only provide a binding location.

Parameters
  • binding (int) – The binding location

  • offset (int) – byte offset

  • size (int) – size of the buffer to bind.

bind_to_storage_buffer(*, binding=0, offset=0, size=- 1)[source]#

Bind this buffer as a shader storage buffer.

Parameters
  • binding (int) – The binding location

  • offset (int) – Byte offset in the buffer

  • size (int) – The size in bytes. The entire buffer will be mapped by default.