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)
Intended for OpenGL 3.0+ with VAO support.
Attributes
Classes
Base class for all gl-owned objects. |
|
OpenGL Vertex Array Objects (VAO) class |
Functions
|
Return QOpenGLContext only if PySide6.QtGui is already imported. |
|
|
|
|
|
Return True when attr describes an element buffer, not a vertex attribute. |
Module Contents
- picogl.backend.modern.core.vertex.array.object._qopengl_context_class() Any | None[source]
Return QOpenGLContext only if PySide6.QtGui is already imported.
- picogl.backend.modern.core.vertex.array.object._is_element_attribute(attr: picogl.gpu.buffers.attributes.AttributeSpec) bool[source]
Return True when attr describes an element buffer, not a vertex attribute.
Index buffers are bound via
VertexArrayObject.add_ebo(), not as VBOs. Some layouts still list EBO for documentation;set_layoutmust skip them instead of requiring a vertex buffer.
- class picogl.backend.modern.core.vertex.array.object.GLResource(handle)[source]
Base class for all gl-owned objects.
- class picogl.backend.modern.core.vertex.array.object.VertexArrayObject(handle: int = None, *, registry_label: str | None = None)[source]
Bases:
picogl.gpu.buffers.base.VertexBase,GLResourceOpenGL Vertex Array Objects (VAO) class
- attributes: list[picogl.gpu.buffers.attributes.AttributeSpec] = [][source]
- _vbos_by_attribute: dict[int, picogl.backend.modern.core.vertex.buffer.object.ModernVBO][source]
- layout: picogl.gpu.buffers.attributes.LayoutDescriptor | None = None[source]
- build(attributes: list[picogl.backend.modern.core.vertex.attribute.VertexAttribute], indices: numpy.ndarray | None = None) None[source]
Populate self from attribute arrays and an optional element buffer.
- set_layout(layout: picogl.gpu.buffers.attributes.LayoutDescriptor | None) None[source]
Configure the VAO from a layout descriptor.
- 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(spec: picogl.gpu.buffers.attributes.AttributeSpec, data: numpy.ndarray, *, handle: int | None = None) picogl.backend.modern.core.vertex.buffer.object.ModernVBO[source]
Add a vertex buffer and configure its vertex attribute.
- Parameters:
spec – Vertex attribute layout (index, size, dtype, name).
data – Vertex data uploaded into the VBO.
handle – Optional existing OpenGL buffer handle.
- Returns:
The created
ModernVBO.
- add_ebo(data: numpy.ndarray) picogl.backend.modern.core.vertex.buffer.element.ModernEBO[source]
add_ebo
- Parameters:
data – np.ndarray
- Returns:
int
- draw(spec: picogl.backend.modern.core.vertex.array.draw_spec.DrawSpec | None = None) None[source]
Issue
glDrawArraysorglDrawElementsfrom aDrawSpec.spec.count is Noneusesindex_count. An explicitcount=0is a no-op and does not fall back to the element buffer length.- Parameters:
spec – GPU draw command; defaults to
DrawSpec(POINTS).
- _modern_vbo_for_attrib(attrib_index: int) picogl.backend.modern.core.vertex.buffer.object.ModernVBO | None[source]
Return the
ModernVBOcreated for attributeattrib_index.
- update_vbo(index: int, data: numpy.ndarray) None[source]
update vbo