All files / player-browser/src/skins/pixi-kit gpu-pass.ts

100% Statements 7/7
100% Branches 0/0
100% Functions 2/2
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28          48x               4x         3x 3x 4x 4x   1x        
import type { Renderer } from 'pixi.js';
 
/** Work a skin wants done on the GPU before the frame is drawn, e.g. stepping a particle simulation in textures. */
export type GPUPass = (renderer: Renderer) => void;
 
const pending: GPUPass[] = [];
 
/**
 * Queues `pass` to run on the renderer that draws the frame being built, right before it is drawn. Call it while
 * building the frame (from `render`, `tick` or a chrome function); passes queued outside a build run before the next
 * frame instead.
 */
export function queueGPUPass(pass: GPUPass): void {
  pending.push(pass);
}
 
/** Runs and clears every queued pass, in the order they were queued. A failing pass doesn't stop the rest. */
export function runGPUPasses(renderer: Renderer, onError?: (error: unknown) => void): void {
  const passes = pending.splice(0);
  for (const pass of passes) {
    try {
      pass(renderer);
    } catch (error) {
      onError?.(error);
    }
  }
}