picogl.backend.gl.api.shader

Submodules

Classes

GLShader

GL Shader

Functions

gl_attach_shader(shader_program, shader) → None

Attaches a shader object to a shader program. This function is used as part

gl_compile_shader(shader)

Compiles a specified OpenGL shader. This function wraps the OpenGL

gl_create_shader(shader_type) → int

Creates a new shader object and returns its unique ID.

gl_get_program_info_log(program) → int

Returns the information log for a program object.

gl_get_programiv(program[, status]) → int

Retrieves the integer value of a specific program parameter.

gl_get_shader_info_log(shader) → str

Retrieves the information log for a given OpenGL shader object.

gl_get_shader_iv(shader[, status]) → int

Retrieves integer value parameters of a shader object.

gl_get_uniform_location(program, name)

Retrieve the location of a uniform variable in a given shader program.

gl_link_program(program)

Links a given OpenGL program object.

gl_shader_source(shader, source) → None

Replace the source code in a shader object.

gl_uniform_matrix_4fv(location, count, transpose, value) → None

Sets a 4x4 matrix for a given uniform variable in the currently active shader program.

gl_uniform_name_matrix_4f(value, location, uniform_name) → None

Updates a 4x4 matrix uniform variable in the OpenGL shader program.

gl_use_program(shader_program) → None

Sets the active shader program for subsequent rendering operations.

Package Contents

picogl.backend.gl.api.shader.gl_attach_shader(shader_program: int, shader: int) → None[source]

Attaches a shader object to a shader program. This function is used as part of the process to create a complete shader program by linking one or more compiled shader objects.

Parameters: shader_program: int

The handle of the shader program to which the shader will be attached.

shader

The handle of the shader object to attach.

Returns: None

picogl.backend.gl.api.shader.gl_compile_shader(shader: int)[source]

Compiles a specified OpenGL shader. This function wraps the OpenGL glCompileShader call and initiates the compilation process for the given shader.

Raises:

RuntimeError – If an OpenGL error is encountered during the shader compilation process.

Parameters:

shader (int) – The handle or ID of the shader to compile. This must be a valid shader object created using OpenGL before calling this function.

picogl.backend.gl.api.shader.gl_create_shader(shader_type: GLShader) → int[source]

Creates a new shader object and returns its unique ID.

Shaders are fundamental components of the shader pipeline in OpenGL, used to process vertex and fragment data in rendering. This function wraps the OpenGL call to create a shader object of a specified type.

Parameters: shader_type: GLShader

The type of the shader to be created. Common types include GL_VERTEX_SHADER and GL_FRAGMENT_SHADER.

Returns: int

The unique identifier of the created shader.

Raises: Exception

If shader creation fails due to invalid shader type or OpenGL-related issues.

picogl.backend.gl.api.shader.gl_get_program_info_log(program: int) → int[source]

Returns the information log for a program object.

This function retrieves the information log for a shader program object. The information log can provide details about the linking process or other states of the program, which can aid in debugging or understanding error in the program.

Parameters: program (int): The handle of the program object whose information log is to

be retrieved.

Returns: int: The length of the information log, in characters, associated with the

specified program object.

picogl.backend.gl.api.shader.gl_get_programiv(program: int, status: int = GL_LINK_STATUS) → int[source]

Retrieves the integer value of a specific program parameter.

This function is used to retrieve the value of a specified parameter for a given shader program. Primarily, it is employed to determine the status or characteristics of a shader program after linking or during its lifecycle.

Parameters: program (int): The handle of the shader program whose parameter is to be retrieved. status (int): The specific program parameter to query. Default is GL_LINK_STATUS.

Returns: int: The integer value of the specified program parameter.

picogl.backend.gl.api.shader.gl_get_shader_info_log(shader) → str[source]

Retrieves the information log for a given OpenGL shader object.

The function acts as a wrapper around OpenGL’s glGetShaderInfoLog method, which retrieves a human-readable debugging or error log associated with a specified shader. This log can include compiler messages, warnings, or error.

Parameters: shader (int): The shader object for which the information log needs to be retrieved. This is usually the identifier returned by OpenGL when the shader was created.

Returns: str: The information log associated with the given shader. It contains informational messages, warnings, or error produced during shader compilation.

Raises: TypeError: If the provided shader is not an integer.

picogl.backend.gl.api.shader.gl_get_shader_iv(shader: int, status: int = GL_COMPILE_STATUS) → int[source]

Retrieves integer value parameters of a shader object.

This function is used to query information about a shader object, such as its compile status, by retrieving a parameter specified by the status argument.

Parameters:
  • shader – Represents the identifier of the shader object whose parameter is being queried.

  • status – Specifies the parameter to query for the shader object. Defaults to GL_COMPILE_STATUS.

Returns:

An integer value representing the requested parameter of the shader object.

picogl.backend.gl.api.shader.gl_get_uniform_location(program: int, name: str)[source]

Retrieve the location of a uniform variable in a given shader program.

This function retrieves the location of a uniform variable specified by its name from a provided shader program. The location is used to set the values of uniform variables in a shader during rendering. The function relies on glGetUniformLocation from an OpenGL context.

Parameters: program (int): An integer representing the OpenGL shader program from which the

uniform location should be retrieved.

name: The name of the uniform variable whose location needs to be determined.

Returns: int: The location of the uniform variable in the shader program. If the uniform

variable does not exist in the program, a value of -1 will be returned.

Raises: TypeError: If the parameter types are not as expected or if the input arguments

are invalid.

Links a given OpenGL program object.

This function wraps the OpenGL glLinkProgram function, which links a program object specified by the “program” parameter. The program object must contain all the necessary shaders attached before linking.

Parameters:

program (int) – The ID of the OpenGL program object to link.

picogl.backend.gl.api.shader.gl_shader_source(shader: int, source: str | bytes | list[str]) → None[source]

Replace the source code in a shader object.

Parameters:
  • shader – OpenGL shader object handle.

  • source – GLSL source as a string, bytes, or list of strings.

class picogl.backend.gl.api.shader.GLShader[source]

Bases: enum.IntEnum

GL Shader

VERTEX_SHADER
FRAGMENT_SHADER
picogl.backend.gl.api.shader.gl_uniform_matrix_4fv(location: int, count: int, transpose: picogl.boolean.GLBoolean, value: Any) → None[source]

Sets a 4x4 matrix for a given uniform variable in the currently active shader program.

Parameters: location (int): The location of the uniform variable to be updated. count (int): The number of matrices to be loaded. Typically 1. transpose (GLBoolean): Specifies whether to transpose the matrix values. value (Any): The matrix data to be assigned to the uniform variable.

Returns: None

picogl.backend.gl.api.shader.gl_uniform_name_matrix_4f(value: Any, location: int, uniform_name: str) → None[source]

Updates a 4x4 matrix uniform variable in the OpenGL shader program.

This function sets the value of a 4x4 matrix uniform variable within a specified OpenGL shader program. It locates the uniform variable by its name and location, then applies the given matrix value.

Parameters: value : Any

The 4x4 matrix to be used as the uniform value in the shader.

locationint

The reference to the OpenGL shader program.

uniform_namestr

The name of the uniform variable within the shader program.

Returns: None

picogl.backend.gl.api.shader.gl_use_program(shader_program: int) → None[source]

Sets the active shader program for subsequent rendering operations.

This function enables the use of a specific shader program for OpenGL rendering. Once set, all subsequent rendering operations will utilize the provided shader program until a different program is set or the shader program is disabled.

Parameters: shader_program: int

The ID of the OpenGL shader program to be activated.

Returns: None