# opengl.vao.VAO

moderngl_window.opengl.vao.VAO

  Represents a vertex array object.

  This is a wrapper class over `moderngl.VertexArray` to make interactions with programs/shaders simpler. Named buffers are added correspoding with attribute names in a vertex shader. When rendering the VAO an internal `moderngl.VertextArray` is created automatically mapping the named buffers compatible with the supplied program. This program is cached internally.

  The shader program doesn’t need to use all the buffers registered in this wrapper. When a subset is used only the used buffers are mapped and the appropriate padding is calculated when interleaved data is used.

  You are not required to use this class, but most methods in the system creating vertexbuffers will return this type. You can obtain a single `moderngl.VertexBuffer` instance by calling `VAO.instance()` method if you prefer to work directly on moderngl instances.

  Example:

      # Separate buffers
      vao = VAO(name="test", mode=moderngl.POINTS)
      vao.buffer(positions, '3f', ['in_position'])
      vao.buffer(velocities, '3f', ['in_velocities'])

      # Interleaved
      vao = VAO(name="test", mode=moderngl.POINTS)
      vao.buffer(interleaved_data, '3f 3f', ['in_position', 'in_velocities'])

      # GLSL vertex shader in attributes
      in vec3 in_position;
      in vec3 in_velocities;

## Methods

VAO.__init__(name='', mode=4)

  Create and empty VAO with a name and default render mode.

  Example:

      VAO(name="cube", mode=moderngl.TRIANGLES)

  Keyword Arguments:

    - name (str) – Optional name for debug purposes

    - mode (int) – Default draw mode

VAO.render(program: Program, mode=None, vertices=-1, first=0, instances=1)

  Render the VAO.

  An internal `moderngl.VertexBuffer` with compatible buffer bindings is automatically created on the fly and cached internally.

  Parameters:

    program – The `moderngl.Program`

  Keyword Arguments:

    - mode – Override the draw mode (`TRIANGLES` etc)

    - 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

VAO.render_indirect(program: Program, buffer, mode=None, count=-1, *, first=0)

  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:

    - program – The `moderngl.Program`

    - buffer – The `moderngl.Buffer` containing indirect draw commands

  Keyword Arguments:

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

    - count (int) – The number of draws.

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

VAO.transform(program: Program, buffer: Buffer, mode=None, vertices=-1, first=0, instances=1)

  Transform vertices. Stores the output in a single buffer.

  Parameters:

    - program – The `moderngl.Program`

    - buffer – The `moderngl.buffer` to store the output

  Keyword Arguments:

    - mode – Draw mode (for example `moderngl.POINTS`)

    - 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

VAO.buffer(buffer, buffer_format: str, attribute_names: List[str])

  Register a buffer/vbo for the VAO. This can be called multiple times. adding multiple buffers (interleaved or not).

  Parameters:

    - buffer – The buffer data. Can be `numpy.array`, `moderngl.Buffer` or `bytes`.

    - buffer_format (str) – The format of the buffer. (eg. `3f 3f` for interleaved positions and normals).

    - attribute_names – A list of attribute names this buffer should map to.

  Returns:

    The `moderngl.Buffer` instance object. This is handy when providing `bytes` and `numpy.array`.

VAO.index_buffer(buffer, index_element_size=4)

  Set the index buffer for this VAO.

  Parameters:

    buffer – `moderngl.Buffer`, `numpy.array` or `bytes`

  Keyword Arguments:

    index_element_size (int) – Byte size of each element. 1, 2 or 4

VAO.instance(program: Program) → VertexArray

  Obtain the `moderngl.VertexArray` instance for the program.

  The instance is only created once and cached internally.

  Parameters:

    program (moderngl.Program) – The program

  Returns:

    instance

  Return type:

    `moderngl.VertexArray`

VAO.release(buffer=True)

  Destroy all internally cached vaos and release all buffers.

  Keyword Arguments:

    buffers (bool) – also release buffers

VAO.get_buffer_by_name(name: str) → BufferInfo

  Get the BufferInfo associated with a specific attribute name

  If no buffer is associated with the name None will be returned.

  Parameters:

    name (str) – Name of the mapped attribute

  Returns:

    BufferInfo instance

  Return type:

    BufferInfo

## Attributes

VAO.ctx

  The actite moderngl context

  Type:

    moderngl.Context