Batch Class

Inheritance diagram of Batch

class Batch

Manage a collection of vertex lists for batched rendering.

Vertex lists are added to a Batch using the add and add_indexed methods. An optional group can be specified along with the vertex list, which gives the OpenGL state required for its rendering. Vertex lists with shared mode and group are allocated into adjacent areas of memory and sent to the graphics card in a single operation.

Call VertexList.delete to remove a vertex list from the batch.

Constructor:

__init__()

Create a graphics batch.

Methods:

add(count, mode, group, *data) Add a vertex list to the batch.
add_indexed(count, mode, group, indices, *data) Add an indexed vertex list to the batch.
draw() Draw the batch.
draw_subset(vertex_lists) Draw only some vertex lists in the batch.
invalidate() Force the batch to update the draw list.
migrate(vertex_list, mode, group, batch) Migrate a vertex list to another batch and/or group.

Methods

Batch.add(count, mode, group, *data)

Add a vertex list to the batch.

Parameters:
  • count (int) – The number of vertices in the list.
  • mode (int) – OpenGL drawing mode enumeration; for example, one of GL_POINTS, GL_LINES, GL_TRIANGLES, etc. See the module summary for additional information.
  • group (Group) – Group of the vertex list, or None if no group is required.
  • data (data items) – Attribute formats and initial data for the vertex list. See the module summary for details.
Return type:

VertexList

Batch.add_indexed(count, mode, group, indices, *data)

Add an indexed vertex list to the batch.

Parameters:
  • count (int) – The number of vertices in the list.
  • mode (int) – OpenGL drawing mode enumeration; for example, one of GL_POINTS, GL_LINES, GL_TRIANGLES, etc. See the module summary for additional information.
  • group (Group) – Group of the vertex list, or None if no group is required.
  • indices (sequence) – Sequence of integers giving indices into the vertex list.
  • data (data items) – Attribute formats and initial data for the vertex list. See the module summary for details.
Return type:

IndexedVertexList

Batch.draw()

Draw the batch.

Batch.draw_subset(vertex_lists)

Draw only some vertex lists in the batch.

The use of this method is highly discouraged, as it is quite inefficient. Usually an application can be redesigned so that batches can always be drawn in their entirety, using draw.

The given vertex lists must belong to this batch; behaviour is undefined if this condition is not met.

Parameters:vertex_lists (sequence of VertexList or IndexedVertexList) – Vertex lists to draw.
Batch.invalidate()

Force the batch to update the draw list.

This method can be used to force the batch to re-compute the draw list when the ordering of groups has changed.

Note

Since pyglet 1.2

Batch.migrate(vertex_list, mode, group, batch)

Migrate a vertex list to another batch and/or group.

vertex_list and mode together identify the vertex list to migrate. group and batch are new owners of the vertex list after migration.

The results are undefined if mode is not correct or if vertex_list does not belong to this batch (they are not checked and will not necessarily throw an exception immediately).

batch can remain unchanged if only a group change is desired.

Parameters:
  • vertex_list (VertexList) – A vertex list currently belonging to this batch.
  • mode (int) – The current GL drawing mode of the vertex list.
  • group (Group) – The new group to migrate to.
  • batch (Batch) – The batch to migrate to (or the current batch).

Table Of Contents

Previous topic

create_indexed_domain Function

Next topic

Group Class