VertexArray#

class VertexArray#

Returned by Context.vertex_array()

A VertexArray object is an OpenGL object that stores all of the state needed to supply vertex data.

It stores the format of the vertex data as well as the Buffer objects providing the vertex data arrays.

In ModernGL, the VertexArray object also stores a reference for a Program object.

Compared to OpenGL, VertexArray also stores a Program object.

Methods#

VertexArray.render(mode: int | None = None, vertices: int = -1, first: int = 0, instances: int = -1) None#

The render primitive (mode) must be the same as the input primitive of the GeometryShader.

Parameters:
  • mode (int) – By default TRIANGLES will be used.

  • vertices (int) – The number of vertices to transform.

  • first (int) – The index of the first vertex to start with.

  • instances (int) – The number of instances.

VertexArray.render_indirect(buffer: Buffer, mode: int | None = None, count: int = -1, first: int = 0) None#

The render primitive (mode) must be the same as the input primitive of the GeometryShader.

The draw commands are 5 integers: (count, instanceCount, firstIndex, baseVertex, baseInstance).

Parameters:
  • buffer (Buffer) – Indirect drawing commands.

  • mode (int) – By default TRIANGLES will be used.

  • count (int) – The number of draws.

  • first (int) – The index of the first indirect draw command.

VertexArray.transform(buffer: Buffer | List[Buffer], mode: int | None = None, vertices: int = -1, first: int = 0, instances: int = -1, buffer_offset: int = 0) None#

Transform vertices.

Stores the output in a single buffer. The transform primitive (mode) must be the same as the input primitive of the GeometryShader.

Parameters:
  • buffer (Buffer) – The buffer to store the output.

  • mode (int) – By default POINTS will be used.

  • vertices (int) – The number of vertices to transform.

  • first (int) – The index of the first vertex to start with.

  • instances (int) – The number of instances.

  • buffer_offset (int) – Byte offset for the output buffer

VertexArray.bind(attribute: int, cls: str, buffer: Buffer, fmt: str, offset: int = 0, stride: int = 0, divisor: int = 0, normalize: bool = False)#

Bind individual attributes to buffers.

Parameters:
  • location (int) – The attribute location.

  • cls (str) – The attribute class. Valid values are f, i or d.

  • buffer (Buffer) – The buffer.

  • format (str) – The buffer format.

  • offset (int) – The offset.

  • stride (int) – The stride.

  • divisor (int) – The divisor.

  • normalize (bool) – The normalize parameter, if applicable.

VertexArray.release() None#

Release the ModernGL object.

Attributes#

VertexArray.mode: int#

Get or set the default rendering mode.

This value is used when mode is not passed in rendering calls.

Examples:

vao.mode = moderngl.TRIANGLE_STRIPS
VertexArray.program: Program#

The program assigned to the VertexArray. The program used when rendering or transforming primitives.

VertexArray.index_buffer: Buffer#

The index buffer if the index_buffer is set, otherwise None.

VertexArray.index_element_size: int#

The byte size of each element in the index buffer.

VertexArray.scope: Scope#

The scope to use while rendering.

VertexArray.vertices: int#

The number of vertices detected.

This is the minimum of the number of vertices possible per Buffer. The size of the index_buffer determines the number of vertices. Per instance vertex attributes does not affect this number.

VertexArray.instances: int#

Get or set the number of instances to render.

VertexArray.ctx: Context#

The context this object belongs to

VertexArray.glo: int#

The internal OpenGL object. This values is provided for interoperability and debug purposes only.

VertexArray.extra: Any#

User defined data.