Source code for picogl.protocols.drawable_buffer

"""
OpenGL buffer protocols for ElMo.

Defines a shared interface (DrawableBuffer) for buffer/VAO objects used in
legacy and modern backends, so group-level and draw code can treat them
uniformly.
"""

from __future__ import annotations

from typing import TYPE_CHECKING, Any, Mapping, Protocol, TypeAlias, runtime_checkable

import numpy as np

if TYPE_CHECKING:
    from picogl.renderer.meshdata import MeshData


@runtime_checkable
[docs] class DrawableBuffer(Protocol): """ Protocol for OpenGL buffer/VAO objects that can be bound, drawn, and deleted. Implementors must provide bind(), unbind(), draw(), and delete(). Optional: is_valid() for validity checks; __enter__/__exit__ for context-manager support (with obj: obj.draw()). Legacy VBO groups and modern VAOs (VertexArrayObject, RibbonVBG, etc.) conform to this protocol. """
[docs] def bind(self) -> None: """Bind this buffer/VAO for rendering.""" ...
[docs] def unbind(self) -> None: """Unbind this buffer/VAO after rendering.""" ...
[docs] def draw(self, *args: Any, **kwargs: Any) -> None: """Issue draw calls. Signature is backend-specific (e.g. atom_count, index_count).""" ...
[docs] def delete(self) -> None: """Release GPU resources.""" ...
[docs] def data_length(self) -> int: """Number of vertices (or drawable elements) in this buffer.""" ...
@runtime_checkable
[docs] class MeshDrawable(Protocol): """GPU object that owns or delegates one CPU mesh. The mesh **value** is always :class:`~picogl.renderer.meshdata.MeshData`. Lookup helpers use ``isinstance(..., MeshData)``; this protocol does not replace that check. Only ``mesh_data`` is part of the protocol. Draw and color upload stay on :class:`DrawableBuffer` and the layout color helpers. """ @property
[docs] def mesh_data(self) -> MeshData | None: """Attached :class:`~picogl.renderer.meshdata.MeshData`, or ``None``.""" ...
@runtime_checkable
[docs] class VertexBufferDataSource(Protocol): """Single legacy/modern VBO or EBO with CPU-side ``data``."""
[docs] data: np.ndarray | None
@runtime_checkable
[docs] class BufferContainer(Protocol): """Wrapper or group holding nested VAO/VBO handles (e.g. ElMo buffer groups)."""
[docs] vao: DrawableBuffer | int | None
[docs] vbo: VertexBufferDataSource | int | None
[docs] named_vbos: Mapping[Any, VertexBufferDataSource]
[docs] index_count: int
[docs] DrawableLengthInput: TypeAlias = ( DrawableBuffer | BufferContainer | VertexBufferDataSource | None )