picogl.backend.gl.api.shader ============================ .. py:module:: picogl.backend.gl.api.shader Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/picogl/backend/gl/api/shader/attach/index /autoapi/picogl/backend/gl/api/shader/compile/index /autoapi/picogl/backend/gl/api/shader/create/index /autoapi/picogl/backend/gl/api/shader/getter/index /autoapi/picogl/backend/gl/api/shader/link/index /autoapi/picogl/backend/gl/api/shader/source/index /autoapi/picogl/backend/gl/api/shader/uniform/index /autoapi/picogl/backend/gl/api/shader/use/index Classes ------- .. autoapisummary:: picogl.backend.gl.api.shader.GLShader Functions --------- .. autoapisummary:: picogl.backend.gl.api.shader.gl_attach_shader picogl.backend.gl.api.shader.gl_compile_shader picogl.backend.gl.api.shader.gl_create_shader picogl.backend.gl.api.shader.gl_get_program_info_log picogl.backend.gl.api.shader.gl_get_programiv picogl.backend.gl.api.shader.gl_get_shader_info_log picogl.backend.gl.api.shader.gl_get_shader_iv picogl.backend.gl.api.shader.gl_get_uniform_location picogl.backend.gl.api.shader.gl_link_program picogl.backend.gl.api.shader.gl_shader_source picogl.backend.gl.api.shader.gl_uniform_matrix_4fv picogl.backend.gl.api.shader.gl_uniform_name_matrix_4f picogl.backend.gl.api.shader.gl_use_program Package Contents ---------------- .. py:function:: gl_attach_shader(shader_program: int, shader: int) -> None 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 .. py:function:: gl_compile_shader(shader: int) 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. :param shader: The handle or ID of the shader to compile. This must be a valid shader object created using OpenGL before calling this function. :type shader: int .. py:function:: gl_create_shader(shader_type: GLShader) -> int 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. .. py:function:: gl_get_program_info_log(program: int) -> int 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. .. py:function:: gl_get_programiv(program: int, status: int = GL_LINK_STATUS) -> int 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. .. py:function:: gl_get_shader_info_log(shader) -> str 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. .. py:function:: gl_get_shader_iv(shader: int, status: int = GL_COMPILE_STATUS) -> int 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. :param shader: Represents the identifier of the shader object whose parameter is being queried. :param 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. .. py:function:: gl_get_uniform_location(program: int, name: str) 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. .. py:function:: gl_link_program(program: int) 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. :param program: The ID of the OpenGL program object to link. :type program: int .. py:function:: gl_shader_source(shader: int, source: str | bytes | list[str]) -> None Replace the source code in a shader object. :param shader: OpenGL shader object handle. :param source: GLSL source as a string, bytes, or list of strings. .. py:class:: GLShader Bases: :py:obj:`enum.IntEnum` GL Shader .. py:attribute:: VERTEX_SHADER .. py:attribute:: FRAGMENT_SHADER .. py:function:: gl_uniform_matrix_4fv(location: int, count: int, transpose: picogl.boolean.GLBoolean, value: Any) -> None 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 .. py:function:: gl_uniform_name_matrix_4f(value: Any, location: int, uniform_name: str) -> None 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. location : int The reference to the OpenGL shader program. uniform_name : str The name of the uniform variable within the shader program. Returns: None .. py:function:: gl_use_program(shader_program: int) -> None 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