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

SILENT_VAO

Classes

GLResource

Base class for all gl-owned objects.

VertexArrayObject

OpenGL Vertex Array Objects (VAO) class

Functions

_qopengl_context_class() → Any | None

Return QOpenGLContext only if PySide6.QtGui is already imported.

_current_qt_gl_context() → Any | None

current_gl_context() → int | None

_is_element_attribute(attr) → bool

Return True when attr describes an element buffer, not a vertex attribute.

Module Contents

picogl.backend.modern.core.vertex.array.object.SILENT_VAO = True[source]
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._current_qt_gl_context() → Any | None[source]
picogl.backend.modern.core.vertex.array.object.current_gl_context() → int | None[source]
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_layout must 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.

_creation_context = None[source]
_deleted = False[source]
_handle = None[source]
property context[source]
validate_context()[source]
class picogl.backend.modern.core.vertex.array.object.VertexArrayObject(handle: int = None, *, registry_label: str | None = None)[source]

Bases: picogl.gpu.buffers.base.VertexBase, GLResource

OpenGL Vertex Array Objects (VAO) class

_creation_context = None[source]
_registry_label = None[source]
_configured: bool = False[source]
attributes: list[picogl.gpu.buffers.attributes.AttributeSpec] = [][source]
vbos = [][source]
named_vbos: dict[str, picogl.backend.modern.core.vertex.base.VertexBuffer][source]
_vbos_by_attribute: dict[int, picogl.backend.modern.core.vertex.buffer.object.ModernVBO][source]
ebo = None[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.

is_valid_in_current_context() → bool[source]
set_layout(layout: picogl.gpu.buffers.attributes.LayoutDescriptor | None) → None[source]

Configure the VAO from a layout descriptor.

bound()[source]
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).

unbind()[source]

Unbind the VAO by binding to zero.

delete()[source]

Delete the VAO from GPU memory.

configure()[source]

set layout

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.

delete_buffers()[source]

delete_buffers

Returns:

None

add_ebo(data: numpy.ndarray) → picogl.backend.modern.core.vertex.buffer.element.ModernEBO[source]

add_ebo

Parameters:

data – np.ndarray

Returns:

int

set_ebo(ebo: int) → int[source]

add_ebo

Parameters:

ebo – int

Returns:

int

property index_count: int | None[source]

Return the number of indices in the EBO.

Returns:

int

data_length() → int[source]

Number of vertices in the position buffer, or indices if no positions.

draw(spec: picogl.backend.modern.core.vertex.array.draw_spec.DrawSpec | None = None) → None[source]

Issue glDrawArrays or glDrawElements from a DrawSpec.

spec.count is None uses index_count. An explicit count=0 is 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 ModernVBO created for attribute attrib_index.

update_vbo(index: int, data: numpy.ndarray) → None[source]

update vbo