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

VertexArrayObject

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.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 = None[source]
vbo = None[source]
cbo = None[source]
nbo = None[source]
ebo = None[source]
layout: picogl.buffers.attributes.LayoutDescriptor | None = None[source]
bind()[source]

Bind the VAO for use in rendering.

unbind()[source]

Unbind the VAO by binding to zero.

delete()[source]

Delete the VAO from GPU memory.

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.

get_vbo_object(name: str) LegacyVBO[source]

Retrieve a VBO by its semantic or shorthand name.

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