opengl.vao.VAO
- moderngl_window.opengl.vao.VAO[source]
Represents a vertex array object.
This is a wrapper class over
moderngl.VertexArrayto make interactions with programs/shaders simpler. Named buffers are added correspoding with attribute names in a vertex shader. When rendering the VAO an internalmoderngl.VertextArrayis 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.VertexBufferinstance by callingVAO.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)[source]
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)[source]
Render the VAO.
An internal
moderngl.VertexBufferwith compatible buffer bindings is automatically created on the fly and cached internally.- Parameters
program – The
moderngl.Program- Keyword Arguments
mode – Override the draw mode (
TRIANGLESetc)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)[source]
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.Programbuffer – The
moderngl.Buffercontaining indirect draw commands
- Keyword Arguments
mode (int) – By default
TRIANGLESwill 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)[source]
Transform vertices. Stores the output in a single buffer.
- Parameters
program – The
moderngl.Programbuffer – The
moderngl.bufferto 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])[source]
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.Bufferorbytes.buffer_format (str) – The format of the buffer. (eg.
3f 3ffor interleaved positions and normals).attribute_names – A list of attribute names this buffer should map to.
- Returns
The
moderngl.Bufferinstance object. This is handy when providingbytesandnumpy.array.
- VAO.index_buffer(buffer, index_element_size=4)[source]
Set the index buffer for this VAO.
- Parameters
buffer –
moderngl.Buffer,numpy.arrayorbytes- Keyword Arguments
index_element_size (int) – Byte size of each element. 1, 2 or 4
- VAO.instance(program: Program) VertexArray[source]
Obtain the
moderngl.VertexArrayinstance for the program.The instance is only created once and cached internally.
- Parameters
program (moderngl.Program) – The program
- Returns
instance
- Return type
moderngl.VertexArray
Attributes
- VAO.ctx
The actite moderngl context
- Type
moderngl.Context