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 IndexedVertexDomain(
- context: SurfaceContextT,
- initial_count: int,
- attribute_meta: dict[str, AttributeFormat],
- index_type: Literal['f', 'i', 'I', 'h', 'H', 'b', 'B', 'q', 'Q', '?', 'd'] = 'I',
Management of a set of indexed vertex lists.
Construction of an indexed vertex domain is usually done with the
create_domain()function.- create( ) IndexedVertexListT
Create an
IndexedVertexListin this domain.
- deallocate_indices(start: int, count: int) None
Release an index range through the storage binding.
- Return type:
- 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.
- Parameters:
mode (
int) – AGeometryModevalue, such asPOINTSorLINES.- Return type:
- draw_subset(
- mode: GeometryMode,
- vertex_list: IndexedVertexListT,
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) – AGeometryModevalue, such asPOINTSorLINES.vertex_list (
TypeVar(IndexedVertexListT, bound=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 None
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.
Initialize an empty range collector.
- add_vertex_list(
- vl: IndexedVertexList,
- Return type:
- remove_vertex_list(
- vl: IndexedVertexList,
- Return type:
- class IndexedVertexList(
- domain: IndexedVertexDomain,
- group: Group | None,
- start: int,
- count: int,
- index_start: int,
- index_count: int,
A list of vertices within an
IndexedVertexDomainthat are indexed.Use
IndexedVertexDomain.create()to construct this list.- domain: IndexedVertexDomain
- class InstanceIndexedVertexList(
- domain: InstancedIndexedVertexDomain,
- group: Group | None,
- 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,
A list of vertices within an
IndexedVertexDomainthat are indexed.Use
IndexedVertexDomain.create()to construct this list.- create_instance(
- **attributes: Any,
- Return type:
- create_instance_collection( ) InstanceCollection
Create a bulk-managed collection without individual instance objects.
- Return type:
- create_instances( ) list[VertexInstance]
Create several instances with a single instance-buffer upload.
- Return type:
- 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:
- get_instance_index(
- instance: VertexInstance,
Get the current slot index for an instance.
- migrate(
- domain: VertexDomain,
- group: Group | None,
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|None) – 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_attribute_data( ) None
Replace one attribute over a contiguous range of instances.
- 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 InstanceVertexList(
- domain: InstancedVertexDomain,
- group: Group | None,
- start: int,
- count: int,
- bucket: InstanceBucket,
A list of vertices within an
InstancedVertexDomainthat are not indexed.- create_instance(
- **attributes: Any,
- Return type:
- create_instance_collection( ) InstanceCollection
Create a bulk-managed collection without individual instance objects.
- Return type:
- create_instances( ) list[VertexInstance]
Create several instances with a single instance-buffer upload.
- Return type:
- get_instance_by_index(
- index: int,
Get an instance by its current slot index.
- Return type:
- get_instance_index(
- instance: VertexInstance,
Get the current slot index for an instance.
- migrate(
- domain: VertexDomain,
- group: Group | None,
Move the geometry and its instance data to another domain.
- 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_attribute_data( ) None
Replace one attribute over a contiguous range of instances.
- 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
- instance_bucket: InstanceBucket
- class InstancedIndexedVertexDomain(
- context: SurfaceContextT,
- initial_count: int,
- attribute_meta: dict[str, AttributeFormat],
- 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( ) InstanceIndexedVertexListT
Create an
IndexedVertexListin this domain.
- class InstancedVertexDomain( ) None
- 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( ) InstanceVertexListT
Create a
VertexListin this domain.
- class VertexDomain( ) None
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( ) VertexListT
Create a
VertexListin this domain.
- dealloc_from_group(vertex_list)
Removes a vertex list from a specific state in this domain.
- deallocate_vertices(start: int, count: int) None
Release a vertex range through the storage binding.
- Return type:
- 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.
- Parameters:
mode (
int) – AGeometryModevalue, such asPOINTSorLINES.- Return type:
- abstractmethod draw_subset(
- mode: GeometryMode,
- vertex_list: VertexListT,
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) – AGeometryModevalue, such asPOINTSorLINES.vertex_list (
TypeVar(VertexListT, bound=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:
- get_vertex_input_binding(
- program: ShaderProgram,
Return a binding for
programover this domain’s geometry.Backends that support multiple VAOs override this. The base check is still useful to non-GL backends: a shader may consume a subset, but it may not require geometry that was never allocated.
- Return type:
VertexInputBinding|None
- safe_realloc(start: int, count: int, new_count: int) int
Reallocate vertices, resizing the buffers if necessary.
- Return type:
- set_shader_attributes(attributes: dict[str, Any]) None
Set the shader metadata used by this domain’s primary input binding.
- Return type:
- set_storage_binding(
- binding: VertexStorageBinding,
Attach the storage-owned streams and allocation resources for this domain.
- Return type:
- property allocator
Compatibility alias for this domain’s storage-owned vertex allocator.
- buffer_attributes: list[tuple[AttributeBufferObject, AttributeFormat]]
- property index_allocator
Compatibility alias for this domain’s storage-owned index allocator.
- mode: GeometryMode
- storage: VertexStorage
- vertex_buffers: VertexStream
- vertex_layout: VertexLayout
- vertex_stream: VertexStream
- class VertexGroupBucket None
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.
Initialize an empty range collector.
- class VertexList(
- domain: VertexDomain,
- group: Group | None,
- start: int,
- count: int,
A list of vertices within a
VertexDomain.Use
VertexDomain.create()to construct this list.- add_pass( ) None
Draw this geometry again in an additional
DrawPass.The additional registration owns no vertex storage. Its shader is validated against this list’s geometry and receives a VAO/input binding over the existing attribute buffers.
- Return type:
- draw(mode: GeometryMode) None
Draw this vertex list in the given OpenGL mode.
- Parameters:
mode (
GeometryMode) – AGeometryModevalue, such asPOINTSorLINES.- Return type:
- migrate(
- domain: VertexDomain,
- group: Group | None,
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|None) – The group this vertex list belongs to.
- Return type:
- set_attribute_constant( ) None
Fill an attribute with one value repeated over its allocated elements.
For example,
vertices.set_attribute_constant('translation', (x, y, z))updates every vertex’s translation without converting each repeated component from Python individually.This is useful for larger runs, as regular assignment can be faster for smaller vertex lists.
The value must contain exactly the attribute’s number of components. Integer values use the attribute’s storage type, including for normalized attributes.
Note
Only per-vertex attributes are supported.
- Return type:
- set_group(group: Group | None) None
Attach geometry to render state without moving its storage allocation.
- Return type:
- bucket: VertexGroupBucket | None
- domain: VertexDomain
- mode: GeometryMode