@flighthq/scene2d-wgpu 0.5.1-next.973.788d3d7 → 0.6.0
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/README.md +2 -2
- package/dist/.tsbuildinfo.contract +1 -0
- package/dist/.tsbuildinfo.runtime +1 -0
- package/dist/contract.d.ts +32 -34
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +32 -34
- package/dist/contract.js.map +1 -1
- package/dist/contract.scene2d-wgpu-types.d.ts +6 -0
- package/dist/contract.scene2d-wgpu-types.d.ts.map +1 -0
- package/dist/contract.scene2d-wgpu-types.js +2 -0
- package/dist/contract.scene2d-wgpu-types.js.map +1 -0
- package/dist/enableWgpuColorAdjustmentGuards.d.ts +3 -2
- package/dist/enableWgpuColorAdjustmentGuards.d.ts.map +1 -1
- package/dist/enableWgpuColorAdjustmentGuards.js +23 -14
- package/dist/enableWgpuColorAdjustmentGuards.js.map +1 -1
- package/dist/enableWgpuStrokePathTessellation.d.ts +1 -1
- package/dist/enableWgpuStrokePathTessellation.d.ts.map +1 -1
- package/dist/enableWgpuStrokePathTessellation.js +1 -6
- package/dist/enableWgpuStrokePathTessellation.js.map +1 -1
- package/dist/index.d.ts +23 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -2
- package/dist/index.js.map +1 -1
- package/dist/scene2DWgpuPipeline.d.ts +13 -0
- package/dist/scene2DWgpuPipeline.d.ts.map +1 -0
- package/dist/scene2DWgpuPipeline.js +59 -0
- package/dist/scene2DWgpuPipeline.js.map +1 -0
- package/dist/types/WgpuColorAdjustmentMaterialFeature.d.ts +2 -0
- package/dist/types/WgpuColorAdjustmentMaterialFeature.d.ts.map +1 -0
- package/dist/types/WgpuColorAdjustmentMaterialFeature.js +2 -0
- package/dist/types/WgpuColorAdjustmentMaterialFeature.js.map +1 -0
- package/dist/types/WgpuRenderStats.d.ts +12 -0
- package/dist/types/WgpuRenderStats.d.ts.map +1 -0
- package/dist/types/WgpuRenderStats.js +2 -0
- package/dist/types/WgpuRenderStats.js.map +1 -0
- package/dist/types/WgpuRichTextOverlay.d.ts +4 -0
- package/dist/types/WgpuRichTextOverlay.d.ts.map +1 -0
- package/dist/types/WgpuRichTextOverlay.js +2 -0
- package/dist/types/WgpuRichTextOverlay.js.map +1 -0
- package/dist/types/WgpuShapeMesh.d.ts +2 -0
- package/dist/types/WgpuShapeMesh.d.ts.map +1 -0
- package/dist/types/WgpuShapeMesh.js +2 -0
- package/dist/types/WgpuShapeMesh.js.map +1 -0
- package/dist/types/WgpuShapeRendererData.d.ts +17 -0
- package/dist/types/WgpuShapeRendererData.d.ts.map +1 -0
- package/dist/types/WgpuShapeRendererData.js +2 -0
- package/dist/types/WgpuShapeRendererData.js.map +1 -0
- package/dist/wgpuBitmapText.d.ts +2 -2
- package/dist/wgpuBitmapText.d.ts.map +1 -1
- package/dist/wgpuBitmapText.js +6 -6
- package/dist/wgpuBitmapText.js.map +1 -1
- package/dist/wgpuCache.d.ts +9 -6
- package/dist/wgpuCache.d.ts.map +1 -1
- package/dist/wgpuCache.js +17 -18
- package/dist/wgpuCache.js.map +1 -1
- package/dist/wgpuClip.d.ts +1 -1
- package/dist/wgpuClip.d.ts.map +1 -1
- package/dist/wgpuClip.js +2 -2
- package/dist/wgpuClip.js.map +1 -1
- package/dist/wgpuClipContours.d.ts +3 -1
- package/dist/wgpuClipContours.d.ts.map +1 -1
- package/dist/wgpuClipContours.js +7 -8
- package/dist/wgpuClipContours.js.map +1 -1
- package/dist/wgpuClipRectangle.d.ts +2 -1
- package/dist/wgpuClipRectangle.d.ts.map +1 -1
- package/dist/wgpuClipRectangle.js +4 -5
- package/dist/wgpuClipRectangle.js.map +1 -1
- package/dist/wgpuColorAdjustmentMaterialFeature.d.ts +1 -1
- package/dist/wgpuColorAdjustmentMaterialFeature.d.ts.map +1 -1
- package/dist/wgpuColorAdjustmentMaterialFeature.js +9 -13
- package/dist/wgpuColorAdjustmentMaterialFeature.js.map +1 -1
- package/dist/wgpuMeshShapeRenderer.d.ts +3 -2
- package/dist/wgpuMeshShapeRenderer.d.ts.map +1 -1
- package/dist/wgpuMeshShapeRenderer.js +9 -8
- package/dist/wgpuMeshShapeRenderer.js.map +1 -1
- package/dist/wgpuNode2D.d.ts +6 -3
- package/dist/wgpuNode2D.d.ts.map +1 -1
- package/dist/wgpuNode2D.js +20 -4
- package/dist/wgpuNode2D.js.map +1 -1
- package/dist/wgpuParticleEmitter2D.d.ts +4 -2
- package/dist/wgpuParticleEmitter2D.d.ts.map +1 -1
- package/dist/wgpuParticleEmitter2D.js +8 -8
- package/dist/wgpuParticleEmitter2D.js.map +1 -1
- package/dist/wgpuQuadBatch.d.ts +3 -3
- package/dist/wgpuQuadBatch.d.ts.map +1 -1
- package/dist/wgpuQuadBatch.js +6 -6
- package/dist/wgpuQuadBatch.js.map +1 -1
- package/dist/wgpuQuadBatchWriter.d.ts +9 -5
- package/dist/wgpuQuadBatchWriter.d.ts.map +1 -1
- package/dist/wgpuQuadBatchWriter.js +12 -8
- package/dist/wgpuQuadBatchWriter.js.map +1 -1
- package/dist/wgpuRasterShapeRenderer.d.ts +3 -2
- package/dist/wgpuRasterShapeRenderer.d.ts.map +1 -1
- package/dist/wgpuRasterShapeRenderer.js +41 -22
- package/dist/wgpuRasterShapeRenderer.js.map +1 -1
- package/dist/wgpuRenderStats.d.ts +2 -1
- package/dist/wgpuRenderStats.d.ts.map +1 -1
- package/dist/wgpuRenderStats.js.map +1 -1
- package/dist/wgpuRendererData.d.ts +2 -1
- package/dist/wgpuRendererData.d.ts.map +1 -1
- package/dist/wgpuRendererData.js +1 -1
- package/dist/wgpuRendererData.js.map +1 -1
- package/dist/wgpuRichText.d.ts +6 -3
- package/dist/wgpuRichText.d.ts.map +1 -1
- package/dist/wgpuRichText.js +67 -34
- package/dist/wgpuRichText.js.map +1 -1
- package/dist/wgpuScale9Mapper.d.ts +2 -1
- package/dist/wgpuScale9Mapper.d.ts.map +1 -1
- package/dist/wgpuScale9Mapper.js.map +1 -1
- package/dist/wgpuScale9Shape.d.ts +10 -5
- package/dist/wgpuScale9Shape.d.ts.map +1 -1
- package/dist/wgpuScale9Shape.js +54 -28
- package/dist/wgpuScale9Shape.js.map +1 -1
- package/dist/wgpuScale9Sprite.d.ts +3 -2
- package/dist/wgpuScale9Sprite.d.ts.map +1 -1
- package/dist/wgpuScale9Sprite.js +9 -10
- package/dist/wgpuScale9Sprite.js.map +1 -1
- package/dist/wgpuShape.d.ts +4 -3
- package/dist/wgpuShape.d.ts.map +1 -1
- package/dist/wgpuShape.js +7 -7
- package/dist/wgpuShape.js.map +1 -1
- package/dist/wgpuShapeData.d.ts +8 -3
- package/dist/wgpuShapeData.d.ts.map +1 -1
- package/dist/wgpuShapeData.js +12 -9
- package/dist/wgpuShapeData.js.map +1 -1
- package/dist/wgpuShapeMesh.d.ts +4 -2
- package/dist/wgpuShapeMesh.d.ts.map +1 -1
- package/dist/wgpuShapeMesh.js +9 -8
- package/dist/wgpuShapeMesh.js.map +1 -1
- package/dist/wgpuShapeRasterizer.d.ts +2 -1
- package/dist/wgpuShapeRasterizer.d.ts.map +1 -1
- package/dist/wgpuShapeRasterizer.js +3 -8
- package/dist/wgpuShapeRasterizer.js.map +1 -1
- package/dist/wgpuSprite.d.ts +3 -2
- package/dist/wgpuSprite.d.ts.map +1 -1
- package/dist/wgpuSprite.js +7 -8
- package/dist/wgpuSprite.js.map +1 -1
- package/dist/wgpuStandardMaterial.d.ts +2 -2
- package/dist/wgpuStandardMaterial.d.ts.map +1 -1
- package/dist/wgpuStandardMaterial.js +5 -5
- package/dist/wgpuStandardMaterial.js.map +1 -1
- package/dist/wgpuTextInput.d.ts +2 -1
- package/dist/wgpuTextInput.d.ts.map +1 -1
- package/dist/wgpuTextInput.js +6 -7
- package/dist/wgpuTextInput.js.map +1 -1
- package/dist/wgpuTextLabel.d.ts +3 -2
- package/dist/wgpuTextLabel.d.ts.map +1 -1
- package/dist/wgpuTextLabel.js +67 -35
- package/dist/wgpuTextLabel.js.map +1 -1
- package/dist/wgpuTilemap.d.ts +2 -2
- package/dist/wgpuTilemap.d.ts.map +1 -1
- package/dist/wgpuTilemap.js +6 -6
- package/dist/wgpuTilemap.js.map +1 -1
- package/dist/wgpuVelocity.d.ts +10 -7
- package/dist/wgpuVelocity.d.ts.map +1 -1
- package/dist/wgpuVelocity.js +89 -87
- package/dist/wgpuVelocity.js.map +1 -1
- package/package.json +31 -25
- package/src/contract.test.ts +13 -0
- package/src/enableWgpuColorAdjustmentGuards.test.ts +50 -28
- package/src/enableWgpuStrokePathTessellation.test.ts +4 -9
- package/src/scene2DWgpuPipeline.test.ts +53 -0
- package/src/wgpuBitmapText.test.ts +10 -10
- package/src/wgpuCache.test.ts +130 -168
- package/src/wgpuClip.test.ts +1 -1
- package/src/wgpuClipContours.test.ts +13 -6
- package/src/wgpuClipRectangle.test.ts +8 -8
- package/src/wgpuColorAdjustmentMaterialFeature.test.ts +20 -19
- package/src/wgpuMeshShapeRenderer.test.ts +51 -52
- package/src/wgpuNode2D.test.ts +14 -14
- package/src/wgpuParticleEmitter2D.test.ts +52 -45
- package/src/wgpuQuadBatch.test.ts +62 -60
- package/src/wgpuQuadBatchWriter.test.ts +76 -34
- package/src/wgpuRasterShapeRenderer.test.ts +95 -57
- package/src/wgpuRenderStats.test.ts +1 -1
- package/src/wgpuRendererData.test.ts +2 -2
- package/src/wgpuRichText.test.ts +109 -58
- package/src/wgpuScale9Mapper.test.ts +1 -1
- package/src/wgpuScale9Shape.test.ts +103 -62
- package/src/wgpuScale9Sprite.test.ts +31 -36
- package/src/wgpuShape.test.ts +111 -76
- package/src/wgpuShapeData.test.ts +96 -53
- package/src/wgpuShapeMesh.test.ts +39 -25
- package/src/wgpuShapeRasterizer.test.ts +11 -7
- package/src/wgpuSprite.test.ts +36 -27
- package/src/wgpuStandardMaterial.test.ts +9 -13
- package/src/wgpuTextInput.test.ts +9 -6
- package/src/wgpuTextLabel.test.ts +145 -88
- package/src/wgpuTilemap.test.ts +11 -11
- package/src/wgpuVelocity.test.ts +86 -86
- package/dist/scene2dWgpuPipeline.d.ts +0 -3
- package/dist/scene2dWgpuPipeline.d.ts.map +0 -1
- package/dist/scene2dWgpuPipeline.js +0 -40
- package/dist/scene2dWgpuPipeline.js.map +0 -1
|
@@ -1,47 +1,33 @@
|
|
|
1
|
+
import type { ColorScaleBias } from '@flighthq/adjustments/contract';
|
|
2
|
+
import { EntityRuntimeKey } from '@flighthq/entity/contract';
|
|
1
3
|
import {
|
|
4
|
+
beginWgpuScreenRenderPassForTest,
|
|
2
5
|
createWgpuRenderStateForTest,
|
|
3
|
-
getWgpuPipelineRegistries,
|
|
4
6
|
getWgpuRenderStateRuntime,
|
|
5
7
|
installWgpuMock,
|
|
6
8
|
registerWgpuRenderTextureResolver,
|
|
7
9
|
renderIntoWgpuRenderTexture,
|
|
8
|
-
|
|
9
|
-
submitWgpuRenderPass,
|
|
10
|
+
submitWgpuFrame,
|
|
10
11
|
} from '@flighthq/render-wgpu/contract';
|
|
12
|
+
import type { WgpuTexture, WgpuTextureEntry, WgpuTextureView } from '@flighthq/render-wgpu/contract';
|
|
13
|
+
import type { RenderProxy2D } from '@flighthq/render/contract';
|
|
14
|
+
import type { Scale9Sprite } from '@flighthq/scene2d/contract';
|
|
15
|
+
import { Scale9SpriteKind } from '@flighthq/scene2d/contract';
|
|
11
16
|
import { createRenderTexture } from '@flighthq/texture/contract';
|
|
12
|
-
import type {
|
|
13
|
-
ColorScaleBias,
|
|
14
|
-
RenderProxy2D,
|
|
15
|
-
Scale9Sprite,
|
|
16
|
-
Texture2D,
|
|
17
|
-
WgpuTextureEntry,
|
|
18
|
-
} from '@flighthq/types/contract';
|
|
19
|
-
import { EntityRuntimeKey, RegistryEntryState, Scale9SpriteKind } from '@flighthq/types/contract';
|
|
17
|
+
import type { Texture2D } from '@flighthq/texture/contract';
|
|
20
18
|
|
|
21
|
-
import {
|
|
22
|
-
import { registerWgpuColorAdjustmentMaterialFeature } from './wgpuColorAdjustmentMaterialFeature';
|
|
23
|
-
import { prepareWgpuQuadBatchWrite, QUAD_BATCH_INSTANCE_FLOATS } from './wgpuQuadBatchWriter';
|
|
24
|
-
import {
|
|
25
|
-
import { registerWgpuStandardMaterial,
|
|
19
|
+
import { wgpuScene2DRenderPreset } from './scene2DWgpuPipeline.ts';
|
|
20
|
+
import { registerWgpuColorAdjustmentMaterialFeature } from './wgpuColorAdjustmentMaterialFeature.ts';
|
|
21
|
+
import { prepareWgpuQuadBatchWrite, QUAD_BATCH_INSTANCE_FLOATS } from './wgpuQuadBatchWriter.ts';
|
|
22
|
+
import { wgpuScale9SpriteRenderer, drawWgpuScale9Sprite } from './wgpuScale9Sprite.ts';
|
|
23
|
+
import { registerWgpuStandardMaterial, standardWgpuQuadMaterialRenderer } from './wgpuStandardMaterial.ts';
|
|
26
24
|
|
|
27
25
|
beforeAll(() => installWgpuMock());
|
|
28
26
|
|
|
29
|
-
describe('defaultWgpuScale9SpriteRenderer', () => {
|
|
30
|
-
it('is registered separately under Scale9SpriteKind', () => {
|
|
31
|
-
expect(typeof defaultWgpuScale9SpriteRenderer.createData).toBe('function');
|
|
32
|
-
expect(typeof defaultWgpuScale9SpriteRenderer.isDirty).toBe('function');
|
|
33
|
-
expect(defaultWgpuScale9SpriteRenderer.submit).toBe(drawWgpuScale9Sprite);
|
|
34
|
-
expect(getWgpuPipelineRegistries(scene2dWgpuPipeline).renderers.entries.get(Scale9SpriteKind)).toEqual({
|
|
35
|
-
state: RegistryEntryState.Bound,
|
|
36
|
-
value: defaultWgpuScale9SpriteRenderer,
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
27
|
describe('drawWgpuScale9Sprite', () => {
|
|
42
28
|
it('emits nine independently positioned quad instances', async () => {
|
|
43
29
|
const state = await createWgpuRenderStateForTest();
|
|
44
|
-
|
|
30
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
45
31
|
registerWgpuRenderTextureResolver(state);
|
|
46
32
|
registerWgpuStandardMaterial(state);
|
|
47
33
|
const texture = createResolvedRenderTexture(state);
|
|
@@ -69,17 +55,17 @@ describe('drawWgpuScale9Sprite', () => {
|
|
|
69
55
|
expect(runtime.quadBatchWriterInstanceData[center + 9]).toBeCloseTo(0);
|
|
70
56
|
expect(runtime.quadBatchWriterInstanceData[center + 10]).toBeCloseTo(0);
|
|
71
57
|
expect(runtime.quadBatchWriterInstanceData[center + 11]).toBeCloseTo(10 / 60);
|
|
72
|
-
|
|
58
|
+
submitWgpuFrame(state);
|
|
73
59
|
});
|
|
74
60
|
|
|
75
61
|
it('indexes parallel instance streams from the post-flush writer count', async () => {
|
|
76
62
|
const state = await createWgpuRenderStateForTest();
|
|
77
|
-
|
|
63
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
78
64
|
registerWgpuRenderTextureResolver(state);
|
|
79
65
|
registerWgpuStandardMaterial(state);
|
|
80
66
|
registerWgpuColorAdjustmentMaterialFeature(state);
|
|
81
67
|
const runtime = getWgpuRenderStateRuntime(state);
|
|
82
|
-
prepareWgpuQuadBatchWrite(state, createWgpuTextureEntry(), null, null, null,
|
|
68
|
+
prepareWgpuQuadBatchWrite(state, createWgpuTextureEntry(), null, null, null, standardWgpuQuadMaterialRenderer, 1);
|
|
83
69
|
runtime.quadBatchWriterCount = 1;
|
|
84
70
|
const tint = createTint();
|
|
85
71
|
const renderProxy = createScale9RenderProxy(createResolvedRenderTexture(state));
|
|
@@ -90,13 +76,22 @@ describe('drawWgpuScale9Sprite', () => {
|
|
|
90
76
|
expect(runtime.quadBatchWriterCount).toBe(9);
|
|
91
77
|
expect(runtime.quadBatchWriterColorScaleBiasMode).toBe(1);
|
|
92
78
|
expect(runtime.quadBatchWriterUniformColorScaleBias).toBe(tint);
|
|
93
|
-
|
|
79
|
+
submitWgpuFrame(state);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('wgpuScale9SpriteRenderer', () => {
|
|
84
|
+
it('is registered separately under Scale9SpriteKind', () => {
|
|
85
|
+
expect(typeof wgpuScale9SpriteRenderer.createData).toBe('function');
|
|
86
|
+
expect(typeof wgpuScale9SpriteRenderer.isDirty).toBe('function');
|
|
87
|
+
expect(wgpuScale9SpriteRenderer.submit).toBe(drawWgpuScale9Sprite);
|
|
88
|
+
expect(wgpuScene2DRenderPreset.nodeRenderers.get(Scale9SpriteKind)).toEqual(wgpuScale9SpriteRenderer);
|
|
94
89
|
});
|
|
95
90
|
});
|
|
96
91
|
|
|
97
92
|
function createResolvedRenderTexture(state: Parameters<typeof renderIntoWgpuRenderTexture>[0]): Texture2D {
|
|
98
93
|
const texture = createRenderTexture({ height: 60, width: 90 });
|
|
99
|
-
renderIntoWgpuRenderTexture(state, texture, () => {});
|
|
94
|
+
renderIntoWgpuRenderTexture(state, texture, () => {}, { color: [0, 0, 0, 0], depth: 1.0, stencil: 0 });
|
|
100
95
|
return texture;
|
|
101
96
|
}
|
|
102
97
|
|
|
@@ -128,8 +123,8 @@ function createWgpuTextureEntry(): WgpuTextureEntry {
|
|
|
128
123
|
[EntityRuntimeKey]: undefined,
|
|
129
124
|
bindings: new Map(),
|
|
130
125
|
mipLevelCount: 1,
|
|
131
|
-
texture: {} as
|
|
132
|
-
view: {} as
|
|
126
|
+
texture: {} as WgpuTexture,
|
|
127
|
+
view: {} as WgpuTextureView,
|
|
133
128
|
};
|
|
134
129
|
}
|
|
135
130
|
|
package/src/wgpuShape.test.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createImageResource,
|
|
3
|
+
registerTestImageDimensionResolver,
|
|
4
|
+
unregisterTestImageDimensionResolver,
|
|
5
|
+
} from '@flighthq/image/contract';
|
|
6
|
+
import type { HostImageCapability } from '@flighthq/image/contract';
|
|
2
7
|
import * as flightNode from '@flighthq/node/contract';
|
|
3
|
-
import {
|
|
8
|
+
import { PathCommand } from '@flighthq/path/contract';
|
|
9
|
+
import { beginWgpuScreenRenderPassForTest, submitWgpuFrame } from '@flighthq/render-wgpu/contract';
|
|
4
10
|
import { getWgpuRenderStateRuntime } from '@flighthq/render-wgpu/contract';
|
|
5
11
|
import { createWgpuRenderStateForTest, installWgpuMock } from '@flighthq/render-wgpu/contract';
|
|
12
|
+
import type { WgpuRenderPassEncoder } from '@flighthq/render-wgpu/contract';
|
|
13
|
+
import { BatchFormat } from '@flighthq/render/contract';
|
|
14
|
+
import type { RenderProxy2D } from '@flighthq/render/contract';
|
|
6
15
|
import {
|
|
7
16
|
appendShapeBeginFill,
|
|
8
17
|
appendShapeEndFill,
|
|
@@ -13,13 +22,22 @@ import {
|
|
|
13
22
|
appendShapeRectangle,
|
|
14
23
|
createShape,
|
|
15
24
|
} from '@flighthq/shape/contract';
|
|
16
|
-
import type {
|
|
17
|
-
|
|
25
|
+
import type { CanvasSurface, HostCanvasCapability } from '@flighthq/surface/contract';
|
|
26
|
+
|
|
27
|
+
import { enableWgpuStrokePathTessellation } from './enableWgpuStrokePathTessellation.ts';
|
|
28
|
+
import { wgpuMorphShapeRenderer, wgpuShapeRenderer, drawWgpuShape } from './wgpuShape.ts';
|
|
29
|
+
import { registerWgpuShapeRasterizer } from './wgpuShapeRasterizer.ts';
|
|
30
|
+
import { registerWgpuStandardMaterial } from './wgpuStandardMaterial.ts';
|
|
31
|
+
|
|
32
|
+
// A test that wraps a host handle supplies the host: the resource measures through the registered
|
|
33
|
+
// resolver, and clearing after each test keeps this file from covering for another's missing one.
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
registerTestImageDimensionResolver();
|
|
36
|
+
});
|
|
18
37
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
import { registerWgpuStandardMaterial } from './wgpuStandardMaterial';
|
|
38
|
+
afterEach(() => {
|
|
39
|
+
unregisterTestImageDimensionResolver();
|
|
40
|
+
});
|
|
23
41
|
|
|
24
42
|
const noopRasterizer = (): void => {};
|
|
25
43
|
|
|
@@ -43,40 +61,57 @@ afterEach(() => {
|
|
|
43
61
|
vi.restoreAllMocks();
|
|
44
62
|
});
|
|
45
63
|
|
|
46
|
-
function
|
|
64
|
+
function createTestSurface(width: number, height: number): CanvasSurface {
|
|
65
|
+
const canvas = document.createElement('canvas');
|
|
66
|
+
canvas.width = width;
|
|
67
|
+
canvas.height = height;
|
|
68
|
+
const context = canvas.getContext('2d')!;
|
|
69
|
+
return {
|
|
70
|
+
get width() {
|
|
71
|
+
return canvas.width;
|
|
72
|
+
},
|
|
73
|
+
set width(value: number) {
|
|
74
|
+
canvas.width = value;
|
|
75
|
+
},
|
|
76
|
+
get height() {
|
|
77
|
+
return canvas.height;
|
|
78
|
+
},
|
|
79
|
+
set height(value: number) {
|
|
80
|
+
canvas.height = value;
|
|
81
|
+
},
|
|
82
|
+
context,
|
|
83
|
+
} as unknown as CanvasSurface;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function createTestCanvasHost(): HostCanvasCapability {
|
|
87
|
+
return {
|
|
88
|
+
acquire: () => null,
|
|
89
|
+
create: () => null,
|
|
90
|
+
createSurface: createTestSurface,
|
|
91
|
+
destroySurface() {},
|
|
92
|
+
release() {},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function createTestImageHost(): HostImageCapability {
|
|
47
97
|
return {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const canvas = document.createElement('canvas');
|
|
51
|
-
canvas.width = width;
|
|
52
|
-
canvas.height = height;
|
|
53
|
-
const context = canvas.getContext('2d')!;
|
|
54
|
-
return {
|
|
55
|
-
[EntityRuntimeKey]: undefined,
|
|
56
|
-
get width() {
|
|
57
|
-
return canvas.width;
|
|
58
|
-
},
|
|
59
|
-
set width(value: number) {
|
|
60
|
-
canvas.width = value;
|
|
61
|
-
},
|
|
62
|
-
get height() {
|
|
63
|
-
return canvas.height;
|
|
64
|
-
},
|
|
65
|
-
set height(value: number) {
|
|
66
|
-
canvas.height = value;
|
|
67
|
-
},
|
|
68
|
-
context,
|
|
69
|
-
image: createImageResource(canvas),
|
|
70
|
-
};
|
|
98
|
+
createImageFromSurface(surface) {
|
|
99
|
+
return createImageResource((surface as unknown as { context: CanvasRenderingContext2D }).context.canvas);
|
|
71
100
|
},
|
|
72
|
-
|
|
101
|
+
loadImageFromUrl: () => Promise.reject(new Error('not implemented')),
|
|
73
102
|
};
|
|
74
103
|
}
|
|
75
104
|
|
|
105
|
+
function setTestHosts(state: { canvasHost: unknown; imageHost: unknown }): void {
|
|
106
|
+
state.canvasHost = createTestCanvasHost();
|
|
107
|
+
state.imageHost = createTestImageHost();
|
|
108
|
+
}
|
|
109
|
+
|
|
76
110
|
// Mirrors createWgpuShapeData: the rasterization surface is absent until a shape actually needs one,
|
|
77
111
|
// so a scene drawn entirely through the mesh path carries no canvases.
|
|
78
112
|
function makeShapeData() {
|
|
79
113
|
return {
|
|
114
|
+
image: null,
|
|
80
115
|
surface: null,
|
|
81
116
|
lastContentId: -1,
|
|
82
117
|
lastPixelRatio: 0,
|
|
@@ -109,7 +144,7 @@ function makeShapeProxy(data: Record<string, unknown> = {}, rendererData: unknow
|
|
|
109
144
|
} as unknown as RenderProxy2D;
|
|
110
145
|
}
|
|
111
146
|
|
|
112
|
-
function makeMeshPassSpy():
|
|
147
|
+
function makeMeshPassSpy(): WgpuRenderPassEncoder {
|
|
113
148
|
return {
|
|
114
149
|
setPipeline: vi.fn(),
|
|
115
150
|
setBindGroup: vi.fn(),
|
|
@@ -119,30 +154,15 @@ function makeMeshPassSpy(): GPURenderPassEncoder {
|
|
|
119
154
|
draw: vi.fn(),
|
|
120
155
|
drawIndexed: vi.fn(),
|
|
121
156
|
end: vi.fn(),
|
|
122
|
-
} as unknown as
|
|
157
|
+
} as unknown as WgpuRenderPassEncoder;
|
|
123
158
|
}
|
|
124
159
|
|
|
125
|
-
describe('defaultWgpuShapeRenderer', () => {
|
|
126
|
-
it('provides the MorphShape renderer alias', () => {
|
|
127
|
-
expect(defaultWgpuMorphShapeRenderer).toBe(defaultWgpuShapeRenderer);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('declares BatchFormat.Quad', () => {
|
|
131
|
-
expect(defaultWgpuShapeRenderer.format).toBe(BatchFormat.Quad);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('has createData and submit functions', () => {
|
|
135
|
-
expect(typeof defaultWgpuShapeRenderer.createData).toBe('function');
|
|
136
|
-
expect(typeof defaultWgpuShapeRenderer.submit).toBe('function');
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
|
|
140
160
|
describe('drawWgpuShape', () => {
|
|
141
161
|
it('draws a solid fill and open solid stroke as GPU meshes in one shape', async () => {
|
|
142
162
|
const state = await createWgpuRenderStateForTest();
|
|
143
|
-
state
|
|
163
|
+
setTestHosts(state);
|
|
144
164
|
registerWgpuShapeRasterizer(state, noopRasterizer);
|
|
145
|
-
|
|
165
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
146
166
|
getWgpuRenderStateRuntime(state).renderPass = makeMeshPassSpy();
|
|
147
167
|
const shape = createShape();
|
|
148
168
|
appendShapeBeginFill(shape, 0x00cc00ff);
|
|
@@ -151,7 +171,7 @@ describe('drawWgpuShape', () => {
|
|
|
151
171
|
appendShapeLineStyle(shape, 4, 0xff0000ff);
|
|
152
172
|
appendShapeMoveTo(shape, 8, 4);
|
|
153
173
|
appendShapeLineTo(shape, 40, 4);
|
|
154
|
-
const rendererData =
|
|
174
|
+
const rendererData = wgpuShapeRenderer.createData!(state, shape)!;
|
|
155
175
|
|
|
156
176
|
drawWgpuShape(state, makeShapeProxy({ commands: shape.data.commands, version: 1 }, rendererData));
|
|
157
177
|
|
|
@@ -160,20 +180,20 @@ describe('drawWgpuShape', () => {
|
|
|
160
180
|
};
|
|
161
181
|
expect(pass.drawIndexed).toHaveBeenCalledTimes(2);
|
|
162
182
|
expect(getWgpuRenderStateRuntime(state).quadBatchWriterCount).toBe(0);
|
|
163
|
-
|
|
183
|
+
submitWgpuFrame(state);
|
|
164
184
|
});
|
|
165
185
|
|
|
166
186
|
it('draws a closed solid stroke ring as one GPU mesh', async () => {
|
|
167
187
|
const state = await createWgpuRenderStateForTest();
|
|
168
|
-
state
|
|
188
|
+
setTestHosts(state);
|
|
169
189
|
registerWgpuShapeRasterizer(state, noopRasterizer);
|
|
170
190
|
enableWgpuStrokePathTessellation(state);
|
|
171
|
-
|
|
191
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
172
192
|
getWgpuRenderStateRuntime(state).renderPass = makeMeshPassSpy();
|
|
173
193
|
const shape = createShape();
|
|
174
194
|
appendShapeLineStyle(shape, 8, 0xff0000ff);
|
|
175
195
|
appendShapeRectangle(shape, 8, 8, 32, 24);
|
|
176
|
-
const rendererData =
|
|
196
|
+
const rendererData = wgpuShapeRenderer.createData!(state, shape)!;
|
|
177
197
|
|
|
178
198
|
drawWgpuShape(state, makeShapeProxy({ commands: shape.data.commands, version: 1 }, rendererData));
|
|
179
199
|
|
|
@@ -182,35 +202,35 @@ describe('drawWgpuShape', () => {
|
|
|
182
202
|
};
|
|
183
203
|
expect(pass.drawIndexed).toHaveBeenCalledTimes(1);
|
|
184
204
|
expect(getWgpuRenderStateRuntime(state).quadBatchWriterCount).toBe(0);
|
|
185
|
-
|
|
205
|
+
submitWgpuFrame(state);
|
|
186
206
|
});
|
|
187
207
|
|
|
188
208
|
it('keeps a closed stroke on the raster lane until stroke-path tessellation is enabled', async () => {
|
|
189
209
|
const state = await createWgpuRenderStateForTest();
|
|
190
|
-
state
|
|
210
|
+
setTestHosts(state);
|
|
191
211
|
registerWgpuShapeRasterizer(state, noopRasterizer);
|
|
192
|
-
|
|
212
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
193
213
|
registerWgpuStandardMaterial(state);
|
|
194
214
|
const pass = makeMeshPassSpy();
|
|
195
215
|
getWgpuRenderStateRuntime(state).renderPass = pass;
|
|
196
216
|
const shape = createShape();
|
|
197
217
|
appendShapeLineStyle(shape, 8, 0xff0000ff);
|
|
198
218
|
appendShapeRectangle(shape, 8, 8, 32, 24);
|
|
199
|
-
const rendererData =
|
|
219
|
+
const rendererData = wgpuShapeRenderer.createData!(state, shape)!;
|
|
200
220
|
|
|
201
221
|
drawWgpuShape(state, makeShapeProxy({ commands: shape.data.commands, version: 1 }, rendererData));
|
|
202
222
|
|
|
203
223
|
expect(pass.drawIndexed).not.toHaveBeenCalled();
|
|
204
224
|
expect(getWgpuRenderStateRuntime(state).quadBatchWriterCount).toBe(1);
|
|
205
|
-
|
|
225
|
+
submitWgpuFrame(state);
|
|
206
226
|
});
|
|
207
227
|
|
|
208
228
|
it('falls back to the raster quad for a self-intersecting stroke centerline', async () => {
|
|
209
229
|
const state = await createWgpuRenderStateForTest();
|
|
210
|
-
state
|
|
230
|
+
setTestHosts(state);
|
|
211
231
|
registerWgpuShapeRasterizer(state, noopRasterizer);
|
|
212
232
|
enableWgpuStrokePathTessellation(state);
|
|
213
|
-
|
|
233
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
214
234
|
registerWgpuStandardMaterial(state);
|
|
215
235
|
const pass = makeMeshPassSpy();
|
|
216
236
|
getWgpuRenderStateRuntime(state).renderPass = pass;
|
|
@@ -222,7 +242,7 @@ describe('drawWgpuShape', () => {
|
|
|
222
242
|
[8, 8, 40, 40, 8, 40, 40, 8],
|
|
223
243
|
'nonZero',
|
|
224
244
|
);
|
|
225
|
-
const rendererData =
|
|
245
|
+
const rendererData = wgpuShapeRenderer.createData!(state, shape)!;
|
|
226
246
|
const proxy = makeShapeProxy({ commands: shape.data.commands, version: 1 }, rendererData);
|
|
227
247
|
|
|
228
248
|
drawWgpuShape(state, proxy);
|
|
@@ -241,46 +261,61 @@ describe('drawWgpuShape', () => {
|
|
|
241
261
|
expect(getWgpuRenderStateRuntime(state).quadBatchWriterCount).toBe(2);
|
|
242
262
|
expect(setWidth).not.toHaveBeenCalled();
|
|
243
263
|
expect(setHeight).not.toHaveBeenCalled();
|
|
244
|
-
|
|
264
|
+
submitWgpuFrame(state);
|
|
245
265
|
});
|
|
246
266
|
|
|
247
267
|
it('returns early without writing to batch when commands are empty', async () => {
|
|
248
268
|
const state = await createWgpuRenderStateForTest();
|
|
249
|
-
state
|
|
269
|
+
setTestHosts(state);
|
|
250
270
|
registerWgpuShapeRasterizer(state, noopRasterizer);
|
|
251
|
-
|
|
271
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
252
272
|
registerWgpuStandardMaterial(state);
|
|
253
273
|
drawWgpuShape(state, makeShapeProxy({ commands: [] }, makeShapeData()));
|
|
254
274
|
expect(getWgpuRenderStateRuntime(state).quadBatchWriterCount).toBe(0);
|
|
255
|
-
|
|
275
|
+
submitWgpuFrame(state);
|
|
256
276
|
});
|
|
257
277
|
|
|
258
278
|
it('returns early without writing to batch when rendererData is null', async () => {
|
|
259
279
|
const state = await createWgpuRenderStateForTest();
|
|
260
|
-
state
|
|
280
|
+
setTestHosts(state);
|
|
261
281
|
registerWgpuShapeRasterizer(state, noopRasterizer);
|
|
262
|
-
|
|
282
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
263
283
|
registerWgpuStandardMaterial(state);
|
|
264
284
|
drawWgpuShape(state, makeShapeProxy({ commands: [{}] }, null));
|
|
265
285
|
expect(getWgpuRenderStateRuntime(state).quadBatchWriterCount).toBe(0);
|
|
266
|
-
|
|
286
|
+
submitWgpuFrame(state);
|
|
267
287
|
});
|
|
268
288
|
|
|
269
289
|
it('does not throw when renderPass is null', async () => {
|
|
270
290
|
const state = await createWgpuRenderStateForTest();
|
|
271
|
-
state
|
|
291
|
+
setTestHosts(state);
|
|
272
292
|
registerWgpuShapeRasterizer(state, noopRasterizer);
|
|
273
293
|
expect(() => drawWgpuShape(state, makeShapeProxy({ commands: [{}] }, makeShapeData()))).not.toThrow();
|
|
274
294
|
});
|
|
275
295
|
|
|
276
296
|
it('writes one instance to the quad-batch writer when shape has valid commands and bounds', async () => {
|
|
277
297
|
const state = await createWgpuRenderStateForTest();
|
|
278
|
-
state
|
|
298
|
+
setTestHosts(state);
|
|
279
299
|
registerWgpuShapeRasterizer(state, noopRasterizer);
|
|
280
|
-
|
|
300
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
281
301
|
registerWgpuStandardMaterial(state);
|
|
282
302
|
drawWgpuShape(state, makeShapeProxy({ commands: [{}], version: 1 }, makeShapeData()));
|
|
283
303
|
expect(getWgpuRenderStateRuntime(state).quadBatchWriterCount).toBe(1);
|
|
284
|
-
|
|
304
|
+
submitWgpuFrame(state);
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
describe('wgpuShapeRenderer', () => {
|
|
309
|
+
it('provides the MorphShape renderer alias', () => {
|
|
310
|
+
expect(wgpuMorphShapeRenderer).toBe(wgpuShapeRenderer);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it('declares BatchFormat.Quad', () => {
|
|
314
|
+
expect(wgpuShapeRenderer.format).toBe(BatchFormat.Quad);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it('has createData and submit functions', () => {
|
|
318
|
+
expect(typeof wgpuShapeRenderer.createData).toBe('function');
|
|
319
|
+
expect(typeof wgpuShapeRenderer.submit).toBe('function');
|
|
285
320
|
});
|
|
286
321
|
});
|