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',
) → None

Management of a set of indexed vertex lists.

Construction of an indexed vertex domain is usually done with the create_domain() function.

create(
group: Group | None,
count: int,
indices: Sequence[int] | None = None,
) → IndexedVertexListT

Create an IndexedVertexList in this domain.

Parameters:
  • group (Group | None) – The Group the resulting vertex list will be drawn with.

  • count (int) – Number of vertices to create

  • indices (Sequence[int] | None) – The indices used for this vertex list.

Return type:

TypeVar(IndexedVertexListT, bound= IndexedVertexList)

deallocate_indices(start: int, count: int) → None

Release an index range through the storage binding.

Return type:

None

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) – A GeometryMode value, such as POINTS or LINES.

Return type:

None

draw_subset(
mode: GeometryMode,
vertex_list: IndexedVertexListT,
) → None

Draw a specific IndexedVertexList in the domain.

The vertex_list parameter specifies a IndexedVertexList to draw. Only primitives in that list will be drawn.

Parameters:
Return type:

None

get_group_bucket(
group: Group,
) → VertexGroupBucket[IndexedVertexList]

Get a drawable bucket to assign vertex list information to a specific group.

Return type:

VertexGroupBucket[IndexedVertexList]

safe_index_alloc(count: int) → int

Allocate indices, resizing the buffers if necessary.

Return type:

int

safe_index_realloc(start: int, count: int, new_count: int) → int

Reallocate indices, resizing the buffers if necessary.

Return type:

int

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,
) → None
Return type:

None

remove_vertex_list(
vl: IndexedVertexList,
) → None
Return type:

None

class IndexedVertexList(
domain: IndexedVertexDomain,
group: Group | None,
start: int,
count: int,
index_start: int,
index_count: int,
) → None

A list of vertices within an IndexedVertexDomain that are indexed.

Use IndexedVertexDomain.create() to construct this list.

delete() → None

Delete this group.

Return type:

None

domain: IndexedVertexDomain
index_count: int
index_start: int
indexed: bool = True
property indices: list[int]

Array of index data.

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,
) → None

A list of vertices within an IndexedVertexDomain that are indexed.

Use IndexedVertexDomain.create() to construct this list.

create_instance(
**attributes: Any,
) → VertexInstance
Return type:

VertexInstance

create_instance_collection(
count: int,
capacity: int | None = None,
**attributes: Any,
) → InstanceCollection

Create a bulk-managed collection without individual instance objects.

Return type:

InstanceCollection

create_instances(
count: int,
**attributes: Any,
) → list[VertexInstance]

Create several instances with a single instance-buffer upload.

Return type:

list[VertexInstance]

dealloc_from_group(vertex_list)

Removes a vertex list from a specific state in this domain.

delete() → None

Delete this group.

Return type:

None

get_instance_by_index(
index: int,
) → VertexInstance | None

Get an instance by its current slot index.

Return type:

VertexInstance | None

get_instance_index(
instance: VertexInstance,
) → int | None

Get the current slot index for an instance.

Return type:

int | None

migrate(
domain: VertexDomain,
group: Group | None,
) → 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:

None

move_instance_to_index(
instance: VertexInstance,
index: int,
) → None

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:

None

move_to_back(
instances: Sequence[VertexInstance],
) → None

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:

None

move_to_top(
instances: Sequence[VertexInstance],
) → None

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:

None

set_attribute_data(name: str, data: Any) → None
Return type:

None

set_instance_attribute_data(
name: str,
data: Any,
start: int = 0,
count: int | None = None,
) → None

Replace one attribute over a contiguous range of instances.

Return type:

None

set_instance_order(
order: Sequence[VertexInstance],
) → None

Set the exact full order of all active instances.

This can be expensive for large lists.

Return type:

None

swap_instances(
first: VertexInstance,
second: VertexInstance,
) → None

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:

None

base_vertex: int
domain: InstancedIndexedVertexDomain
index_count: int
index_start: int
index_type: Literal['f', 'i', 'I', 'h', 'H', 'b', 'B', 'q', 'Q', '?', 'd']
indexed: bool = True
instance_bucket: InstanceBucket
property instance_count: int

Number of active instances in this vertex list.

instanced: bool = True
start_base_vertex: int
supports_base_vertex: bool = False
class InstanceVertexList(
domain: InstancedVertexDomain,
group: Group | None,
start: int,
count: int,
bucket: InstanceBucket,
) → None

A list of vertices within an InstancedVertexDomain that are not indexed.

create_instance(
**attributes: Any,
) → VertexInstance
Return type:

VertexInstance

create_instance_collection(
count: int,
capacity: int | None = None,
**attributes: Any,
) → InstanceCollection

Create a bulk-managed collection without individual instance objects.

Return type:

InstanceCollection

create_instances(
count: int,
**attributes: Any,
) → list[VertexInstance]

Create several instances with a single instance-buffer upload.

Return type:

list[VertexInstance]

delete() → None

Delete this vertex list and its instance storage.

Return type:

None

get_instance_by_index(
index: int,
) → VertexInstance | None

Get an instance by its current slot index.

Return type:

VertexInstance | None

get_instance_index(
instance: VertexInstance,
) → int | None

Get the current slot index for an instance.

Return type:

int | None

migrate(
domain: VertexDomain,
group: Group | None,
) → None

Move the geometry and its instance data to another domain.

Return type:

None

move_instance_to_index(
instance: VertexInstance,
index: int,
) → None

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:

None

move_to_back(
instances: Sequence[VertexInstance],
) → None

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:

None

move_to_top(
instances: Sequence[VertexInstance],
) → None

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:

None

set_attribute_data(name: str, data: Any) → None
Return type:

None

set_instance_attribute_data(
name: str,
data: Any,
start: int = 0,
count: int | None = None,
) → None

Replace one attribute over a contiguous range of instances.

Return type:

None

set_instance_order(
order: Sequence[VertexInstance],
) → None

Set the exact full order of all active instances.

This can be expensive for large lists.

Return type:

None

swap_instances(
first: VertexInstance,
second: VertexInstance,
) → None

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:

None

domain: InstancedVertexDomain
instance_bucket: InstanceBucket
property instance_count: int

Number of active instances in this vertex list.

instanced: bool = True
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',
) → 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(
group: Group | None,
count: int,
indices: Sequence[int] | None = None,
) → InstanceIndexedVertexListT

Create an IndexedVertexList in this domain.

Parameters:
  • group (Group | None) – The Group the resulting vertex list will be drawn with.

  • count (int) – Number of vertices to create

  • indices (Sequence[int] | None) – Indices used for this vertex list.

Return type:

TypeVar(InstanceIndexedVertexListT, bound= InstanceIndexedVertexList)

abstractmethod create_instance_domain(
size: int,
) → InstanceDomain
Return type:

InstanceDomain

class InstancedVertexDomain(
context: SurfaceContextT,
initial_count: int,
attribute_meta: dict[str, AttributeFormat],
) → 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(
group: Group | None,
count: int,
indices: Sequence[int] | None = None,
) → InstanceVertexListT

Create a VertexList in this domain.

Parameters:
  • group (Group | None) – The Group the resulting vertex list will be drawn with.

  • count (int) – Number of vertices to create.

  • indices (Sequence[int] | None) – Ignored for non indexed VertexDomains

Return type:

TypeVar(InstanceVertexListT, bound= InstanceVertexList)

abstractmethod create_instance_domain(
size: int,
) → InstanceDomain
Return type:

InstanceDomain

class VertexDomain(
context: SurfaceContextT,
initial_count: int,
attribute_meta: dict[str, AttributeFormat],
) → 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,
) → VertexGroupBucket

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:

VertexGroupBucket

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:

None

create(
group: Group | None,
count: int,
indices: Sequence[int] | None = None,
) → VertexListT

Create a VertexList in this domain.

Parameters:
  • group (Group | None) – The Group the resulting vertex list will be drawn with.

  • count (int) – Number of vertices to create.

  • indices (Sequence[int] | None) – Ignored for non indexed VertexDomains

Return type:

TypeVar(VertexListT, bound= VertexList)

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:

None

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) – A GeometryMode value, such as POINTS or LINES.

Return type:

None

abstractmethod draw_subset(
mode: GeometryMode,
vertex_list: VertexListT,
) → None

Draw a specific VertexList in the domain.

The vertex_list parameter specifies a VertexList to draw. Only primitives in that list will be drawn.

Parameters:
Return type:

None

get_drawable_bucket(
group: Group,
) → VertexGroupBucket | None

Get a bucket that exists and has vertices to draw (not empty).

Return type:

VertexGroupBucket | None

get_vertex_input_binding(
program: ShaderProgram,
) → VertexInputBinding | None

Return a binding for program over 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

has_bucket(group: Group) → bool
Return type:

bool

safe_alloc(count: int) → int

Allocate vertices, resizing the buffers if necessary.

Return type:

int

safe_realloc(start: int, count: int, new_count: int) → int

Reallocate vertices, resizing the buffers if necessary.

Return type:

int

set_shader_attributes(attributes: dict[str, Any]) → None

Set the shader metadata used by this domain’s primary input binding.

Return type:

None

set_storage_binding(
binding: VertexStorageBinding,
) → None

Attach the storage-owned streams and allocation resources for this domain.

Return type:

None

property allocator

Compatibility alias for this domain’s storage-owned vertex allocator.

attrib_name_buffers: dict[str, VertexStream | InstanceStream]
attribute_meta: dict[str, AttributeFormat]
batch: Batch
buffer_attributes: list[tuple[AttributeBufferObject, AttributeFormat]]
property index_allocator

Compatibility alias for this domain’s storage-owned index allocator.

property is_empty: bool

If the domain has no vertices.

mode: GeometryMode
per_instance: list[AttributeFormat]
per_vertex: list[AttributeFormat]
shader_attributes: dict[str, Any]
storage: VertexStorage
vao: VertexArrayBinding | None
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.

add_vertex_list(
vl: _VertexListT,
) → None
Return type:

None

remove_vertex_list(
vl: _VertexListT,
) → None
Return type:

None

is_dirty: bool
class VertexList(
domain: VertexDomain,
group: Group | None,
start: int,
count: int,
) → None

A list of vertices within a VertexDomain.

Use VertexDomain.create() to construct this list.

add_pass(
draw_pass: DrawPass,
*,
group: Group,
) → 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:

None

delete() → None

Delete this group.

Return type:

None

draw(mode: GeometryMode) → None

Draw this vertex list in the given OpenGL mode.

Parameters:

mode (GeometryMode) – A GeometryMode value, such as POINTS or LINES.

Return type:

None

migrate(
domain: VertexDomain,
group: Group | None,
) → 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:

None

resize(count: int, index_count: int | None = None) → None

Resize this group.

Parameters:
  • count (int) – New number of vertices in the list.

  • index_count (int | None) – Ignored for non indexed VertexDomains

Return type:

None

set_attribute_constant(
name: str,
value: Sequence[float | int | bool],
) → 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:

None

set_attribute_data(name: str, data: Any) → None
Return type:

None

set_group(group: Group | None) → None

Attach geometry to render state without moving its storage allocation.

Return type:

None

update_group(group: Group) → None

Compatibility wrapper for changing render state.

Return type:

None

bucket: VertexGroupBucket | None
count: int
domain: VertexDomain
group: Group | None
indexed: bool = False
initial_attribs: dict
instanced: bool = False
mode: GeometryMode
start: int