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

Holds OpenGL-related state objects for rendering.

Package Contents

class picogl.renderer.RendererBase(parent: object = 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)[source]

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

vertices
indices
use_indices = True
colors
normals
uvs
vao: picogl.backend.modern.core.vertex.array.object.VertexArrayObject | None = None
index_count: int = 0
_expanded_vertices = None
_expanded_colors = None
_expanded_normals = None
_expanded_uvs = None
_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: MeshData) GLMesh[source]

Construct a GLMesh from a MeshData container.

Parameters:

mesh (MeshData) – Must have .vbo (Nx3), .ebo (Mx1), optional .cbo (Nx3), .nbo (Nx3), uvs (Nx2)

Returns:

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

Return type:

GLMesh

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(vbo: numpy.ndarray = None, nbo: numpy.ndarray = None, uvs: numpy.ndarray = None, cbo: numpy.ndarray = None, ebo: numpy.ndarray = None)[source]

Holds OpenGL-related state objects for rendering.

vbo = None
nbo = None
uvs = None
cbo = None
ebo = None
vertex_count
as_ribbon_args() dict[source]

Convert into arguments for setup_ribbon_buffers.

__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 colour override and transparency.

Parameters:
  • color – Optional colour 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]

delete to remove atoms_buffers