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.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
import { createMockGPUDevice, installMockNavigatorGPU, uninstallMockNavigatorGPU } from '../../../__test__/webgpu-mock';import { Vector2i } from '../../../utils/Vector2i';import { PixelMosaic } from './PixelMosaic';
const FORMAT: GPUTextureFormat = 'r8uint';const SIZE = new Vector2i(320, 240);
beforeAll(() => { installMockNavigatorGPU();});
afterAll(() => { uninstallMockNavigatorGPU();});
describe('PixelMosaic', () => { it("declares tier='pixel'", () => { expect(new PixelMosaic().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 PixelMosaic();
fx.init(device, FORMAT, SIZE);
expect(createSampler).not.toHaveBeenCalled(); });
it('updateUniforms writes blockSize', () => { const device = createMockGPUDevice(); const writeBuffer = vi.spyOn(device.queue, 'writeBuffer'); const fx = new PixelMosaic(); fx.blockSize = 8;
fx.init(device, FORMAT, SIZE); fx.updateUniforms(16, SIZE);
expect(writeBuffer).toHaveBeenCalledTimes(1); const buf = writeBuffer.mock.calls[0]?.[2] as Float32Array; expect(buf[2]).toBeCloseTo(8); });});