pyglet.graphics.vertexdomain
Manage related vertex attributes within a single vertex domain.
A vertex “domain” consists of a set of attribute descriptions that together describe the layout of one or more vertex buffers which are used together to specify the vertices in a primitive. Additionally, the domain manages the buffers used to store the data and will resize them as necessary to accommodate new vertices.
Domains can optionally be indexed, in which case they also manage a buffer containing vertex indices. This buffer is grown separately and has no size relation to the attribute buffers.
Applications can create vertices (and optionally, indices) within a domain
with the VertexDomain.create() method. This returns a
VertexList representing the list of vertices created. The vertex
attribute data within the group can be modified, and the changes will be made
to the underlying buffers automatically.
The entire domain can be efficiently drawn in one step with the
VertexDomain.draw() method, assuming all the vertices comprise
primitives of the same OpenGL primitive mode.
- class IndexStream
A container to manage an index buffer for a domain.
- __init__( )
Initialize the stream and create an allocator.
- Parameters:
size – Initial allocator and buffer size.
- class IndexedVertexDomain
Management of a set of indexed vertex lists.
Construction of an indexed vertex domain is usually done with the
create_domain()function.- __init__(
- context: SurfaceContext,
- initial_count: int,
- attribute_meta: dict[str, Attribute],
- index_type: Literal['f', 'i', 'I', 'h', 'H', 'b', 'B', 'q', 'Q', '?', 'd'] = 'I',
- create( ) IndexedVertexList
Create an
IndexedVertexListin this domain.
- draw(mode: int) None
Draw all vertices in the domain.
All vertices in the domain are drawn at once. This is the most efficient way to render primitives.
- draw_subset(
- mode: GeometryMode,
- vertex_list: IndexedVertexList,
Draw a specific IndexedVertexList in the domain.
The vertex_list parameter specifies a
IndexedVertexListto draw. Only primitives in that list will be drawn.- Parameters:
mode (
GeometryMode) – OpenGL drawing mode, e.g.GL_POINTS,GL_LINES, etc.vertex_list (
IndexedVertexList) – Vertex list to draw.
- Return type:
- get_group_bucket(
- group: Group,
Get a drawable bucket to assign vertex list information to a specific group.
- Return type:
- safe_index_realloc(start: int, count: int, new_count: int) int
Reallocate indices, resizing the buffers if necessary.
- Return type:
- index_stream: IndexStream
- class IndexedVertexGroupBucket
A grouping of indexed vertex lists belonging to a single group in a domain.
Vertex lists are still owned by the domain, but this allows states to be rendered together if possible.
- add_vertex_list(
- vl: IndexedVertexList,
- Return type:
- remove_vertex_list(
- vl: IndexedVertexList,
- Return type:
- class IndexedVertexList
A list of vertices within an
IndexedVertexDomainthat are indexed.Use
IndexedVertexDomain.create()to construct this list.- __init__(
- domain: IndexedVertexDomain,
- group: Group,
- start: int,
- count: int,
- index_start: int,
- index_count: int,
- domain: IndexedVertexDomain
- class InstanceIndexedVertexList
A list of vertices within an
IndexedVertexDomainthat are indexed.Use
IndexedVertexDomain.create()to construct this list.- __init__(
- domain: InstancedIndexedVertexDomain,
- group: Group,
- start: int,
- count: int,
- index_start: int,
- index_count: int,
- index_type: Literal['f', 'i', 'I', 'h', 'H', 'b', 'B', 'q', 'Q', '?', 'd'],
- base_vertex: int,
- instance_bucket: InstanceBucket,
- dealloc_from_group(vertex_list)
Removes a vertex list from a specific state in this domain.
- get_instance_by_index(
- index: int,
Get an instance by its current slot index.
- Return type:
VertexInstance|None
- get_instance_index(
- instance: VertexInstance,
Get the current slot index for an instance.
- migrate(
- domain: InstancedIndexedVertexDomain,
- group: Group,
Move this group from its current domain and add to the specified one.
Attributes on domains must match. (In practice, used to change parent state of some vertices).
- Parameters:
domain (
InstancedIndexedVertexDomain) – Domain to migrate this vertex list to.group (
Group) – The group this vertex list belongs to.
- Return type:
- move_instance_to_index(
- instance: VertexInstance,
- index: int,
Move one instance to a target slot index.
Other instances shift as needed to keep slots contiguous. This may be expensive when moving across many slots.
- Return type:
- move_to_back(
- instances: Sequence[VertexInstance],
Move a subset of instances to the back in the given order.
Back means lower indices (drawn earlier). Unspecified instances remain after the moved prefix. This can be expensive for large lists.
- Return type:
- move_to_top(
- instances: Sequence[VertexInstance],
Move a subset of instances to the top in the given order.
Top means higher indices (drawn later). Unspecified instances remain before the moved suffix. This can be expensive for large lists.
- Return type:
- set_instance_order(
- order: Sequence[VertexInstance],
Set the exact full order of all active instances.
This can be expensive for large lists.
- Return type:
- swap_instances(
- first: VertexInstance,
- second: VertexInstance,
Swap two instances in-place.
Useful when changing draw order without rebuilding all instance data. This can still be expensive if instance attributes are large.
- Return type:
- domain: InstancedIndexedVertexDomain
- instance_bucket: InstanceBucket
- class InstanceStream
Handles a stream of buffers to be used with the per-instance attributes.
- class InstanceVertexList
A list of vertices within an
InstancedVertexDomainthat are not indexed.- __init__(
- domain: VertexDomain,
- group: Group,
- start: int,
- count: int,
- bucket: InstanceBucket,
- get_instance_by_index(
- index: int,
Get an instance by its current slot index.
- Return type:
VertexInstance|None
- get_instance_index(
- instance: VertexInstance,
Get the current slot index for an instance.
- move_instance_to_index(
- instance: VertexInstance,
- index: int,
Move one instance to a target slot index.
Other instances shift as needed to keep slots contiguous. This may be expensive when moving across many slots.
- Return type:
- move_to_back(
- instances: Sequence[VertexInstance],
Move a subset of instances to the back in the given order.
Back means lower indices (drawn earlier). Unspecified instances remain after the moved prefix. This can be expensive for large lists.
- Return type:
- move_to_top(
- instances: Sequence[VertexInstance],
Move a subset of instances to the top in the given order.
Top means higher indices (drawn later). Unspecified instances remain before the moved suffix. This can be expensive for large lists.
- Return type:
- set_instance_order(
- order: Sequence[VertexInstance],
Set the exact full order of all active instances.
This can be expensive for large lists.
- Return type:
- swap_instances(
- first: VertexInstance,
- second: VertexInstance,
Swap two instances in-place.
Useful when changing draw order without rebuilding all instance data. This can still be expensive if instance attributes are large.
- Return type:
- domain: InstancedVertexDomain
- class InstancedIndexedVertexDomain
- __init__(
- context: SurfaceContext,
- initial_count: int,
- attribute_meta: dict[str, Attribute],
- index_type: Literal['f', 'i', 'I', 'h', 'H', 'b', 'B', 'q', 'Q', '?', 'd'] = 'I',
- alloc_to_group(vertex_list, group)
Assigns a vertex list to a specific state in this domain.
A state bucket does not allocate any vertices or allocates any GPU resources, it is simply to track the data required for drawing in a specific state.
- Parameters:
vertex_list – The vertex list to allocate.
group – The group affecting the vertices.
- Returns:
The new state bucket object.
- bind_vao()
Binds the VAO as well as commit any pending buffer changes to the GPU.
- create( ) InstanceIndexedVertexList
Create an
IndexedVertexListin this domain.
- class InstancedVertexDomain
-
- alloc_to_group(vertex_list, group)
Assigns a vertex list to a specific state in this domain.
A state bucket does not allocate any vertices or allocates any GPU resources, it is simply to track the data required for drawing in a specific state.
- Parameters:
vertex_list – The vertex list to allocate.
group – The group affecting the vertices.
- Returns:
The new state bucket object.
- bind_vao()
Binds the VAO as well as commit any pending buffer changes to the GPU.
- create( ) VertexList
Create a
VertexListin this domain.
- class Stream
A container that handles a set of buffers to be used with domains.
- __init__(size: int) None
Initialize the stream and create an allocator.
- Parameters:
size (
int) – Initial allocator and buffer size.
- abstractmethod bind_into(vao) None
Record this stream into the VAO.
The VAO should be bound before this function is called.
- Return type:
- realloc(start: int, count: int, new_count: int) int
Reallocate a region of data, resizing the buffers if necessary.
- Return type:
- class VertexArrayBinding
A wrapper for a Vertex Array Object that binds streams.
VAO’s store which attribute layouts are used, as well as which buffer object each attribute pulls from.
In the case of instanced drawing, each instance needs its own VAO as their per-instance data are separate buffers.
- __init__(
- ctx: SurfaceContext,
- streams: list[VertexStream | InstanceStream | IndexStream],
- bind()
- streams: list[VertexStream | InstanceStream | IndexStream]
- class VertexDomain
Management of a set of vertex lists.
Construction of a vertex domain is usually done with the
create_domain()function.- alloc_to_group(
- vertex_list,
- group,
Assigns a vertex list to a specific state in this domain.
A state bucket does not allocate any vertices or allocates any GPU resources, it is simply to track the data required for drawing in a specific state.
- Parameters:
vertex_list – The vertex list to allocate.
group – The group affecting the vertices.
- Return type:
- Returns:
The new state bucket object.
- bind_vao() None
Binds the VAO as well as commit any pending buffer changes to the GPU.
- Return type:
- create( ) VertexList
Create a
VertexListin this domain.
- dealloc_from_group(vertex_list)
Removes a vertex list from a specific state in this domain.
- abstractmethod draw(mode: int) None
Draw all vertices in the domain.
All vertices in the domain are drawn at once. This is the most efficient way to render primitives.
- abstractmethod draw_subset(
- mode: GeometryMode,
- vertex_list: VertexList,
Draw a specific VertexList in the domain.
The vertex_list parameter specifies a
VertexListto draw. Only primitives in that list will be drawn.- Parameters:
mode (
GeometryMode) – OpenGL drawing mode, e.g.GL_POINTS,GL_LINES, etc.vertex_list (
VertexList) – Vertex list to draw.
- Return type:
- get_drawable_bucket(
- group: Group,
Get a bucket that exists and has vertices to draw (not empty).
- Return type:
- safe_realloc(start: int, count: int, new_count: int) int
Reallocate vertices, resizing the buffers if necessary.
- Return type:
- attrib_name_buffers: dict[str, VertexStream | InstanceStream]
- property attribute_names
- buffer_attributes: list[tuple[AttributeBufferObject, Attribute]]
- vertex_stream: VertexStream
- class VertexGroupBucket
A grouping of vertex lists belonging to a single group in a domain.
Vertex lists are still owned by the domain, but this allows states to be rendered together if possible.
- add_vertex_list(
- vl: VertexList,
- Return type:
- remove_vertex_list(
- vl: VertexList,
- Return type:
- class VertexList
A list of vertices within a
VertexDomain.Use
VertexDomain.create()to construct this list.- draw(mode: GeometryMode) None
Draw this vertex list in the given OpenGL mode.
- Parameters:
mode (
GeometryMode) – OpenGL drawing mode, e.g.GL_POINTS,GL_LINES, etc.- Return type:
- migrate(
- domain: VertexDomain,
- group: Group,
Move this group from its current domain and add to the specified one.
Attributes on domains must match. (In practice, used to change parent state of some vertices).
- Parameters:
domain (
VertexDomain) – Domain to migrate this vertex list to.group (
Group) – The group this vertex list belongs to.
- Return type:
- domain: VertexDomain
- class VertexStream
A stream of buffers to be used with per-vertex attributes.
- __init__( )
Initialize the stream and create an allocator.
- Parameters:
size – Initial allocator and buffer size.
- copy_data(
- dst_slot: int,
- dst_stream: VertexStream | InstanceStream,
- src_slot: int,
- count: int = 1,
- attrs: Iterable[str] | None = None,
- *,
- strict: bool = False,
- Return type:
- get_buffer(size, attribute)
- get_graphics_attribute(
- attribute: Attribute,
- view: AttributeView,
- Return type:
- attrib_name_buffers: dict[str, AttributeBufferObject]