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, vbo=vbo, size=3) …vao.add_attribute(index=1, vbo=colors, size=3) …vao.update(index_count=100)
Intended for OpenGL 3.0+ with VAO support.
Classes
OpenGL Vertex Array Objects (VAO) class |
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]
- set_layout(layout: picogl.buffers.attributes.LayoutDescriptor) None[source]
set_layout
- Parameters:
layout – LayoutDescriptor: The layout descriptor to define the vertex attribute format.
- Raises:
None
Sets the layout for the rendering setup by binding the buffers and configuring the attributes. The state is stored in the Vertex Array Object (VAO). This method assumes a single Vertex Buffer Object (VBO) holds all position data but can be adapted as required. Handles optional usage of Normal Buffer Object (NBO) and Element Buffer Object (EBO) if present.
- add_vbo_object(name: str, vbo: LegacyVBO) LegacyVBO[source]
Register a VBO by semantic name or shorthand alias.
- 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