Class WebGpuStrategyBasic

Basic WebGPU rendering strategy implementation that handles mesh rendering, storage buffer management, and shader program setup for WebGPU-based rendering pipeline.

This class provides a complete rendering solution using WebGPU API, including:

  • Storage buffer management for efficient GPU data transfer
  • Shader program compilation and setup
  • Morph target and blend shape handling
  • Camera and transform matrix updates
  • Render pass execution with proper primitive sorting
const strategy = WebGpuStrategyBasic.getInstance();
strategy.prerender();
strategy.common_$render(primitiveUids, renderPass, tickCount);

Implements

  • CGAPIStrategy

Methods

  • Loads and prepares a mesh component for rendering. Sets up vertex buffer objects (VBO) and vertex array objects (VAO) if not already done.

    Parameters

    Returns boolean

    True if the mesh was successfully loaded, false if the mesh is null

  • Performs common loading operations required for the WebGPU strategy. Initializes morph target arrays and updates blend shape storage buffers when needed.

    Returns void

  • Main rendering method that draws all primitives in the specified render pass. Handles different primitive types (opaque, translucent, blend) with appropriate depth writing settings.

    Parameters

    • primitiveUids: number[]

      Array of primitive UIDs to render, sorted by rendering order

    • renderPass: RenderPass

      The render pass configuration containing rendering settings

    • renderPassTickCount: number

      Current tick count for animation and timing purposes

    Returns boolean

    True if any primitives were successfully rendered

  • Performs pre-rendering operations required before drawing. Updates storage buffers when components have been modified and handles morph target updates. This method should be called once per frame before any rendering operations.

    Returns void

  • Renders a single primitive with the specified material and render settings. Handles shader setup, uniform buffer updates, and the actual draw call.

    Parameters

    • primitiveUid: number

      Unique identifier of the primitive to render

    • renderPass: RenderPass

      Render pass containing rendering configuration

    • zWrite: boolean

      Whether to enable depth buffer writing

    Returns boolean

    True if the primitive was successfully rendered

  • Renders a render pass using pre-built render bundles for improved performance. Render bundles allow WebGPU to optimize command encoding by pre-recording draw commands.

    Parameters

    Returns boolean

    True if the render bundle was successfully executed

  • Sets up shader programs for materials using the WebGPU rendering strategy. This method orchestrates the shader compilation process by providing the necessary method definitions and property setters.

    Parameters

    • material: Material

      The material to create shader programs for

    • primitive: Primitive

      The primitive geometry that will use this material

    • vertexShaderMethodDefinitions: string

      WGSL code containing vertex shader helper methods

    • propertySetter: getShaderPropertyFunc

      Function to generate property accessor methods

    Returns void

  • Generates vertex shader method definitions for storage buffer access. These methods provide standardized access to transform matrices, visibility flags, and morphing functionality in vertex shaders.

    Returns string

    WGSL shader code containing helper functions for storage buffer access