pyglet.graphics.vertexbuffer
Shared GPU buffer abstractions.
AbstractBuffer models a GPU byte buffer. It intentionally has no knowledge of ctypes element formats or shader attribute data types.
Typed host-side data is provided by BufferDataStore implementations. The default store is CTypeDataStore, but other stores can be created later such as JS for WebGL or even Numpy.
- class AbstractBuffer
A backend GPU buffer represented as bytes.
- abstractmethod get_bytes_region(offset: int, length: int) bytes
Read a byte-range from the buffer.
- Return type:
- get_data_region(start: int, length: int) bytes
Compatibility helper for callers that expect get_data_region.
- Return type:
- abstractmethod set_bytes(data: bytes | bytearray | memoryview) None
Replace the entire buffer contents from bytes.
- Return type:
- abstractmethod set_bytes_region(
- offset: int,
- data: bytes | bytearray | memoryview,
Write bytes into a sub-range of the buffer.
- Return type:
- set_data(
- data: Sequence[int] | _Pointer | bytes | bytearray | memoryview,
Compatibility helper for callers that expect set_data.
- Return type:
- set_data_ptr(offset: int, length: int, ptr: _Pointer) None
Compatibility helper for callers that pass a ctypes pointer.
- Return type:
- class AttributeBufferObject
A backed buffer used for shader attributes.
- class BackedBufferObject
A GPU buffer that keeps data on the host.
- __init__(
- size: int,
- store: BufferDataStore,
- abstractmethod commit() None
Commits all saved changes to the underlying GPU buffer before drawing.
Allows submitting multiple changes at once, rather than having to call glBufferSubData for every change.
- Return type:
- set_bytes(data: bytes | bytearray | memoryview) None
Replace the entire buffer contents from bytes.
- Return type:
- set_bytes_region(
- offset: int,
- data: bytes | bytearray | memoryview,
Write bytes into a sub-range of the buffer.
- Return type:
- store: BufferDataStore
- class BufferBindingSlice
BufferBindingSlice(offset: ‘int’, size: ‘int’)
- class BufferDataStore
Host-side data store used by BackedBufferObject.
- abstractmethod copy_region(dst: int, src: int, count: int) None
Copy a typed region inside the store.
- Return type:
- abstractmethod get_bytes(offset: int = 0, length: int | None = None) bytes
Get raw bytes from the store.
- Return type:
- abstractmethod set_bytes(offset: int, data: bytes | bytearray | memoryview) None
Write raw bytes into the store.
- Return type:
- class BufferRange
BufferRange(offset: ‘int’, size: ‘int’, in_use: ‘bool’ = False, frame_use_count: ‘int’ = 0)
- class CTypeDataStore
ctypes-based BufferDataStore.
This is the default host-side data store and keeps data in a ctypes array.
- __init__(
- size: int,
- data_type: Literal['f', 'i', 'I', 'h', 'H', 'b', 'B', 'q', 'Q', '?', 'd'],
- stride: int,
- element_count: int,
- data_ptr: int | None = None,
Create a ctypes-backed typed data store.
- Parameters:
size (
int) – Total byte size for the store.data_type (
Literal['f','i','I','h','H','b','B','q','Q','?','d']) – Struct-format data type code (for example"f"or"I") used to determine the underlying ctypes type and element size.stride (
int) – Byte stride for one logical element in this buffer layout.element_count (
int) – Number of scalar values per logical element.data_ptr (
int|None) – Optional pointer to externally owned memory. When provided, this store binds to that memory instead of allocating its own ctypes array.
Note
The
_owns_memoryflag indicates whether this store allocated its own backing array (True) or is bound to external memory (False). This is used to protectresize: externally backed stores cannot reallocate memory and must be rebound withrebind_external.
- copy_region(dst: int, src: int, count: int) None
Copy a typed region inside the store.
- Return type:
- get_bytes(offset: int = 0, length: int | None = None) bytes
Get raw bytes from the store.
- Return type:
- rebind_external(size: int, data_ptr: int) None
Rebind this store to a new externally-owned memory region.
- Return type:
- set_bytes(offset: int, data: bytes | bytearray | memoryview) None
Write raw bytes into the store.
- Return type:
- class DrawIndirectBuffer
Backend-agnostic draw indirect buffer.
- class IndexedBindingBuffer
Backend-agnostic role for buffers that support indexed binding points.
- class IndexedBufferObject
A backed buffer used for indices.
- class MappedBufferObject
A GPU buffer that supports map/unmap and range mapping.
- class PersistentBufferObject
A persistently mapped GPU buffer.
Available in OpenGL 4.3+ contexts. Persistently mapped buffers are mapped one time on creation, and can be updated at any time without the need to map or unmap.
- class PixelBuffer
Backend-agnostic pixel transfer buffer.
- class PixelPackBuffer
Backend-agnostic pixel pack buffer.
- class PixelUnpackBuffer
Backend-agnostic pixel unpack buffer.
- class RingBuffer
Generic ring allocator.
Range lifetime is tracked by owners such as
FrameResourceManagerby settingBufferRange.in_use. This allocator only selects writable ranges.- __init__(
- *,
- range_size: int,
- alignment: int = 1,
- copies_per_resource: int = 3,
- strict: bool = False,
- start_offset: int = 0,
- acquire_writable_slice() tuple[BufferBindingSlice, BufferRange]
- Return type:
- acquire_writable_slice_from_ranges(
- ranges: list[BufferRange],
- next_range_index: int,
- Return type:
- reserve_resource_range( ) list[BufferRange]
- Return type:
- class ShaderStorageBuffer
Backend-agnostic shader storage buffer.
- class TextureBuffer
Backend-agnostic texture buffer.
- class TransformFeedbackBuffer
Backend-agnostic transform feedback buffer.
- __init__( ) None
Create a transform feedback buffer view.
- Parameters:
size (
int) – The buffer size in bytes.data_type (
Literal['f','i','I','h','H','b','B','q','Q','?','d']) – Preferred format used by helper methodget_data(), defaults to"b"for bytes.
- class UniformBufferObject
Backend-agnostic Uniform Buffer Object wrapper.
- __init__(
- context: Any,
- view_class: type[Structure],
- buffer_size: int,
- binding: int,
- *,
- alignment: int = 1,
- copies_per_resource: int = 3,
- strict: bool = False,
- bind_slice(
- binding: BufferBindingSlice,
- *,
- binding_index: int | None = None,
- Return type:
- upload_to_available_binding(
- resource_data: Structure,
- Return type:
- upload_to_available_binding_from_ranges(
- resource_data: Structure,
- ranges: list[BufferRange],
- next_range_index: int,
- Return type:
- use_range(range_: BufferRange) None
- Return type:
- buffer: AbstractBuffer
- class UniformBufferRegion
UBO region that uploads through a ring-buffered
UniformBufferObject.The region owns one CPU-side data structure and a set of GPU ranges.
General practice is to update the data structure, mark it dirty, and then commit when you are done updating for that frame.
Warning
Do not make the CPU-side data dirty after binding/committing during the same frame (for example, during the
on_drawcall), or GPU stalls may occur.Added in version 3.0.
- __init__(
- ubo: UniformBufferObject,
- *,
- copies_per_resource: int | None = None,
- bind(*, binding_index: int | None = None) None
Upload dirty data if needed, then bind the current GPU range.
- Return type:
- data
- property ubo: UniformBufferObject
The underlying
UniformBufferObject.