picogl.backend.state
Render-state descriptors and command helpers for PicoGL backends.
The classes in this module are intentionally backend-neutral: they describe desired OpenGL state and delegate the actual gl calls to a backend object.
Classes
Raster State |
|
Tracks capability state without querying OpenGL. |
|
Blend State |
|
Represents depth-related state settings used for rendering. |
|
Represents the rendering state configuration for a graphics pipeline. |
|
Manages the application of render states to a backend. |
|
gl Attribute Array |
|
Represents a viewport in OpenGL with specified position and dimensions. |
|
Representation of a GL mesh with vertices, optional indices, and attributes. |
|
Represents a command for draw a mesh with optional rendering parameters. |
|
gl Clipping Plane State |
Functions
|
Return a raw OpenGL value for PicoGL enums or pass raw values through. |
Module Contents
- picogl.backend.state.gl_value(value: Any) Any[source]
Return a raw OpenGL value for PicoGL enums or pass raw values through.
- class picogl.backend.state.RasterState[source]
Raster State
- apply(backend: Any) None[source]
Applies rendering properties to the given backend.
This method configures the rendering settings of the provided backend based on its attributes. It will utilize the appropriate backend’s methods to apply the rendering properties.
Parameters: backend (Any): The rendering backend to apply the settings to. The backend should
have either a ‘raster’ attribute with an ‘apply()’ method or methods for setting polygon mode and line width.
Returns: None
- class picogl.backend.state.GLStateManager(backend: CapabilityDriver)[source]
Tracks capability state without querying OpenGL.
- set_enabled(cap: int, enabled: bool) None[source]
Sets the state of a specific capability.
This method enables or disables a given capability based on the specified flag. It ensures that the backend is updated only if the capability’s state changes.
Parameters: cap: int
The capability to be enabled or disabled.
- enabled: bool
A boolean value indicating whether to enable (True) or disable (False) the capability.
Returns: None
- is_enabled(cap: int) bool[source]
Determines if a specific capability is enabled.
This method checks whether a given capability, identified by its integer representation, is currently enabled. The capability’s value is processed using the gl_value function, and the result is determined by querying the internal data structure.
Parameters: cap: int
The integer representation of the capability to check.
Returns: bool
True if the specified capability is enabled, False otherwise.
- class picogl.backend.state.BlendState[source]
Blend State
- apply(state: GLStateManager)[source]
Applies blending state to the given GLStateManager.
This method adjusts the blending settings in the given OpenGL state manager based on the current configuration. If the backend of the GLStateManager supports blending and has a custom implementation, that custom behavior is invoked; otherwise, standard OpenGL blending state is configured.
Parameters: state (GLStateManager): The state manager to which the blending configuration
should be applied.
- class picogl.backend.state.DepthState(test: bool = True, write: bool = True, enabled: bool | None = None)[source]
Represents depth-related state settings used for rendering.
This class encapsulates settings for depth test and depth write functionalities, commonly used in rendering pipelines. It ensures immutability, allowing safe usage in contexts where concurrent access or state integrity is required. The class provides mechanisms to apply depth states to an OpenGL rendering backend.
- property enabled: bool[source]
Checks if the feature is currently enabled.
This property determines whether the feature or functionality controlled by the associated test attribute is active or not.
- Returns:
True if the feature is enabled, False otherwise.
- Return type:
- apply(state: GLStateManager)[source]
Applies depth-related settings to the given GLStateManager.
The method interacts with the provided GLStateManager to configure depth test and depth write capabilities. If the backend associated with the GLStateManager supports depth operations directly, it delegates the application of these settings to the backend; otherwise, it sets the appropriate GL pipeline capabilities and depth write settings.
Parameters: state (GLStateManager): The state manager used to manage OpenGL states and
capabilities.
Raises: None
- class picogl.backend.state.RenderState(*, raster: RasterState | None = None, depth: DepthState | None = None, blend: BlendState | bool | None = None, blend_src: Any = GLBlendFactor.SRC_ALPHA, blend_dst: Any = GLBlendFactor.ONE_MINUS_SRC_ALPHA, depth_test: bool | None = None, depth_write: bool | None = None, line_width: float | None = None, polygon_mode: Any | None = None, polygon_offset: tuple[float, float] | None = None, point_size: float | None = None, program_point_size: bool = False, cull_face: bool = False, lighting: bool = False)[source]
Represents the rendering state configuration for a graphics pipeline.
The RenderState class encapsulates various rendering states such as blending, depth testing, polygon rendering modes, and other state-related settings. This class is intended to provide an immutable configuration object for managing rendering behavior.
- property raster: RasterState[source]
Property to retrieve the rasterization state.
The raster property gathers various rendering state settings related to rasterization and combines them into a RasterState object.
- Returns:
An object representing the rasterization settings, including polygon mode, line width, polygon offset, and point size.
- Return type:
- property depth: DepthState[source]
Returns the DepthState object representing the current depth state.
The DepthState object encapsulates whether depth testing is enabled, and whether depth writing is allowed. This property provides a way to retrieve the current state of depth testing and writing configured in the system.
- Returns:
An object combining depth test and depth write settings, where test reflects the current depth test state and write reflects the current depth write state.
- Return type:
- property blend_state: BlendState[source]
Retrieve the blend state of the object.
Provides the configuration of the blending state based on the object’s current attributes.
- Returns:
An object representing the blend state, including whether blending is enabled and the source and destination blend factors.
- Return type:
- class picogl.backend.state.RenderStateApplier(backend: Any)[source]
Manages the application of render states to a backend.
This class ensures that a given render state is applied incrementally to a backend, avoiding redundant operations. The purpose is to optimize rendering performance by minimizing redundant state changes. The apply method orchestrates the comparison of the current state with a new state and applies only the necessary differences.
- current[source]
The current render state that has been applied. This is updated each time a new state is applied.
- Type:
RenderState | None
- apply(state
RenderState): Applies a given render state to the backend. Only applies differences compared to the currently applied state to optimize the rendering process.
- current: RenderState | None = None[source]
- apply(state: RenderState)[source]
- class picogl.backend.state.GLVertexBuffer(data: numpy.ndarray)[source]
- class picogl.backend.state.GLAttributeArray[source]
gl Attribute Array
- enable_legacy(kind: picogl.backend.gl.state.client.GLClientState)[source]
Enables the legacy client state for a specific OpenGL client state.
This method enables the specified OpenGL client state by calling the appropriate gl_enable_legacy_client_state function and then uses a corresponding handler to configure the relevant pointer settings for the client state. If the given client state is unsupported by the handlers, a RuntimeError is raised.
Parameters: kind (GLClientState): The type of OpenGL client state to enable. This determines the specific handler to be invoked for configuring pointer settings.
Raises: RuntimeError: If the argument kind cannot be processed by any of the handlers provided in the method.
- class picogl.backend.state.GLViewport[source]
Bases:
picogl.core.protocol.applicable.ApplicableRepresents a viewport in OpenGL with specified position and dimensions.
This class encapsulates the functionality of an OpenGL viewport, allowing the user to define the x and y position, as well as the width and height of the viewport. The apply method sets the viewport in the OpenGL context using the specified attributes.
- apply()[source]
Adjusts the viewport to the specified dimensions and coordinates.
The apply method sets the area of the window where OpenGL draws content. It defines the x and y coordinates of the lower-left corner of the viewport, as well as the width and height of the viewable region.
- Raises:
This function may raise an OpenGL context-specific error if incorrect –
parameters are used. –
- class picogl.backend.state.TestGLMesh(vertices, indices=None)[source]
Representation of a GL mesh with vertices, optional indices, and attributes.
This class allows for the creation and management of a graphical mesh, including the specification of vertices, optional indices, and associated attributes for rendering purposes. It provides methods to add attributes to the mesh and handle its draw using OpenGL.
- indices[source]
Optional indices for indexed rendering, allowing for more efficient rendering of shared vertices.
- Type:
Optional[Any]
- attributes[source]
A list of attribute arrays associated with the mesh, representing the additional data (e.g., colors, texture coordinates) needed for rendering.
- Type:
- attributes: list[GLAttributeArray] = [][source]
- add_attribute(attr: GLAttributeArray)[source]
Adds a GLAttributeArray instance to the attributes list.
Attributes represent specific data or configuration required for the functional operation of the object. This method allows adding new attributes dynamically to the internal list.
- Parameters:
attr (GLAttributeArray) – The attribute object to add to the list.
- draw()[source]
Draw the object using the attributes and indices provided. This method prepares and manages OpenGL draw by enabling necessary vertex attributes and rendering either indexed or non-indexed primitives based on the presence of indices.
- Raises:
RuntimeError – If an OpenGL error occurs during the draw process.
- class picogl.backend.state.DrawCommand[source]
Represents a command for draw a mesh with optional rendering parameters.
This class serves as a utility to encapsulate mesh draw operations alongside related rendering state, texture, and mode settings. It integrates with a rendering backend to facilitate the execution of draw commands.
- mesh[source]
The mesh object to be drawn. Must support a draw method or be used with a backend capable of draw it.
- Type:
Any
- mode[source]
Optional draw mode. Determines how the mesh should be rendered. Not all rendering backends require this attribute.
- Type:
int | None
- texture[source]
Optional texture or reference to a texture. If specified, the texture is bound before draw the mesh.
- Type:
GLTextureDriver | int | None
- state[source]
Optional rendering state to apply before executing the draw command.
- Type:
RenderState | None
- execute(backend
Any): Executes the draw command by applying the rendering state, binding the texture, and invoking the appropriate backend-specific draw operation.
- texture: picogl.texture.gltexture_driver.GLTextureDriver | int | None = None[source]
- state: RenderState | None = None[source]