// src/engine/pingPong.ts
// Helper that holds two GPU resources and swaps them per frame.
export class PingPong<T> {
private a: T;
private b: T;
constructor(a: T, b: T) {
this.a = a;
this.b = b;
}
get read(): T {
return this.a;
}
get write(): T {
return this.b;
}
swap(): void {
const tmp = this.a;
this.a = this.b;
this.b = tmp;
}
destroy(destroyFn: (resource: T) => void): void {
destroyFn(this.a);
destroyFn(this.b);
}
}