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

Management of a set of indexed vertex lists.

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

__init__(
attribute_meta: dict[str, dict[str, Any]],
index_gl_type: int = 5125,
) None
create(
count: int,
index_count: int,
) IndexedVertexList

Create an IndexedVertexList in this domain.

Parameters:
  • count (int) – Number of vertices to create

  • index_count (int) – Number of indices to create

Return type:

IndexedVertexList

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) – OpenGL drawing mode, e.g. GL_POINTS, GL_LINES, etc.

Return type:

None

draw_subset(
mode: int,
vertex_list: IndexedVertexList,
) 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:
  • mode (int) – OpenGL drawing mode, e.g. GL_POINTS, GL_LINES, etc.

  • vertex_list (IndexedVertexList) – Vertex list to draw.

Return type:

None

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_allocator: Allocator
index_buffer: IndexedBufferObject
index_c_type: Type[_SimpleCData]
index_element_size: int
index_gl_type: int
class IndexedVertexList

A list of vertices within an IndexedVertexDomain that are indexed.

Use IndexedVertexDomain.create() to construct this list.

__init__(
domain: IndexedVertexDomain,
start: int,
count: int,
index_start: int,
index_count: int,
) None
delete() None

Delete this group.

Return type:

None

migrate(
domain: IndexedVertexDomain | InstancedIndexedVertexDomain,
) None

Move this group from its current indexed domain and add to the specified one.

Attributes on domains must match. (In practice, used to change parent state of some vertices).

Parameters:

domain (IndexedVertexDomain | InstancedIndexedVertexDomain) – Indexed domain to migrate this vertex list to.

Return type:

None

set_instance_source(
domain: IndexedVertexDomain | InstancedIndexedVertexDomain,
instance_attributes: Sequence[str],
) None
Return type:

None

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

Array of index data.

class InstancedIndexedVertexDomain

Management of a set of indexed vertex lists.

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

__init__(
attribute_meta: dict[str, dict[str, Any]],
index_gl_type: int = 5125,
) None
create(
count: int,
index_count: int,
) IndexedVertexList

Create an IndexedVertexList in this domain.

Parameters:
  • count (int) – Number of vertices to create

  • index_count (int) – Number of indices to create

Return type:

IndexedVertexList

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) – OpenGL drawing mode, e.g. GL_POINTS, GL_LINES, etc.

Return type:

None

draw_subset(
mode: int,
vertex_list: IndexedVertexList,
) 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:
  • mode (int) – OpenGL drawing mode, e.g. GL_POINTS, GL_LINES, etc.

  • vertex_list (IndexedVertexList) – Vertex list to draw.

Return type:

None

safe_index_alloc(count: int) int

Allocate indices, resizing the buffers if necessary.

Return type:

int

Returns:

The starting index of the allocated region.

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

Reallocate indices, resizing the buffers if necessary.

Return type:

int

class InstancedVertexDomain
__init__(
attribute_meta: dict[str, dict[str, Any]],
) 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) – OpenGL drawing mode, e.g. GL_POINTS, GL_LINES, etc.

Return type:

None

draw_subset(
mode: int,
vertex_list: VertexList,
) 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:
  • mode (int) – OpenGL drawing mode, e.g. GL_POINTS, GL_LINES, etc.

  • vertex_list (VertexList) – Vertex list to draw.

Return type:

None

safe_alloc(count: int) int

Allocate vertices, resizing the buffers if necessary.

Return type:

int

safe_alloc_instance(count: int) int
Return type:

int

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

Reallocate vertices, resizing the buffers if necessary.

Return type:

int

instance_allocator: Allocator
property is_empty: bool
class VertexDomain

Management of a set of vertex lists.

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

__init__(attribute_meta: dict[str, dict[str, Any]]) None
create(
count: int,
index_count: int | None = None,
) VertexList

Create a VertexList in this domain.

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

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

Return type:

VertexList

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) – OpenGL drawing mode, e.g. GL_POINTS, GL_LINES, etc.

Return type:

None

draw_subset(
mode: int,
vertex_list: VertexList,
) 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:
  • mode (int) – OpenGL drawing mode, e.g. GL_POINTS, GL_LINES, etc.

  • vertex_list (VertexList) – Vertex list to draw.

Return type:

None

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

allocator: Allocator
attrib_name_buffers: dict[str, AttributeBufferObject]
attribute_meta: dict[str, dict[str, Any]]
attribute_names: dict[str, Attribute]
buffer_attributes: list[tuple[AttributeBufferObject, Attribute]]
property is_empty: bool
vao: VertexArray
class VertexInstance
__init__(
vertex_list: VertexList | IndexedVertexList,
instance_id: int,
start: int,
) None
delete() None
Return type:

None

property domain: InstancedVertexDomain | InstancedIndexedVertexDomain
id: int
start: int
class VertexList

A list of vertices within a VertexDomain.

Use VertexDomain.create() to construct this list.

__init__(
domain: VertexDomain,
start: int,
count: int,
) None
add_instance(
**kwargs: Any,
) VertexInstance
Return type:

VertexInstance

delete() None

Delete this group.

Return type:

None

delete_instance(
instance: VertexInstance,
) None
Return type:

None

draw(mode: int) None

Draw this vertex list in the given OpenGL mode.

Parameters:

mode (int) – OpenGL drawing mode, e.g. GL_POINTS, GL_LINES, etc.

Return type:

None

migrate(
domain: VertexDomain | InstancedVertexDomain,
) 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 | InstancedVertexDomain) – Domain to migrate this vertex list 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_data(name: str, data: Any) None
Return type:

None

set_instance_source(
domain: InstancedVertexDomain,
instance_attributes: Sequence[str],
) None
Return type:

None

count: int
domain: VertexDomain | InstancedVertexDomain
indexed: bool = False
initial_attribs: dict
instanced: bool = False
start: int