Hide navigation sidebar
Hide table of contents sidebar
Back to top
Toggle table of contents sidebar

# Buffer

class Buffer

  Returned by `Context.buffer()`

  Buffer objects are OpenGL objects that store an array of unformatted memory allocated by the OpenGL context, (data allocated on the GPU).

  These can be used to store vertex data, pixel data retrieved from images or the framebuffer, and a variety of other things.

  A Buffer object cannot be instantiated directly, it requires a context. Use `Context.buffer()` to create one.

  Copy buffer content using `Context.copy_buffer()`.

## Methods

Buffer.write(data: Any, *, offset: int = 0) → None:

  Write the content.

  Parameters:

    - data (bytes) – The data.

    - offset (int) – The offset in bytes.

Buffer.read(size: int = -1, *, offset: int = 0) → bytes:

  Read the content.

  Parameters:

    - size (int) – The size in bytes. Value `-1` means all.

    - offset (int) – The offset in bytes.

Buffer.read_into(buffer: Any, size: int = -1, *, offset: int = 0, write_offset: int = 0) → None:

  Read the content into a buffer.

  Parameters:

    - buffer (bytearray) – The buffer that will receive the content.

    - size (int) – The size in bytes. Value `-1` means all.

    - offset (int) – The read offset in bytes.

    - write_offset (int) – The write offset in bytes.

Buffer.clear(size: int = -1, *, offset: int = 0, chunk: Any = None) → None:

  Clear the content.

  Parameters:

    - size (int) – The size. Value `-1` means all.

    - offset (int) – The offset.

    - chunk (bytes) – The chunk to use repeatedly.

Buffer.bind_to_uniform_block(binding: int = 0, *, offset: int = 0, size: int = -1) → None:

  Bind the buffer to a uniform block.

  Parameters:

    - binding (int) – The uniform block binding.

    - offset (int) – The offset.

    - size (int) – The size. Value `-1` means all.

Buffer.bind_to_storage_buffer(binding: int = 0, *, offset: int = 0, size: int = -1) → None:

  Bind the buffer to a shader storage buffer.

  Parameters:

    - binding (int) – The shader storage binding.

    - offset (int) – The offset.

    - size (int) – The size. Value `-1` means all.

Buffer.release() → None:

  Release the ModernGL object

Buffer.bind(*attribs, layout=None) → tuple:

  Helper method for binding a buffer in `Context.vertex_array()`.

Buffer.assign(index: int) → tuple:

  Helper method for assigning a buffer to an index in `Context.scope()`.

## Attributes

Buffer.size: int

  The size of the buffer in bytes.

Buffer.dynamic: bool

  The dynamic flag.

Buffer.ctx: Context

  The context this object belongs to

Buffer.glo: int

  The internal OpenGL object. This values is provided for interoperability and debug purposes only.

Buffer.extra: Any

  User defined data.