picogl.backend.modern.core.vertex.base
vertex_base.py
This module defines the VertexBuffer class, a foundational abstraction for OpenGL objects that require explicit binding and unbinding during rendering.
VertexBuffer provides a common interface and context management protocol for derived classes such as VertexArrayObject, ModernVBO, and ModernEBO. It ensures consistent handling of OpenGL object lifetimes and usage patterns by enforcing the implementation of bind() and unbind() methods.
Features: - Stores a raw OpenGL object handle (ID) - Provides bind() / unbind() interface to be implemented by subclasses - Supports Python context manager protocol (with statement) - Useful for any OpenGL object that must be bound/unbound during draw calls
Example Usage:
class MyBuffer(VertexBuffer): …def bind(self): glBindBuffer(GL_ARRAY_BUFFER, self.handle) …def unbind(self): glBindBuffer(GL_ARRAY_BUFFER, 0) … …with MyBuffer(handle) as buf: … # buffer is bound
…
…# buffer is unbound
Note: This base class is abstract and cannot be used directly; bind and unbind must be implemented in subclasses.
Classes
VertexBuffer |
Module Contents
- class picogl.backend.modern.core.vertex.base.VertexBuffer(handle: int = None, data: numpy.ndarray = None, target: int = GL_ARRAY_BUFFER, size: int = 3, stride: int = 0, dtype: int = GL_FLOAT, index: int = None, pointer: ctypes.c_void_p = ctypes.c_void_p(0))[source]
Bases:
picogl.buffers.base.VertexBaseVertexBuffer
Base class for OpenGL vertex-related buffers (VBO, VAO, EBO).
- This handles:
Buffer binding/unbinding
Data upload (glBufferData)
Vertex attribute configuration
Type mapping from NumPy dtype to GL constants
- update(data: numpy.ndarray)[source]
- set_data(data: numpy.ndarray, usage: int = GL_STATIC_DRAW) None[source]
Upload data to the GPU.
- Parameters:
data – NumPy array containing buffer data.
usage – GL usage hint (e.g., GL_STATIC_DRAW, GL_DYNAMIC_DRAW).
- set_vertex_attributes(index: int, data: numpy.ndarray = None, size: int = None, normalized: bool = False, stride: int = 0, offset: int = 0, dtype: int = None, pointer: ctypes.c_void_p = None) None[source]
Set the vertex attribute pointer configuration.
- Parameters:
index – Attribute index in the VAO.
data – Optional data array to store alongside attribute info.
size – Number of components per vertex (1-4).
normalized – Whether values should be normalized.
stride – Byte offset between consecutive attributes.
offset – Byte offset of the first attribute.
dtype – GL data type (e.g., GL_FLOAT).
pointer – Offset pointer for glVertexAttribPointer.