Class WebGLStrategyDataTexture

WebGL rendering strategy implementation that uses data textures for storing shader data. This strategy stores uniform data in textures rather than traditional uniform variables, enabling support for larger amounts of instance data and more efficient batch rendering.

This class implements both CGAPIStrategy and WebGLStrategy interfaces, providing a complete rendering pipeline for WebGL with data texture optimization. The strategy is particularly useful for rendering many instances with unique properties.

Implements

Properties

_totalSizeOfGPUShaderDataStorageExceptMorphData: number = 0

Methods

  • Loads and prepares a mesh component for rendering with the data texture strategy. This method validates the mesh, updates current component SIDs, and ensures the mesh's VBO and VAO are properly set up.

    Parameters

    • meshComponent: MeshComponent

      The mesh component to load and prepare for rendering

    Returns boolean

    true if the mesh was successfully loaded, false if there was an error

    This method performs several important tasks:

    • Validates that the mesh component has a valid mesh
    • Updates the current component SIDs for data texture access
    • Triggers VBO/VAO setup if the mesh hasn't been set up yet
    • Deletes and recreates the data texture if needed for mesh updates
  • Re-establishes a shader program for a material using updated shader sources. This method is typically called by debugging tools like Spector.js when shader sources are modified at runtime for inspection or debugging.

    Parameters

    • material: Material

      The material whose shader needs to be re-setup

    • primitive: Primitive

      The primitive geometry associated with the shader

    • updatedShaderSources: ShaderSources

      The modified shader source code

    • onError: ((message: string) => void)

      Callback function to handle compilation or linking errors

        • (message): void
        • Parameters

          • message: string

          Returns void

    Returns number

    The resource handle of the updated shader program, or InvalidCGAPIResourceUid on failure

    This method performs the same setup as setupShaderForMaterial but uses externally provided shader sources instead of generating them. It's primarily used for debugging workflows where shaders are modified at runtime.

  • Attaches GPU data for a primitive (placeholder implementation). This method is part of the CGAPIStrategy interface but is not used in the data texture strategy since data is handled through textures.

    Parameters

    • primitive: Primitive

      The primitive to attach GPU data for

    Returns void

  • Internal GPU data attachment (placeholder implementation). This method is part of the interface but not actively used in data texture strategy.

    Parameters

    • gl: WebGLRenderingContext

      The WebGL rendering context

    • shaderProgram: WebGLProgram

      The shader program to attach data to

    Returns void

  • Attaches vertex data for a primitive (placeholder implementation). This method is part of the interface but delegates to attachVertexDataInner.

    Parameters

    • i: number

      Index parameter (unused in this implementation)

    • primitive: Primitive

      The primitive to attach vertex data for

    • glw: WebGLContextWrapper

      The WebGL context wrapper

    • instanceIDBufferUid: number

      The instance ID buffer resource handle

    Returns void

  • Internal implementation for attaching vertex data to the rendering pipeline. This method binds the appropriate Vertex Array Object (VAO) or sets up vertex attribute pointers and element buffer bindings.

    Parameters

    • mesh: Mesh

      The mesh containing the vertex data

    • primitive: Primitive

      The specific primitive within the mesh

    • primitiveIndex: number

      Index of the primitive within the mesh

    • glw: WebGLContextWrapper

      The WebGL context wrapper for WebGL operations

    • instanceIDBufferUid: number

      Resource handle for instance ID buffer

    Returns void

    This method handles two scenarios:

    • If a VAO exists, it simply binds the VAO (most efficient)
    • If no VAO exists, it manually sets up vertex attributes and index buffer
  • Main rendering method that processes all primitives in a render pass. This method handles different primitive types (opaque, translucent, blend) and manages VR/non-VR rendering modes.

    Parameters

    • primitiveUids: number[]

      Array of primitive UIDs to render

    • renderPass: RenderPass

      The render pass configuration

    • renderPassTickCount: number

      Current tick count for the render pass

    Returns boolean

    true if any primitives were successfully rendered, false otherwise

    This method processes primitives in the following order:

    1. Opaque primitives (back-to-front for depth optimization)
    2. Translucent primitives (front-to-back for proper blending)
    3. Blend primitives with Z-write enabled
    4. Blend primitives without Z-write

    The method also handles buffer-less rendering mode for special cases and manages depth mask settings for different primitive types.

  • Deletes the current data texture and frees associated GPU resources. This method should be called when the data texture needs to be recreated or when cleaning up resources.

    Returns void

    After calling this method, the data texture UID is reset to an invalid state, and a new data texture will be created on the next rendering cycle.

  • Prepares the rendering pipeline before actual rendering begins. This method updates GPU storage (data texture and UBO) based on component update states and manages light components for the current frame.

    Returns void

    This method performs conditional updates based on what has changed:

    • Full update: When animation, transforms, scene graph, or materials change
    • Camera-only update: When only camera or camera controller data changes
    • Also retrieves current light components for the rendering pass

    The method tracks update counts to avoid unnecessary GPU uploads and provides optimal performance by updating only what has changed.

  • Sets up a shader program for the specified material and primitive. This method creates and configures the complete shader program including uniform locations and data texture-specific shader definitions.

    Parameters

    • material: Material

      The material that requires shader setup

    • primitive: Primitive

      The primitive geometry that will use this shader

    Returns number

    The resource handle of the created or retrieved shader program

    This method handles:

    • Creating the WebGL shader program with data texture method definitions
    • Setting up basic uniform locations for the material
    • Configuring material node uniform locations
    • Setting up additional uniform locations for point sprites
    • Configuring data texture-specific uniform locations
  • Initiates the dumping of the data texture buffer for debugging purposes. This method flags the system to export the data texture buffer contents on the next rendering cycle.

    Returns void

    The dumped buffer will be downloaded as a binary file named 'Rhodonite_dataTextureBuffer.bin'. This is useful for debugging shader data layout and content issues.

  • Gets the singleton instance of WebGLStrategyDataTexture. Creates the instance if it doesn't exist and initializes the WebXR system reference.

    Returns WebGLStrategyDataTexture

    The singleton instance of WebGLStrategyDataTexture

    This method ensures only one instance of the strategy exists throughout the application and properly initializes the WebXR system for VR/AR rendering capabilities.

  • Generates vertex shader method definitions for data texture access. These methods provide standardized ways to fetch transformation matrices, visibility flags, and other per-instance data from the data texture.

    Returns string

    A string containing GLSL shader method definitions for data texture access

    The generated methods include:

    • get_worldMatrix: Fetches world transformation matrix
    • get_normalMatrix: Fetches normal transformation matrix
    • get_isVisible: Fetches visibility flag
    • get_isBillboard: Fetches billboard flag
    • get_position: Fetches morphed vertex positions (if morphing is enabled)