picogl.renderer

Submodules

Classes

RendererBase

Base Renderer Class

GLContext

Stores dynamic OpenGL-related state (VAO, shader, texture handles, etc.).

GLMesh

GPU‐resident mesh: owns VAO/VBO/EBO/CBO/NBO for an indexed triangle mesh.

MeshData

Representation of mesh data for OpenGL rendering.

Package Contents

class picogl.renderer.RendererBase(parent=None)[source]

Bases: picogl.renderer.abstract.AbstractRenderer

Base Renderer Class

line_width = 2.0
show_model = False
parent = None
_initialized = False
_set_gl_state()[source]

Set the line width and disable depth test.

_restore_gl_state()[source]

Restore the original line width and depth test state.

property dispatch_list
initialize() None[source]

Initialize OpenGL resources (shaders, atoms_buffers, etc.).

property initialized: bool
render(mvp_matrix: numpy.ndarray | None = None) None[source]

render dispatcher

Returns:

None

initialize_rendering_buffers()[source]

For back compatibility

_finalize_render()[source]

Finalize the rendering (e.g., flush or swap atoms_buffers).

abstract _draw_model()[source]

draw_model

abstract _draw_selection()[source]

draw_selection

set_visibility(visible: bool) None[source]

Set the visibility of the object.

class picogl.renderer.GLContext[source]

Stores dynamic OpenGL-related state (VAO, shader, texture handles, etc.). Does NOT store raw vertex data.

vaos: dict[str, picogl.backend.modern.core.vertex.array.object.VertexArrayObject]
vertex_array: picogl.backend.modern.core.vertex.array.object.VertexArrayObject | None = None
shader: picogl.backend.modern.core.shader.program.ShaderProgram | None = None
texture_id: int | None = None
mvp_matrix: numpy.ndarray
model_matrix: numpy.ndarray
view: numpy.ndarray
eye_np: numpy.ndarray
create_shader_program(vertex_source_file: str, fragment_source_file: str, glsl_dir: str | pathlib.Path | None = None) None[source]

create_shader_program

Parameters:
  • vertex_source_file – str

  • fragment_source_file – str

  • glsl_dir – str

Returns:

None

class picogl.renderer.GLMesh(vertices: numpy.ndarray, faces: numpy.ndarray, colors: numpy.ndarray | None = None, normals: numpy.ndarray | None = None, uvs: numpy.ndarray | None = None, use_indices: bool = True, *, shader_type: Literal[picogl.shaders.type.ShaderType.ISOSURFACE, picogl.shaders.type.ShaderType.RIBBONS] = ShaderType.ISOSURFACE)[source]

GPU‐resident mesh: owns VAO/VBO/EBO/CBO/NBO for an indexed triangle mesh. It does not know anything about shaders or matrices.

vao: picogl.backend.modern.core.vertex.array.object.VertexArrayObject | None = None
index_count: int = 0
vertices
indices
use_indices = True
shader_type
colors
normals
uvs
_expanded_vertices = None
_expanded_colors = None
_expanded_normals = None
_expanded_uvs = None
_layouts
_layout_descriptor
_get_buffer_data(vbo_type: picogl.buffers.vertex.vbo.vbo_class.VBOType) numpy.ndarray | None[source]

get_buffer_data(vbo_type) -> np.ndarray

_expand_to_non_indexed() None[source]

Expand the mesh so that every triangle has its own copy of vertices/colors/normals/uvs. This converts indexed data (shared vertices) into a per-triangle vertex list suitable for glDrawArrays. The API remains the same; just keep the EBO empty and set index_count accordingly.

classmethod from_mesh_data(mesh: picogl.renderer.meshdata.MeshData, *, vertex_layout: picogl.shaders.type.ShaderType.ISOSURFACE | picogl.shaders.type.ShaderType.RIBBONS = ShaderType.ISOSURFACE) GLMesh[source]

Construct a GLMesh from a MeshData container.

Parameters:
  • mesh (MeshData) – Must have .vertices (Nx3), .ebo (Mx1), optional .cbo (Nx3), .nbo (Nx3), uvs (Nx2)

  • vertex_layoutsurface → attr order pos, color, normal (surface_with_lighting / mesh). ribbon → pos, normal, color (ribbons / RibbonVAO).

Returns:

Ready-to-upload mesh (GPU buffers are allocated only when upload() is called).

Return type:

GLMesh

update_colors(colors: numpy.ndarray)[source]
upload() None[source]

Allocate & fill GPU buffers.

bind()[source]
unbind()[source]
delete()[source]

Free GPU resources.

__enter__()[source]
__exit__(exc_type, exc, tb)[source]
draw() None[source]

Draw the mesh.

class picogl.renderer.MeshData(vertices: numpy.ndarray = None, normals: numpy.ndarray = None, texcoords: numpy.ndarray = None, colors: numpy.ndarray = None, indices: numpy.ndarray = None)[source]

Representation of mesh data for OpenGL rendering.

This class encapsulates mesh data and provides utilities for setting up and managing vertex attributes such as positions, normals, texture coordinates, colors, and indices. It enables interoperability with OpenGL through context management and binding/unbinding functions. Additionally, the class includes methods for raw data conversion and generation of default attributes.

vertices

Optional array of vertex positions as np.ndarray.

normals

Optional array of vertex normals as np.ndarray.

texcoords

Optional array of texture coordinates as np.ndarray.

colors

Optional array of vertex colors as np.ndarray.

indices

Optional array of vertex indices as np.ndarray.

vertex_count

Optional count of vertices, computed from vertices input.

bind()[source]

Binds vertex attributes to OpenGL client states for rendering.

unbind()[source]

Unbinds vertex attributes from OpenGL client states.

as_canonical_names()[source]

Converts the mesh data into a dictionary with canonical attribute names.

draw()[source]

Draws the mesh with optional OpenGL parameters for color, line width, drawing mode, fill mode, and alpha transparency.

from_raw()[source]

Class method for constructing a MeshData object from raw input data.

vertices = None
normals = None
texcoords = None
colors = None
indices = None
vertex_count
property vbo
property nbo
property uvs
property cbo
property ebo
as_canonical_names() dict[source]

Convert into canonical names.

__str__()[source]
classmethod _to_float32_flat(arr, name: str, required: bool = False) numpy.ndarray[source]
classmethod _to_float32_flat_or_none(arr, name: str) numpy.ndarray[source]
classmethod _to_int32_flat(arr, name: str, required: bool = False) numpy.ndarray[source]
classmethod _default_colors_for_vertices(vertex_count: int) numpy.ndarray[source]
classmethod _default_normals_for_vertices(vertex_count: int) numpy.ndarray[source]
__enter__()[source]
__exit__(exc_type, exc_val, exc_tb)[source]
bind()[source]
unbind()[source]
classmethod from_raw(vertices: numpy.ndarray | list[float], normals: numpy.ndarray | list[float] | None = None, uvs: numpy.ndarray | list[float] | None = None, colors: numpy.ndarray | list[float] | None = None, indices: numpy.ndarray | list[float] | None = None, color_per_vertex: numpy.ndarray | list[float] | None = None)[source]

Build a MeshData from raw/python inputs.

Parameters:
  • vertices – np.ndarray required, list/array of x,y,z triplets

  • normals – np.ndarray optional, list/array of x,y,z triplets

  • uvs – np.ndarray optional, list/array of u,v pairs

  • indices – np.ndarray optional int indices

  • colors – np.ndarray optional per-vertex colors (flat float32 array)

  • color_per_vertex – np.ndarray if provided and colors is None, generate per-vertex colors

draw(color: tuple = None, line_width: float = 1.0, mode: int = GL.GL_TRIANGLES, fill: bool = False, alpha: float = 1.0)[source]

Draw the mesh with optional color override and transparency.

Parameters:
  • color – Optional color override. If None and vertex colors exist, uses vertex colors.

  • line_width – Line width for wireframe mode

  • mode – OpenGL drawing mode

  • fill – Whether to fill or use wireframe

  • alpha – Transparency value from 0.0 (opaque) to 1.0 (fully transparent)

delete()[source]

Drop CPU references to mesh arrays (no GL objects on this type).