@quake2ts/test-utils 0.0.764 → 0.0.766
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +54 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -7
- package/dist/index.d.ts +25 -7
- package/dist/index.js +52 -56
- package/dist/index.js.map +1 -1
- package/package.json +14 -9
- package/src/engine/helpers/webgl-rendering.ts +47 -0
- package/src/index.ts +5 -2
- package/src/setup/headless-webgl.ts +54 -51
package/dist/index.cjs
CHANGED
|
@@ -6160,6 +6160,7 @@ __export(index_exports, {
|
|
|
6160
6160
|
createVector3: () => createVector3,
|
|
6161
6161
|
createViewTestScenario: () => createViewTestScenario,
|
|
6162
6162
|
createVisualTestScenario: () => createVisualTestScenario,
|
|
6163
|
+
createWebGLRenderTestSetup: () => createWebGLRenderTestSetup,
|
|
6163
6164
|
expectSnapshot: () => expectSnapshot,
|
|
6164
6165
|
findPakFile: () => findPakFile,
|
|
6165
6166
|
flipPixelsVertically: () => flipPixelsVertically,
|
|
@@ -6181,6 +6182,7 @@ __export(index_exports, {
|
|
|
6181
6182
|
parseProtocolPlayerState: () => parseProtocolPlayerState,
|
|
6182
6183
|
randomVector3: () => randomVector3,
|
|
6183
6184
|
renderAndCapture: () => renderAndCapture,
|
|
6185
|
+
renderAndCaptureWebGL: () => renderAndCaptureWebGL,
|
|
6184
6186
|
renderAndExpectSnapshot: () => renderAndExpectSnapshot,
|
|
6185
6187
|
restoreSaveGameSnapshot: () => restoreSaveGameSnapshot,
|
|
6186
6188
|
runComputeAndReadback: () => runComputeAndReadback,
|
|
@@ -8940,60 +8942,58 @@ async function createHeadlessTestContext() {
|
|
|
8940
8942
|
}
|
|
8941
8943
|
|
|
8942
8944
|
// src/setup/headless-webgl.ts
|
|
8943
|
-
|
|
8945
|
+
function createHeadlessWebGL(options = {}) {
|
|
8944
8946
|
const width = options.width ?? 256;
|
|
8945
8947
|
const height = options.height ?? 256;
|
|
8946
|
-
|
|
8947
|
-
|
|
8948
|
+
let createGL;
|
|
8949
|
+
try {
|
|
8950
|
+
createGL = require_gl();
|
|
8951
|
+
} catch (e) {
|
|
8952
|
+
throw new Error("gl package not found or failed to load. Install it to run WebGL tests.");
|
|
8953
|
+
}
|
|
8954
|
+
const glContext = createGL(width, height, {
|
|
8948
8955
|
antialias: options.antialias ?? false,
|
|
8949
|
-
// Default to false for
|
|
8956
|
+
// Default to false for deterministic testing
|
|
8950
8957
|
preserveDrawingBuffer: options.preserveDrawingBuffer ?? true,
|
|
8951
|
-
//
|
|
8958
|
+
// Needed for readback
|
|
8952
8959
|
stencil: true,
|
|
8953
|
-
|
|
8954
|
-
|
|
8960
|
+
depth: true,
|
|
8961
|
+
alpha: true
|
|
8955
8962
|
});
|
|
8956
|
-
if (!
|
|
8963
|
+
if (!glContext) {
|
|
8957
8964
|
throw new Error("Failed to create headless WebGL context");
|
|
8958
8965
|
}
|
|
8959
|
-
const
|
|
8966
|
+
const gl = glContext;
|
|
8967
|
+
const version = gl.getParameter(gl.VERSION);
|
|
8968
|
+
const cleanup = () => {
|
|
8969
|
+
const ext = gl.getExtension("STACKGL_destroy_context");
|
|
8970
|
+
if (ext) {
|
|
8971
|
+
ext.destroy();
|
|
8972
|
+
}
|
|
8973
|
+
};
|
|
8960
8974
|
return {
|
|
8961
|
-
gl
|
|
8975
|
+
gl,
|
|
8962
8976
|
width,
|
|
8963
8977
|
height,
|
|
8964
|
-
cleanup
|
|
8965
|
-
const ext = glContext.getExtension("STACKGL_destroy_context");
|
|
8966
|
-
if (ext) {
|
|
8967
|
-
ext.destroy();
|
|
8968
|
-
}
|
|
8969
|
-
}
|
|
8978
|
+
cleanup
|
|
8970
8979
|
};
|
|
8971
8980
|
}
|
|
8972
|
-
function captureWebGLFramebuffer(
|
|
8981
|
+
function captureWebGLFramebuffer(gl, width, height) {
|
|
8973
8982
|
const pixels = new Uint8ClampedArray(width * height * 4);
|
|
8974
|
-
|
|
8975
|
-
0,
|
|
8976
|
-
0,
|
|
8977
|
-
width,
|
|
8978
|
-
height,
|
|
8979
|
-
glContext.RGBA,
|
|
8980
|
-
glContext.UNSIGNED_BYTE,
|
|
8981
|
-
pixels
|
|
8982
|
-
);
|
|
8983
|
+
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
|
|
8983
8984
|
return flipPixelsVertically(pixels, width, height);
|
|
8984
8985
|
}
|
|
8985
8986
|
function flipPixelsVertically(pixels, width, height) {
|
|
8987
|
+
const flipped = new Uint8ClampedArray(pixels.length);
|
|
8986
8988
|
const rowSize = width * 4;
|
|
8987
|
-
|
|
8988
|
-
|
|
8989
|
-
|
|
8990
|
-
|
|
8991
|
-
|
|
8992
|
-
|
|
8993
|
-
pixels.copyWithin(topOffset, bottomOffset, bottomOffset + rowSize);
|
|
8994
|
-
pixels.set(tempRow, bottomOffset);
|
|
8989
|
+
for (let y = 0; y < height; y++) {
|
|
8990
|
+
const srcRowStart = y * rowSize;
|
|
8991
|
+
const destRowStart = (height - 1 - y) * rowSize;
|
|
8992
|
+
for (let i = 0; i < rowSize; i++) {
|
|
8993
|
+
flipped[destRowStart + i] = pixels[srcRowStart + i];
|
|
8994
|
+
}
|
|
8995
8995
|
}
|
|
8996
|
-
return
|
|
8996
|
+
return flipped;
|
|
8997
8997
|
}
|
|
8998
8998
|
|
|
8999
8999
|
// src/engine/mocks/webgpu.ts
|
|
@@ -10223,6 +10223,23 @@ async function runComputeAndReadback(setup, computeFn) {
|
|
|
10223
10223
|
return result;
|
|
10224
10224
|
}
|
|
10225
10225
|
|
|
10226
|
+
// src/engine/helpers/webgl-rendering.ts
|
|
10227
|
+
async function createWebGLRenderTestSetup(width = 256, height = 256) {
|
|
10228
|
+
const context = createHeadlessWebGL({ width, height });
|
|
10229
|
+
return {
|
|
10230
|
+
gl: context.gl,
|
|
10231
|
+
width: context.width,
|
|
10232
|
+
height: context.height,
|
|
10233
|
+
cleanup: context.cleanup
|
|
10234
|
+
};
|
|
10235
|
+
}
|
|
10236
|
+
async function renderAndCaptureWebGL(setup, renderFn) {
|
|
10237
|
+
const { gl, width, height } = setup;
|
|
10238
|
+
renderFn(gl);
|
|
10239
|
+
gl.finish();
|
|
10240
|
+
return captureWebGLFramebuffer(gl, width, height);
|
|
10241
|
+
}
|
|
10242
|
+
|
|
10226
10243
|
// src/engine/helpers/pipeline-test-template.ts
|
|
10227
10244
|
var import_vitest18 = require("vitest");
|
|
10228
10245
|
async function testPipelineRendering(name, createPipeline, setupGeometry, expectedOutput) {
|
|
@@ -11329,6 +11346,7 @@ function createVisualTestScenario(sceneName) {
|
|
|
11329
11346
|
createVector3,
|
|
11330
11347
|
createViewTestScenario,
|
|
11331
11348
|
createVisualTestScenario,
|
|
11349
|
+
createWebGLRenderTestSetup,
|
|
11332
11350
|
expectSnapshot,
|
|
11333
11351
|
findPakFile,
|
|
11334
11352
|
flipPixelsVertically,
|
|
@@ -11350,6 +11368,7 @@ function createVisualTestScenario(sceneName) {
|
|
|
11350
11368
|
parseProtocolPlayerState,
|
|
11351
11369
|
randomVector3,
|
|
11352
11370
|
renderAndCapture,
|
|
11371
|
+
renderAndCaptureWebGL,
|
|
11353
11372
|
renderAndExpectSnapshot,
|
|
11354
11373
|
restoreSaveGameSnapshot,
|
|
11355
11374
|
runComputeAndReadback,
|