picogl.renderer
Submodules
Classes
Base Renderer Class |
|
Stores dynamic OpenGL-related state (VAO, shader, texture handles, etc.). |
|
GPU‐resident mesh: owns VAO/VBO/EBO/CBO/NBO for an indexed triangle mesh. |
|
Representation of mesh data for OpenGL rendering. |
Package Contents
- class picogl.renderer.RendererBase(parent=None)[source]
Bases:
picogl.renderer.abstract.AbstractRendererBase Renderer Class
- line_width = 2.0
- show_model = False
- parent = None
- _initialized = False
- property dispatch_list
- render(mvp_matrix: numpy.ndarray | None = None) None[source]
render dispatcher
- Returns:
None
- class picogl.renderer.GLContext[source]
Stores dynamic OpenGL-related state (VAO, shader, texture handles, etc.). Does NOT store raw vertex data.
- vertex_array: picogl.backend.modern.core.vertex.array.object.VertexArrayObject | None = None
- shader: picogl.backend.modern.core.shader.program.ShaderProgram | None = None
- mvp_matrix: numpy.ndarray
- model_matrix: numpy.ndarray
- view: numpy.ndarray
- eye_np: numpy.ndarray
- 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.
- 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_layout –
surface→ 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:
- update_colors(colors: numpy.ndarray)[source]
- 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.
- 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.
- vertices = None
- normals = None
- texcoords = None
- colors = None
- indices = None
- vertex_count
- property vbo
- property nbo
- property uvs
- property cbo
- property ebo
- 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]
- 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)