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
29
30
31
32
33
34
35
|
import { getWebGLContext, readResult } from "./webgl-context";
import { applyMultiPassEffect } from "./webgl-utils";
import type { EffectPassData } from "./webgl-utils";
export interface ApplyEffectParams {
source: CanvasImageSource;
width: number;
height: number;
passes: EffectPassData[];
}
function applyEffect({
source,
width,
height,
passes,
}: ApplyEffectParams): CanvasImageSource {
if (passes.length === 0) {
return source;
}
const { context, programCache } = getWebGLContext({ width, height });
applyMultiPassEffect({
context,
source,
width,
height,
passes,
programCache,
});
return readResult({ width, height });
}
export const webglEffectRenderer = {
applyEffect,
};
|