Something went wrong. Try again.
A WebGPU retro game engine for TypeScript, inspired by RetroBlit. Build pixel-perfect 2D games with a clean, fantasy-console-style API.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
import { createMockGPUDevice, installMockNavigatorGPU, uninstallMockNavigatorGPU } from '../../../__test__/webgpu-mock';import { Vector2i } from '../../../utils/Vector2i';import { PixelGlitch } from './PixelGlitch';
const FORMAT: GPUTextureFormat = 'r8uint';const SIZE = new Vector2i(320, 240);
beforeAll(() => { installMockNavigatorGPU();});
afterAll(() => { uninstallMockNavigatorGPU();});
describe('PixelGlitch', () => { it("declares tier='pixel'", () => { expect(new PixelGlitch().tier).toBe('pixel'); });
it('does not create a sampler for r8uint pixel chain', () => { const device = createMockGPUDevice(); const createSampler = vi.spyOn(device, 'createSampler'); const fx = new PixelGlitch();
fx.init(device, FORMAT, SIZE);
expect(createSampler).not.toHaveBeenCalled(); });
it('init allocates a 32-byte uniform buffer', () => { const device = createMockGPUDevice(); const createBuffer = vi.spyOn(device, 'createBuffer'); const fx = new PixelGlitch();
fx.init(device, FORMAT, SIZE);
expect(createBuffer.mock.calls[0]?.[0]?.size).toBe(32); });
it('updateUniforms writes intensity, bandHeight, seed', () => { const device = createMockGPUDevice(); const writeBuffer = vi.spyOn(device.queue, 'writeBuffer'); const fx = new PixelGlitch(); fx.intensity = 0.4; fx.bandHeight = 6; fx.seed = 12;
fx.init(device, FORMAT, SIZE); fx.updateUniforms(16, SIZE);
const buf = writeBuffer.mock.calls[0]?.[2] as Float32Array; expect(buf[2]).toBeCloseTo(0.4); expect(buf[3]).toBeCloseTo(6); expect(buf[4]).toBeCloseTo(12); });});