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

VertexArrayObject

OpenGL Vertex Array Objects (VAO) class

Functions

current_gl_context()

Module Contents

picogl.backend.modern.core.vertex.array.object.current_gl_context()[source]
class picogl.backend.modern.core.vertex.array.object.VertexArrayObject(handle: int = None)[source]

Bases: picogl.buffers.base.VertexBase

OpenGL Vertex Array Objects (VAO) class

_configured: bool = False[source]
attributes = [][source]
vbos = [][source]
named_vbos: dict[str, picogl.backend.modern.core.vertex.base.VertexBuffer][source]
vao: int | None = None[source]
ebo = None[source]
layout: picogl.buffers.attributes.LayoutDescriptor | None = None[source]
_creation_context_id: int | 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

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_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)

delete_buffers()[source]

delete_buffers

Returns:

None

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

set_ebo(ebo: int) int[source]

add_ebo

Parameters:

ebo – int

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 ModernVBO created for add_vbo(index=attrib_index, ...).

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

Upload new contents for the vertex buffer tied to attribute index.

index is the same value passed to add_vbo() (e.g. 0 positions, 1 colours, 2 normals). If the new array has the same byte size as the existing GPU store, glBufferSubData() is used; otherwise ModernVBO.set_data() (glBufferData) reallocates the buffer.

The VAO must have been built via add_vbo(); arbitrary add_attribute() entries (raw handles only) are not updated here.