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(attribute_usages, index_gl_type=5125)

Management of a set of indexed vertex lists.

Construction of an indexed vertex domain is usually done with the create_indexed_domain function.

create(count, index_count)

Create an IndexedVertexList in this domain.

Parameters:
  • count (int) – Number of vertices to create
  • index_count – Number of indices to create
draw(mode, vertex_list=None)

Draw vertices in the domain.

If vertex_list is not specified, all vertices in the domain are drawn. This is the most efficient way to render primitives.

If vertex_list specifies a VertexList, 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, or None for all lists in this domain.
get_index_region(start, count)

Get a region of the index buffer.

Parameters:
  • start (int) – Start of the region to map.
  • count (int) – Number of indices to map.
Return type:

Array of int

class IndexedVertexList(domain, start, count, index_start, index_count)

A list of vertices within an IndexedVertexDomain that are indexed. Use IndexedVertexDomain.create() to construct this list.

delete()

Delete this group.

draw(mode)

Draw this vertex list in the given OpenGL mode.

Parameters:mode (int) – OpenGL drawing mode, e.g. GL_POINTS, GL_LINES, etc.
migrate(domain)

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) – Indexed domain to migrate this vertex list to.
resize(count, index_count)

Resize this group.

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

Array of index data.

class VertexDomain(attribute_usages)

Management of a set of vertex lists.

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

create(count)

Create a VertexList in this domain.

Parameters:count (int) – Number of vertices to create.
Return type:VertexList
draw(mode, vertex_list=None)

Draw vertices in the domain.

If vertex_list is not specified, all vertices in the domain are drawn. This is the most efficient way to render primitives.

If vertex_list specifies a VertexList, 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, or None for all lists in this domain.
class VertexList(domain, start, count)

A list of vertices within a VertexDomain. Use VertexDomain.create() to construct this list.

delete()

Delete this group.

draw(mode)

Draw this vertex list in the given OpenGL mode.

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

Get the domain this vertex list belongs to.

Return type:VertexDomain
get_size()

Get the number of vertices in the list.

Return type:int
migrate(domain)

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.
resize(count)

Resize this group.

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

Array of color data.

edge_flags

Array of edge flag data.

fog_coords

Array of fog coordinate data.

multi_tex_coords

Multi-array texture coordinate data.

normals

Array of normal vector data.

secondary_colors

Array of secondary color data.

tex_coords

Array of texture coordinate data.

vertices

Array of vertex coordinate data.

create_attribute_usage(fmt)

Create an attribute and usage pair from a format string. The format string is as documented in pyglet.graphics.vertexattribute, with the addition of an optional usage component:

usage ::= attribute ( '/' ('static' | 'dynamic' | 'stream' | 'none') )?

If the usage is not given it defaults to ‘dynamic’. The usage corresponds to the OpenGL VBO usage hint, and for static also indicates a preference for interleaved arrays. If none is specified a buffer object is not created, and vertex data is stored in system memory.

Some examples:

v3f/stream
3D vertex position using floats, for stream usage
c4b/static
4-byte color attribute, for static usage
Returns:attribute, usage
create_domain(*attribute_usage_formats)

Create a vertex domain covering the given attribute usage formats. See documentation for create_attribute_usage() and pyglet.graphics.vertexattribute.create_attribute() for the grammar of these format strings.

Return type:VertexDomain
create_indexed_domain(*attribute_usage_formats)

Create an indexed vertex domain covering the given attribute usage formats. See documentation for create_attribute_usage and pyglet.graphics.vertexattribute.create_attribute() for the grammar of these format strings.

Return type:VertexDomain