VertexArray¶
-
class
moderngl.
VertexArray
¶ 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, and some Subroutine information.A VertexArray object cannot be instantiated directly, it requires a context. Use
Context.vertex_array()
orContext.simple_vertex_array()
to create one.Note
Compared to OpenGL,
VertexArray
objects have some additional responsibilities:- Binding a
Program
whenVertexArray.render()
orVertexArray.transform()
is called. - Subroutines can be assigned. Please see the example below.
- Binding a
Create¶
-
Context.
simple_vertex_array
(program, buffer, *attributes, index_buffer=None, index_element_size=4) → VertexArray Create a
VertexArray
object.Warning
This method is deprecated and may be removed in the future. Use
Context.vertex_array()
instead. It also supports the argument format this method describes.Parameters: Keyword Arguments: - index_element_size (int) – byte size of each index element, 1, 2 or 4.
- index_buffer (Buffer) – An index buffer.
Returns: VertexArray
object
-
Context.
vertex_array
(*args, **kwargs) → VertexArray Create a
VertexArray
object.This method also supports arguments for
Context.simple_vertex_array()
.Parameters: - program (Program) – The program used when rendering.
- content (list) – A list of (buffer, format, attributes). See Buffer Format.
- index_buffer (Buffer) – An index buffer.
Keyword Arguments: - index_element_size (int) – byte size of each index element, 1, 2 or 4.
- skip_errors (bool) – Ignore skip_errors varyings.
Returns: VertexArray
object
Methods¶
-
VertexArray.
render
(mode=None, vertices=-1, first=0, instances=-1)¶ 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.
Keyword Arguments: - first (int) – The index of the first vertex to start with.
- instances (int) – The number of instances.
- mode (int) – By default
-
VertexArray.
render_indirect
(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: - buffer (Buffer) – Indirect drawing commands.
- mode (int) – By default
TRIANGLES
will be used. - count (int) – The number of draws.
Keyword Arguments: first (int) – The index of the first indirect draw command.
-
VertexArray.
transform
(buffer, mode=None, vertices=-1, first=0, instances=-1, buffer_offset=0)¶ 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.
Keyword Arguments: - 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, cls, buffer, fmt, offset=0, stride=0, divisor=0, normalize=False)¶ Bind individual attributes to buffers.
Parameters: - location (int) – The attribute location.
- cls (str) – The attribute class. Valid values are
f
,i
ord
. - buffer (Buffer) – The buffer.
- format (str) – The buffer format.
Keyword Arguments: - offset (int) – The offset.
- stride (int) – The stride.
- divisor (int) – The divisor.
- normalize (bool) – The normalize parameter, if applicable.
-
VertexArray.
release
()¶ Release the ModernGL object.
Attributes¶
-
VertexArray.
program
¶ The program assigned to the VertexArray. The program used when rendering or transforming primitives.
Type: Program
-
VertexArray.
index_element_size
¶ The byte size of each element in the index buffer
Type: int
-
VertexArray.
scope
¶ The
moderngl.Scope
.
-
VertexArray.
vertices
¶ 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.
Type: int
-
VertexArray.
instances
¶ Get or set the number of instances to render
Type: int
-
VertexArray.
subroutines
¶ The subroutines assigned to the VertexArray. The subroutines used when rendering or transforming primitives.
Type: tuple
-
VertexArray.
glo
¶ The internal OpenGL object. This values is provided for debug purposes only.
Type: int
-
VertexArray.
mglo
¶ Internal representation for debug purposes only.
-
VertexArray.
extra
¶ Any - Attribute for storing user defined objects
-
VertexArray.
ctx
¶ The context this object belongs to