Skip to content

pingPongFBO()

ts
function pingPongFBO<U>(
  gl: WebGL2RenderingContext,
  params: {
    uniforms?: U;
    fragment: string;
    dataTexture: {
      name?: string;
      initialData: number[] | Float32Array<ArrayBufferLike>;
    };
  },
): PingPongFBOPass<U>;

Creates a ping-pong Framebuffer Object (FBO) pass for GPGPU calculations.

This pattern uses two textures (read and write) that are swapped at each render call. It is commonly used for particle simulations, fluid dynamics, or any iterative process.

Type Parameters

U

U extends Uniforms

Parameters

gl

WebGL2RenderingContext

The WebGL2 context.

params

Configuration for the ping-pong pass.

uniforms?

U = ...

Uniforms for the pass.

fragment

string

Fragment shader source. Should read from dataTexture.name.

dataTexture

{ name?: string; initialData: number[] | Float32Array<ArrayBufferLike>; }

Initial data and uniform name for the double-buffered texture.

dataTexture.name?

string

The name of the sampler2D uniform in the fragment shader. Defaults to "tData".

dataTexture.initialData

number[] | Float32Array<ArrayBufferLike>

The raw numerical data to seed the initial texture state.

Returns

PingPongFBOPass<U>

A RenderPass object specialized for double-buffering.

Released under the MIT License.