picogl.backend.modern.core.vertex.array.object
vertex_array_object.py
This module defines the VertexArrayObject class, which encapsulates the creation, management, and usage of OpenGL Vertex Array Objects (VAOs) in modern OpenGL rendering workflows.
The VertexArrayObject class inherits from VertexBuffer and provides a clean, object-oriented interface for managing VAO handles and vertex attribute configurations.
It supports binding/unbinding operations, attribute registration, and rendering via glDrawArrays.
Features: - Automatic VAO generation if none is provided - Storage and enabling of vertex attribute definitions - Integration with VBOs via ModernVBO (used as context managers) - Simplified draw calls for points or other primitive modes - Graceful deletion and handle management
Dependencies: - numpy - PyOpenGL (OpenGL.GL and OpenGL.raw.GL)
Example usage:
>>>vao = VertexArrayObject() …vao.add_attribute(index=0, vertices=vertices, size=3) …vao.add_attribute(index=1, vertices=colors, size=3) …vao.update(index_count=100)
Intended for OpenGL 3.0+ with VAO support.
Classes
OpenGL Vertex Array Objects (VAO) class |
Functions
Module Contents
- class picogl.backend.modern.core.vertex.array.object.VertexArrayObject(handle: int = None)[source]
Bases:
picogl.buffers.base.VertexBaseOpenGL Vertex Array Objects (VAO) class
- layout: picogl.buffers.attributes.LayoutDescriptor | None = None[source]
- is_valid_in_current_context() bool[source]
True if this VAO was created in the current OpenGL context (safe to bind/draw).
- set_layout(layout: picogl.buffers.attributes.LayoutDescriptor) None[source]
configure
- bind() VertexArrayObject | None[source]
Bind the VAO for use in rendering. :return: True if bound, False if skipped (wrong context — avoids GL_INVALID_OPERATION/segfault).
- add_vbo_object(name: str, vbo: picogl.backend.modern.core.vertex.buffer.object.ModernVBO) picogl.backend.modern.core.vertex.buffer.object.ModernVBO[source]
Register a VBO by semantic name or shorthand alias.
- get_vbo_object(name: str) picogl.backend.modern.core.vertex.base.VertexBuffer | None[source]
Retrieve a VBO by its semantic or shorthand name.
- add_vbo_data(data: numpy.ndarray)[source]
add VBO data
- add_vbo(index: int, data: numpy.ndarray, size: int, dtype: int = GL_FLOAT, name: str = None, handle: int = None) picogl.backend.modern.core.vertex.buffer.object.ModernVBO[source]
Add a Vertex Buffer Object (VBO) to the VAO and set its attributes.
- Parameters:
handle
index – VAO attribute index
data – Vertex data
size – Size per vertex (e.g., 3 for vec3)
dtype – OpenGL data type (e.g., GL_FLOAT)
name – Optional semantic name (e.g., “position”, “colour”)
- Returns:
OpenGL buffer handle (GLuint)
- add_attribute(index: int, vbo: int, size: int = 3, dtype: int = GL_FLOAT, normalized: bool = False, stride: int = 0, offset: int = 0)[source]
add_attribute
- Parameters:
index – int Index of the vertex attribute.
vbo – int Vertex Buffer Object (VBO) associated with this attribute.
size – int Size of the vertex attribute (e.g., 3 for a 3D vector).
dtype – int Data type of the vertex attribute (default is GL_FLOAT).
normalized – bool Whether the data is normalized (default is False).
stride – int Byte offset between consecutive vertex attributes (default is 0).
offset – int Byte offset to the first component of the
vertex attribute (default is 0). Add a vertex attribute to the VAO.
- add_ebo(data: numpy.ndarray) picogl.backend.modern.core.vertex.buffer.element.ModernEBO[source]
add_ebo
- Parameters:
data – np.ndarray
- Returns:
int
- property index_count: str | int | None[source]
Return the number of indices in the EBO.
- Returns:
int
- draw(index_count: int = None, dtype: int = GL_UNSIGNED_INT, mode: int = GL_POINTS, pointer: int = ctypes.c_void_p(0))[source]
draw
- Parameters:
pointer – ctypes.c_void_p(0)
dtype – GL_UNSIGNED_INT
index_count – int Number of vertices to draw.
mode – int e.g. GL_POINT
- Returns:
None
- _modern_vbo_for_attrib(attrib_index: int) picogl.backend.modern.core.vertex.buffer.object.ModernVBO | None[source]
Return the
ModernVBOcreated foradd_vbo(index=attrib_index, ...).
- update_vbo(index: int, data: numpy.ndarray) None[source]
Upload new contents for the vertex buffer tied to attribute
index.indexis the same value passed toadd_vbo()(e.g.0positions,1colours,2normals). If the new array has the same byte size as the existing GPU store,glBufferSubData()is used; otherwiseModernVBO.set_data()(glBufferData) reallocates the buffer.The VAO must have been built via
add_vbo(); arbitraryadd_attribute()entries (raw handles only) are not updated here.