rhodonite
    Preparing search index...

    Class ShaderityUtilityWebGL

    A utility class for processing and managing Shaderity shader objects in WebGL environments.

    This class provides comprehensive functionality for shader processing including:

    • Template filling and parameter substitution in shader code
    • WebGL version compatibility transformations (WebGL 1.0/2.0)
    • Shader reflection for extracting vertex attribute information
    • Uniform declaration parsing and semantic information extraction
    • Initial value parsing and type conversion for shader uniforms

    The class integrates with the Shaderity library to provide enhanced shader processing capabilities specifically tailored for the Rhodonite rendering engine's WebGL backend. It handles the complex process of analyzing GLSL shader code, extracting metadata from comments, and preparing shader objects for use in the rendering pipeline.

    All methods are static and the class serves as a namespace for shader utility functions.

    // Fill shader template with arguments
    const filledShader = ShaderityUtilityWebGL.fillTemplate(shaderObject, { color: 'red' });

    // Transform for WebGL 2.0 compatibility
    const webgl2Shader = ShaderityUtilityWebGL.transformWebGLVersion(filledShader, true);

    // Extract vertex attribute information
    const attributes = ShaderityUtilityWebGL.getAttributeReflection(webgl2Shader);
    Index

    Constructors

    Methods

    • Fills template placeholders in a shader object with provided arguments and WebGL-specific parameters. This method performs a two-step template filling process: first with user-provided arguments, then with WebGL resource repository specific parameters.

      Parameters

      • engine: Engine
      • shaderityObject: ShaderityObject

        The shader object containing template placeholders to be filled

      • primitive: Primitive
      • args: FillArgsObject

        Key-value pairs of template arguments to fill in the shader

      Returns ShaderityObject

      A new ShaderityObject with all template placeholders replaced

    • Extracts vertex attribute information from a shader object using reflection. This method analyzes the shader code to determine vertex attribute names, semantics, compositions, and component types required for proper vertex buffer binding.

      Parameters

      • shaderityObject: ShaderityObject

        The shader object to analyze for vertex attributes

      Returns VertexAttributesLayout

      An object containing arrays of attribute names, semantics, compositions, and components

    • Extracts shader uniform data and semantic information from a shader object. This method parses uniform declarations in the shader code, extracts metadata from comments, and creates semantic information objects for each uniform.

      Parameters

      • engine: Engine
      • shaderityObject: ShaderityObject

        The shader object to analyze for uniform declarations

      Returns {
          shaderityObject: ShaderityObject;
          shaderSemanticsInfoArray: ShaderSemanticsInfo[];
      }

      An object containing an array of shader semantic info and a modified shader object with uniforms removed

    • Transforms a shader object to target a specific WebGL version (WebGL 1.0 or 2.0). This method converts GLSL code to be compatible with either GLSL ES 1.0 or 3.0 depending on the WebGL version being used.

      Parameters

      • shaderityObject: ShaderityObject

        The shader object to transform

      • isWebGL2: boolean

        Whether to target WebGL 2.0 (true) or WebGL 1.0 (false)

      Returns ShaderityObject

      A new ShaderityObject with version-appropriate GLSL code