@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,16 +1,31 @@
|
|
|
1
|
-
import { allocateEntity
|
|
2
|
-
import {
|
|
1
|
+
import { allocateEntity } from '@flighthq/entity/contract';
|
|
2
|
+
import {
|
|
3
|
+
createImageResource,
|
|
4
|
+
registerTestImageDimensionResolver,
|
|
5
|
+
unregisterTestImageDimensionResolver,
|
|
6
|
+
} from '@flighthq/image/contract';
|
|
7
|
+
import type { HostImageCapability } from '@flighthq/image/contract';
|
|
3
8
|
import { getWgpuRenderStateRuntime } from '@flighthq/render-wgpu/contract';
|
|
4
9
|
import { createWgpuRenderStateForTest, installWgpuMock } from '@flighthq/render-wgpu/contract';
|
|
5
|
-
import type {
|
|
6
|
-
import { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
10
|
+
import type { CanvasSurface, HostCanvasCapability } from '@flighthq/surface/contract';
|
|
7
11
|
|
|
12
|
+
import type { WgpuShapeRendererData } from './contract.scene2d-wgpu-types.ts';
|
|
8
13
|
import {
|
|
9
14
|
acquireWgpuShapeRasterSurface,
|
|
10
15
|
createWgpuShapeData,
|
|
11
16
|
destroyWgpuShapeData,
|
|
12
17
|
getWgpuShapeData,
|
|
13
|
-
} from './wgpuShapeData';
|
|
18
|
+
} from './wgpuShapeData.ts';
|
|
19
|
+
|
|
20
|
+
// A test that wraps a host handle supplies the host: the resource measures through the registered
|
|
21
|
+
// resolver, and clearing after each test keeps this file from covering for another's missing one.
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
registerTestImageDimensionResolver();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
unregisterTestImageDimensionResolver();
|
|
28
|
+
});
|
|
14
29
|
|
|
15
30
|
const destroySurface = vi.fn();
|
|
16
31
|
|
|
@@ -22,38 +37,55 @@ beforeEach(() => {
|
|
|
22
37
|
destroySurface.mockReset();
|
|
23
38
|
});
|
|
24
39
|
|
|
25
|
-
function
|
|
40
|
+
function createTestSurface(width: number, height: number): CanvasSurface {
|
|
41
|
+
const canvas = document.createElement('canvas');
|
|
42
|
+
canvas.width = width;
|
|
43
|
+
canvas.height = height;
|
|
44
|
+
const context = canvas.getContext('2d')!;
|
|
45
|
+
return {
|
|
46
|
+
get width() {
|
|
47
|
+
return canvas.width;
|
|
48
|
+
},
|
|
49
|
+
set width(value: number) {
|
|
50
|
+
canvas.width = value;
|
|
51
|
+
},
|
|
52
|
+
get height() {
|
|
53
|
+
return canvas.height;
|
|
54
|
+
},
|
|
55
|
+
set height(value: number) {
|
|
56
|
+
canvas.height = value;
|
|
57
|
+
},
|
|
58
|
+
context,
|
|
59
|
+
} as unknown as CanvasSurface;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function createTestCanvasHost(): HostCanvasCapability {
|
|
63
|
+
return {
|
|
64
|
+
acquire: () => null,
|
|
65
|
+
create: () => null,
|
|
66
|
+
createSurface: createTestSurface,
|
|
67
|
+
destroySurface,
|
|
68
|
+
release() {},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function createTestImageHost(): HostImageCapability {
|
|
26
73
|
return {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const canvas = document.createElement('canvas');
|
|
30
|
-
canvas.width = width;
|
|
31
|
-
canvas.height = height;
|
|
32
|
-
const context = canvas.getContext('2d')!;
|
|
33
|
-
return {
|
|
34
|
-
[EntityRuntimeKey]: undefined,
|
|
35
|
-
get width() {
|
|
36
|
-
return canvas.width;
|
|
37
|
-
},
|
|
38
|
-
set width(value: number) {
|
|
39
|
-
canvas.width = value;
|
|
40
|
-
},
|
|
41
|
-
get height() {
|
|
42
|
-
return canvas.height;
|
|
43
|
-
},
|
|
44
|
-
set height(value: number) {
|
|
45
|
-
canvas.height = value;
|
|
46
|
-
},
|
|
47
|
-
context,
|
|
48
|
-
image: createImageResource(canvas),
|
|
49
|
-
};
|
|
74
|
+
createImageFromSurface(surface) {
|
|
75
|
+
return createImageResource((surface as unknown as { context: CanvasRenderingContext2D }).context.canvas);
|
|
50
76
|
},
|
|
51
|
-
|
|
77
|
+
loadImageFromUrl: () => Promise.reject(new Error('not implemented')),
|
|
52
78
|
};
|
|
53
79
|
}
|
|
54
80
|
|
|
81
|
+
function setTestHosts(state: { canvasHost: unknown; imageHost: unknown }): void {
|
|
82
|
+
state.canvasHost = createTestCanvasHost();
|
|
83
|
+
state.imageHost = createTestImageHost();
|
|
84
|
+
}
|
|
85
|
+
|
|
55
86
|
function emptyData(): WgpuShapeRendererData {
|
|
56
87
|
const out = allocateEntity<WgpuShapeRendererData>();
|
|
88
|
+
out.image = null;
|
|
57
89
|
out.surface = null;
|
|
58
90
|
out.lastContentId = -1;
|
|
59
91
|
out.lastPixelRatio = 0;
|
|
@@ -71,32 +103,40 @@ function emptyData(): WgpuShapeRendererData {
|
|
|
71
103
|
colorScaleBiasUniformBuffers: [],
|
|
72
104
|
colorScaleBiasBindGroups: [],
|
|
73
105
|
};
|
|
74
|
-
return
|
|
106
|
+
return out;
|
|
75
107
|
}
|
|
76
108
|
|
|
77
109
|
describe('acquireWgpuShapeRasterSurface', () => {
|
|
78
110
|
it('allocates once and returns the same surface thereafter', () => {
|
|
79
|
-
const
|
|
111
|
+
const canvasHost = createTestCanvasHost();
|
|
112
|
+
const imageHost = createTestImageHost();
|
|
80
113
|
const data = emptyData();
|
|
81
|
-
const first = acquireWgpuShapeRasterSurface(
|
|
114
|
+
const first = acquireWgpuShapeRasterSurface(canvasHost, imageHost, data);
|
|
82
115
|
expect(data.surface).toBe(first);
|
|
83
|
-
expect(acquireWgpuShapeRasterSurface(
|
|
116
|
+
expect(acquireWgpuShapeRasterSurface(canvasHost, imageHost, data)).toBe(first);
|
|
84
117
|
});
|
|
85
118
|
|
|
86
119
|
it('wraps the canvas as an Image so the quad batch treats it like any other texture source', () => {
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
120
|
+
const canvasHost = createTestCanvasHost();
|
|
121
|
+
const imageHost = createTestImageHost();
|
|
122
|
+
const data = emptyData();
|
|
123
|
+
acquireWgpuShapeRasterSurface(canvasHost, imageHost, data);
|
|
124
|
+
const surface = data.surface!;
|
|
125
|
+
const image = data.image!;
|
|
126
|
+
expect(image.source).toBe((surface as unknown as { context: CanvasRenderingContext2D }).context.canvas);
|
|
90
127
|
});
|
|
91
128
|
|
|
92
129
|
it('preserves expected absence without caching it when the provider refuses', () => {
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
130
|
+
const canvasHost: HostCanvasCapability = {
|
|
131
|
+
acquire: () => null,
|
|
132
|
+
create: () => null,
|
|
133
|
+
createSurface: () => null,
|
|
134
|
+
destroySurface,
|
|
135
|
+
release() {},
|
|
97
136
|
};
|
|
137
|
+
const imageHost = createTestImageHost();
|
|
98
138
|
const data = emptyData();
|
|
99
|
-
expect(acquireWgpuShapeRasterSurface(
|
|
139
|
+
expect(acquireWgpuShapeRasterSurface(canvasHost, imageHost, data)).toBeNull();
|
|
100
140
|
expect(data.surface).toBeNull();
|
|
101
141
|
});
|
|
102
142
|
});
|
|
@@ -104,7 +144,7 @@ describe('acquireWgpuShapeRasterSurface', () => {
|
|
|
104
144
|
describe('createWgpuShapeData', () => {
|
|
105
145
|
it('allocates no canvas up front, so a mesh-only scene carries none', async () => {
|
|
106
146
|
const state = await createWgpuRenderStateForTest();
|
|
107
|
-
state
|
|
147
|
+
setTestHosts(state);
|
|
108
148
|
const data = getWgpuShapeData(createWgpuShapeData(state, {} as never))!;
|
|
109
149
|
expect(data.surface).toBeNull();
|
|
110
150
|
expect(data.meshes).toBeNull();
|
|
@@ -115,7 +155,7 @@ describe('createWgpuShapeData', () => {
|
|
|
115
155
|
describe('destroyWgpuShapeData', () => {
|
|
116
156
|
it('does nothing when the shape only ever tessellated, since there is no surface to free', async () => {
|
|
117
157
|
const state = await createWgpuRenderStateForTest();
|
|
118
|
-
state
|
|
158
|
+
setTestHosts(state);
|
|
119
159
|
const data = createWgpuShapeData(state, {} as never);
|
|
120
160
|
expect(() => destroyWgpuShapeData(state, data)).not.toThrow();
|
|
121
161
|
expect(destroySurface).not.toHaveBeenCalled();
|
|
@@ -123,18 +163,20 @@ describe('destroyWgpuShapeData', () => {
|
|
|
123
163
|
|
|
124
164
|
it('destroys the cached GPU texture before the raster surface, then frees the mesh buffers', async () => {
|
|
125
165
|
const state = await createWgpuRenderStateForTest();
|
|
126
|
-
state
|
|
166
|
+
setTestHosts(state);
|
|
127
167
|
const data = createWgpuShapeData(state, {} as never);
|
|
128
168
|
const shapeData = getWgpuShapeData(data)!;
|
|
129
|
-
|
|
169
|
+
acquireWgpuShapeRasterSurface(state.canvasHost!, state.imageHost!, shapeData);
|
|
170
|
+
const surface = shapeData.surface!;
|
|
171
|
+
const image = shapeData.image!;
|
|
130
172
|
const cache = getWgpuRenderStateRuntime(state).context.textureSourcePremultipliedTextureCache;
|
|
131
173
|
const order: string[] = [];
|
|
132
174
|
const destroy = vi.fn(() => order.push('texture'));
|
|
133
|
-
cache.set(
|
|
175
|
+
cache.set(image, {
|
|
134
176
|
texture: { destroy },
|
|
135
177
|
} as never);
|
|
136
|
-
destroySurface.mockImplementation((
|
|
137
|
-
expect(cache.has(
|
|
178
|
+
destroySurface.mockImplementation(() => {
|
|
179
|
+
expect(cache.has(image)).toBe(false);
|
|
138
180
|
order.push('surface');
|
|
139
181
|
});
|
|
140
182
|
const bufferDestroy = vi.fn(() => order.push('buffer'));
|
|
@@ -146,7 +188,7 @@ describe('destroyWgpuShapeData', () => {
|
|
|
146
188
|
expect(destroy).toHaveBeenCalledOnce();
|
|
147
189
|
expect(destroySurface).toHaveBeenCalledWith(surface);
|
|
148
190
|
expect(bufferDestroy).toHaveBeenCalledTimes(2);
|
|
149
|
-
expect(cache.has(
|
|
191
|
+
expect(cache.has(image)).toBe(false);
|
|
150
192
|
expect(order).toEqual(['texture', 'surface', 'buffer', 'buffer']);
|
|
151
193
|
expect(shapeData.meshBuffers.vertexBuffers).toHaveLength(0);
|
|
152
194
|
expect(shapeData.meshBuffers.colorScaleBiasUniformBuffers).toHaveLength(0);
|
|
@@ -154,10 +196,11 @@ describe('destroyWgpuShapeData', () => {
|
|
|
154
196
|
|
|
155
197
|
it('destroys a raster surface even when it never acquired a GPU cache entry', async () => {
|
|
156
198
|
const state = await createWgpuRenderStateForTest();
|
|
157
|
-
state
|
|
199
|
+
setTestHosts(state);
|
|
158
200
|
const data = createWgpuShapeData(state, {} as never);
|
|
159
201
|
const shapeData = getWgpuShapeData(data)!;
|
|
160
|
-
|
|
202
|
+
acquireWgpuShapeRasterSurface(state.canvasHost!, state.imageHost!, shapeData);
|
|
203
|
+
const surface = shapeData.surface!;
|
|
161
204
|
|
|
162
205
|
destroyWgpuShapeData(state, data);
|
|
163
206
|
|
|
@@ -168,7 +211,7 @@ describe('destroyWgpuShapeData', () => {
|
|
|
168
211
|
describe('getWgpuShapeData', () => {
|
|
169
212
|
it('reads the shape data back out of the opaque RendererData slot', async () => {
|
|
170
213
|
const state = await createWgpuRenderStateForTest();
|
|
171
|
-
state
|
|
214
|
+
setTestHosts(state);
|
|
172
215
|
const data = createWgpuShapeData(state, {} as never);
|
|
173
216
|
expect(getWgpuShapeData(data)?.meshVersion).toBe(-1);
|
|
174
217
|
});
|
|
@@ -1,18 +1,29 @@
|
|
|
1
|
+
import type { ColorScaleBias } from '@flighthq/adjustments/contract';
|
|
1
2
|
import { createMatrix } from '@flighthq/geometry/contract';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
3
|
+
import { BlendMode } from '@flighthq/materials/contract';
|
|
4
|
+
import {
|
|
5
|
+
beginWgpuScreenRenderPassForTest,
|
|
6
|
+
createWgpuRenderStateForTest,
|
|
7
|
+
getWgpuRenderStateRuntime,
|
|
8
|
+
installWgpuMock,
|
|
9
|
+
} from '@flighthq/render-wgpu/contract';
|
|
4
10
|
import type {
|
|
5
|
-
|
|
6
|
-
|
|
11
|
+
WgpuBindGroup,
|
|
12
|
+
WgpuBindGroupLayout,
|
|
13
|
+
WgpuBuffer,
|
|
14
|
+
WgpuQueue,
|
|
15
|
+
WgpuRenderPassEncoder,
|
|
16
|
+
WgpuRenderPipeline,
|
|
17
|
+
WgpuRenderPipelineDescriptor,
|
|
7
18
|
WgpuRenderState,
|
|
8
19
|
WgpuShapeMeshBuffers,
|
|
9
20
|
WgpuShapeMeshPipeline,
|
|
10
|
-
} from '@flighthq/
|
|
11
|
-
import type {
|
|
12
|
-
import { BlendMode } from '@flighthq/types/contract';
|
|
21
|
+
} from '@flighthq/render-wgpu/contract';
|
|
22
|
+
import type { RenderProxy2D } from '@flighthq/render/contract';
|
|
13
23
|
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
24
|
+
import type { WgpuShapeMesh } from './contract.scene2d-wgpu-types.ts';
|
|
25
|
+
import { registerWgpuColorAdjustmentMaterialFeature } from './wgpuColorAdjustmentMaterialFeature.ts';
|
|
26
|
+
import { drawWgpuShapeMeshBatch, drawWgpuShapeMeshes } from './wgpuShapeMesh.ts';
|
|
16
27
|
|
|
17
28
|
beforeAll(() => {
|
|
18
29
|
installWgpuMock();
|
|
@@ -38,7 +49,7 @@ function makeBuffers(): WgpuShapeMeshBuffers {
|
|
|
38
49
|
};
|
|
39
50
|
}
|
|
40
51
|
|
|
41
|
-
function makePassSpy():
|
|
52
|
+
function makePassSpy(): WgpuRenderPassEncoder {
|
|
42
53
|
return {
|
|
43
54
|
setPipeline: vi.fn(),
|
|
44
55
|
setBindGroup: vi.fn(),
|
|
@@ -47,7 +58,7 @@ function makePassSpy(): GPURenderPassEncoder {
|
|
|
47
58
|
setStencilReference: vi.fn(),
|
|
48
59
|
draw: vi.fn(),
|
|
49
60
|
drawIndexed: vi.fn(),
|
|
50
|
-
} as unknown as
|
|
61
|
+
} as unknown as WgpuRenderPassEncoder;
|
|
51
62
|
}
|
|
52
63
|
|
|
53
64
|
function makeProxy(overrides?: Partial<RenderProxy2D>): RenderProxy2D {
|
|
@@ -83,8 +94,11 @@ function ct(
|
|
|
83
94
|
} as ColorScaleBias;
|
|
84
95
|
}
|
|
85
96
|
|
|
97
|
+
// A real screen pass, with its encoder swapped for a spy: the draw path reads the pass viewport for its
|
|
98
|
+
// projection, so a state with only a fake encoder attached has no coordinate space to draw into.
|
|
86
99
|
async function makeState(): Promise<WgpuRenderState> {
|
|
87
100
|
const state = await createWgpuRenderStateForTest();
|
|
101
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
88
102
|
getWgpuRenderStateRuntime(state).renderPass = makePassSpy();
|
|
89
103
|
return state;
|
|
90
104
|
}
|
|
@@ -93,20 +107,20 @@ describe('drawWgpuShapeMeshBatch', () => {
|
|
|
93
107
|
it('writes only the shared matrix and color fields, preserving a feature-owned uniform tail', async () => {
|
|
94
108
|
const state = await makeState();
|
|
95
109
|
const buffers = makeBuffers();
|
|
96
|
-
const uniformBuffers:
|
|
97
|
-
const bindGroups:
|
|
110
|
+
const uniformBuffers: WgpuBuffer[] = [];
|
|
111
|
+
const bindGroups: WgpuBindGroup[] = [];
|
|
98
112
|
const uniformData = new Float32Array(24);
|
|
99
113
|
uniformData.set([0.25, 0.5, 0.75, 1, 0.1, 0.2, 0.3, 0.4], 16);
|
|
100
114
|
const pipelineEntry: WgpuShapeMeshPipeline = {
|
|
101
|
-
bindGroupLayout: {} as
|
|
102
|
-
pipeline: {} as
|
|
115
|
+
bindGroupLayout: {} as WgpuBindGroupLayout,
|
|
116
|
+
pipeline: {} as WgpuRenderPipeline,
|
|
103
117
|
};
|
|
104
118
|
let upload: Float32Array | undefined;
|
|
105
|
-
state.device.queue.writeBuffer = vi.fn((buffer:
|
|
119
|
+
state.device.queue.writeBuffer = vi.fn((buffer: WgpuBuffer, _offset: number, data: BufferSource) => {
|
|
106
120
|
if (buffer !== uniformBuffers[0]) return;
|
|
107
121
|
const view = ArrayBuffer.isView(data) ? data : new Uint8Array(data as ArrayBuffer);
|
|
108
122
|
upload = new Float32Array(view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength));
|
|
109
|
-
}) as unknown as
|
|
123
|
+
}) as unknown as WgpuQueue['writeBuffer'];
|
|
110
124
|
|
|
111
125
|
drawWgpuShapeMeshBatch(
|
|
112
126
|
state,
|
|
@@ -200,7 +214,7 @@ describe('drawWgpuShapeMeshes', () => {
|
|
|
200
214
|
|
|
201
215
|
const pipelines = [...getWgpuRenderStateRuntime(state).shapeMeshPipelines!.values()].map(
|
|
202
216
|
(entry) => entry.pipeline,
|
|
203
|
-
) as unknown as { __descriptor:
|
|
217
|
+
) as unknown as { __descriptor: WgpuRenderPipelineDescriptor }[];
|
|
204
218
|
expect(pipelines).toHaveLength(2);
|
|
205
219
|
const blends = pipelines.map((pipeline) => [...pipeline.__descriptor.fragment!.targets][0]!.blend!.color);
|
|
206
220
|
expect(blends).toContainEqual({ srcFactor: 'one', dstFactor: 'one-minus-src-alpha', operation: 'add' });
|
|
@@ -210,14 +224,14 @@ describe('drawWgpuShapeMeshes', () => {
|
|
|
210
224
|
it('writes premultiplied color (color * alpha) into the uniform buffer', async () => {
|
|
211
225
|
const state = await makeState();
|
|
212
226
|
const buffers = makeBuffers();
|
|
213
|
-
const writes = new Map<
|
|
214
|
-
state.device.queue.writeBuffer = vi.fn((buffer:
|
|
227
|
+
const writes = new Map<WgpuBuffer, Float32Array>();
|
|
228
|
+
state.device.queue.writeBuffer = vi.fn((buffer: WgpuBuffer, _offset: number, data: BufferSource) => {
|
|
215
229
|
const view = ArrayBuffer.isView(data) ? data : new Uint8Array(data as ArrayBuffer);
|
|
216
230
|
// Only the uniform write is inspected; record a copy keyed by its destination buffer.
|
|
217
231
|
if (view.byteLength % 4 === 0) {
|
|
218
232
|
writes.set(buffer, new Float32Array(view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength)));
|
|
219
233
|
}
|
|
220
|
-
}) as unknown as
|
|
234
|
+
}) as unknown as WgpuQueue['writeBuffer'];
|
|
221
235
|
|
|
222
236
|
drawWgpuShapeMeshes(state, makeProxy({ alpha: 0.5 }), [{ ...TRIANGLE, color: 0xffffffff }], buffers);
|
|
223
237
|
|
|
@@ -277,13 +291,13 @@ describe('drawWgpuShapeMeshes', () => {
|
|
|
277
291
|
const buffers = makeBuffers();
|
|
278
292
|
registerWgpuColorAdjustmentMaterialFeature(state);
|
|
279
293
|
const createShaderModule = vi.spyOn(state.device, 'createShaderModule');
|
|
280
|
-
const writes = new Map<
|
|
281
|
-
state.device.queue.writeBuffer = vi.fn((buffer:
|
|
294
|
+
const writes = new Map<WgpuBuffer, Float32Array>();
|
|
295
|
+
state.device.queue.writeBuffer = vi.fn((buffer: WgpuBuffer, _offset: number, data: BufferSource) => {
|
|
282
296
|
const view = ArrayBuffer.isView(data) ? data : new Uint8Array(data as ArrayBuffer);
|
|
283
297
|
if (view.byteLength % 4 === 0) {
|
|
284
298
|
writes.set(buffer, new Float32Array(view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength)));
|
|
285
299
|
}
|
|
286
|
-
}) as unknown as
|
|
300
|
+
}) as unknown as WgpuQueue['writeBuffer'];
|
|
287
301
|
|
|
288
302
|
drawWgpuShapeMeshes(
|
|
289
303
|
state,
|
|
@@ -311,7 +325,7 @@ describe('drawWgpuShapeMeshes', () => {
|
|
|
311
325
|
const buffers = makeBuffers();
|
|
312
326
|
registerWgpuColorAdjustmentMaterialFeature(state);
|
|
313
327
|
|
|
314
|
-
drawWgpuShapeMeshes(state, makeProxy({ colorMatrix: new
|
|
328
|
+
drawWgpuShapeMeshes(state, makeProxy({ colorMatrix: new Float32Array(20) }), [TRIANGLE], buffers);
|
|
315
329
|
|
|
316
330
|
expect(buffers.uniformBuffers).toHaveLength(1);
|
|
317
331
|
expect(buffers.colorScaleBiasUniformBuffers).toHaveLength(0);
|
|
@@ -3,10 +3,14 @@ import {
|
|
|
3
3
|
getWgpuRenderStateRuntime,
|
|
4
4
|
installWgpuMock,
|
|
5
5
|
} from '@flighthq/render-wgpu/contract';
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import {
|
|
7
|
+
createRenderState,
|
|
8
|
+
enableRenderRegistriesGuards,
|
|
9
|
+
explainRenderRegistriesMisses,
|
|
10
|
+
} from '@flighthq/render/contract';
|
|
11
|
+
import { RenderRegistries } from '@flighthq/render/contract';
|
|
8
12
|
|
|
9
|
-
import { getWgpuShapeRasterizer, registerWgpuShapeRasterizer } from './wgpuShapeRasterizer';
|
|
13
|
+
import { getWgpuShapeRasterizer, registerWgpuShapeRasterizer } from './wgpuShapeRasterizer.ts';
|
|
10
14
|
|
|
11
15
|
beforeAll(() => {
|
|
12
16
|
installWgpuMock();
|
|
@@ -28,8 +32,8 @@ describe('registerWgpuShapeRasterizer', () => {
|
|
|
28
32
|
registerWgpuShapeRasterizer(state, rasterizer);
|
|
29
33
|
|
|
30
34
|
expect(getWgpuShapeRasterizer(state)).toBe(rasterizer);
|
|
31
|
-
expect(getWgpuRenderStateRuntime(state).registries.shapeRasterizer).
|
|
32
|
-
expect(before
|
|
35
|
+
expect(getWgpuRenderStateRuntime(state).registries.shapeRasterizer).toBe(rasterizer);
|
|
36
|
+
expect(before).toBeNull();
|
|
33
37
|
});
|
|
34
38
|
|
|
35
39
|
it('removes one again, so a state can drop back to tessellation only', async () => {
|
|
@@ -40,7 +44,7 @@ describe('registerWgpuShapeRasterizer', () => {
|
|
|
40
44
|
registerWgpuShapeRasterizer(state, null);
|
|
41
45
|
|
|
42
46
|
expect(getWgpuShapeRasterizer(state)).toBeNull();
|
|
43
|
-
expect(getWgpuRenderStateRuntime(state).registries.shapeRasterizer).
|
|
44
|
-
expect(before
|
|
47
|
+
expect(getWgpuRenderStateRuntime(state).registries.shapeRasterizer).toBeNull();
|
|
48
|
+
expect(before).not.toBeNull();
|
|
45
49
|
});
|
|
46
50
|
});
|
package/src/wgpuSprite.test.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
|
+
beginWgpuScreenRenderPassForTest,
|
|
2
3
|
createWgpuRenderStateForTest,
|
|
3
4
|
getWgpuRenderStateRuntime,
|
|
4
5
|
installWgpuMock,
|
|
5
6
|
registerWgpuRenderTextureResolver,
|
|
6
7
|
renderIntoWgpuRenderTexture,
|
|
7
|
-
|
|
8
|
-
submitWgpuRenderPass,
|
|
8
|
+
submitWgpuFrame,
|
|
9
9
|
} from '@flighthq/render-wgpu/contract';
|
|
10
10
|
import { getOrCreateRenderProxy2D, prepareScene2DRender } from '@flighthq/render/contract';
|
|
11
11
|
import { createSprite } from '@flighthq/scene2d/contract';
|
|
12
12
|
import { createRenderTexture, setTextureUvFromPixelRect } from '@flighthq/texture/contract';
|
|
13
13
|
|
|
14
|
-
import { registerWgpuColorAdjustmentMaterialFeature } from './wgpuColorAdjustmentMaterialFeature';
|
|
15
|
-
import {
|
|
16
|
-
import { registerWgpuStandardMaterial } from './wgpuStandardMaterial';
|
|
14
|
+
import { registerWgpuColorAdjustmentMaterialFeature } from './wgpuColorAdjustmentMaterialFeature.ts';
|
|
15
|
+
import { wgpuSpriteRenderer, drawWgpuSprite } from './wgpuSprite.ts';
|
|
16
|
+
import { registerWgpuStandardMaterial } from './wgpuStandardMaterial.ts';
|
|
17
17
|
|
|
18
18
|
const CT_MODE_UNIFORM = 1;
|
|
19
19
|
|
|
@@ -36,8 +36,11 @@ async function drawSpriteOverNewTexture(
|
|
|
36
36
|
colorScaleBias: unknown,
|
|
37
37
|
): Promise<void> {
|
|
38
38
|
const texture = createRenderTexture({ height: size, width: size });
|
|
39
|
-
renderIntoWgpuRenderTexture(state, texture, () => {});
|
|
40
|
-
const sprite =
|
|
39
|
+
renderIntoWgpuRenderTexture(state, texture, () => {}, { color: [0, 0, 0, 0], depth: 1.0, stencil: 0 });
|
|
40
|
+
const sprite = ((created) => {
|
|
41
|
+
Object.assign(created.data, { texture });
|
|
42
|
+
return created;
|
|
43
|
+
})(createSprite());
|
|
41
44
|
prepareScene2DRender(state, sprite);
|
|
42
45
|
const proxy = getOrCreateRenderProxy2D(state, sprite);
|
|
43
46
|
(proxy as { colorScaleBias: unknown }).colorScaleBias = colorScaleBias;
|
|
@@ -46,27 +49,19 @@ async function drawSpriteOverNewTexture(
|
|
|
46
49
|
|
|
47
50
|
beforeAll(() => installWgpuMock());
|
|
48
51
|
|
|
49
|
-
describe('defaultWgpuSpriteRenderer', () => {
|
|
50
|
-
it('has createData and submit functions', () => {
|
|
51
|
-
expect(typeof defaultWgpuSpriteRenderer.createData).toBe('function');
|
|
52
|
-
expect(typeof defaultWgpuSpriteRenderer.isDirty).toBe('function');
|
|
53
|
-
expect(defaultWgpuSpriteRenderer.submit).toBe(drawWgpuSprite);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
52
|
describe('drawWgpuSprite', () => {
|
|
58
53
|
it('accepts an unbound sprite', async () => {
|
|
59
54
|
const state = await createWgpuRenderStateForTest();
|
|
60
|
-
|
|
55
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
61
56
|
const sprite = createSprite();
|
|
62
57
|
prepareScene2DRender(state, sprite);
|
|
63
58
|
expect(() => drawWgpuSprite(state, getOrCreateRenderProxy2D(state, sprite))).not.toThrow();
|
|
64
|
-
|
|
59
|
+
submitWgpuFrame(state);
|
|
65
60
|
});
|
|
66
61
|
|
|
67
62
|
it('records a tint against the instance the flush uploads when a new texture breaks the batch', async () => {
|
|
68
63
|
const state = await createWgpuRenderStateForTest();
|
|
69
|
-
|
|
64
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
70
65
|
registerWgpuRenderTextureResolver(state);
|
|
71
66
|
registerWgpuStandardMaterial(state);
|
|
72
67
|
registerWgpuColorAdjustmentMaterialFeature(state);
|
|
@@ -79,18 +74,21 @@ describe('drawWgpuSprite', () => {
|
|
|
79
74
|
|
|
80
75
|
expect(runtime.quadBatchWriterCount).toBe(1);
|
|
81
76
|
expect(runtime.quadBatchWriterColorScaleBiasMode).toBe(CT_MODE_UNIFORM);
|
|
82
|
-
|
|
77
|
+
submitWgpuFrame(state);
|
|
83
78
|
});
|
|
84
79
|
|
|
85
80
|
it('uses the physical slab once and preserves a top-origin render-target sub-view', async () => {
|
|
86
81
|
const state = await createWgpuRenderStateForTest();
|
|
87
|
-
|
|
82
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
88
83
|
registerWgpuRenderTextureResolver(state);
|
|
89
84
|
registerWgpuStandardMaterial(state);
|
|
90
85
|
const renderTexture = createRenderTexture({ height: 480, width: 720 });
|
|
91
86
|
setTextureUvFromPixelRect(renderTexture, 140, 160, 100, 80);
|
|
92
|
-
renderIntoWgpuRenderTexture(state, renderTexture, () => {});
|
|
93
|
-
const sprite =
|
|
87
|
+
renderIntoWgpuRenderTexture(state, renderTexture, () => {}, { color: [0, 0, 0, 0], depth: 1.0, stencil: 0 });
|
|
88
|
+
const sprite = ((created) => {
|
|
89
|
+
Object.assign(created.data, { texture: renderTexture });
|
|
90
|
+
return created;
|
|
91
|
+
})(createSprite());
|
|
94
92
|
prepareScene2DRender(state, sprite);
|
|
95
93
|
|
|
96
94
|
drawWgpuSprite(state, getOrCreateRenderProxy2D(state, sprite));
|
|
@@ -102,22 +100,25 @@ describe('drawWgpuSprite', () => {
|
|
|
102
100
|
expect(data[7]).toBeCloseTo(160 / 480);
|
|
103
101
|
expect(data[8]).toBeCloseTo(100 / 720);
|
|
104
102
|
expect(data[11]).toBeCloseTo(80 / 480);
|
|
105
|
-
|
|
103
|
+
submitWgpuFrame(state);
|
|
106
104
|
});
|
|
107
105
|
|
|
108
106
|
it('packs a quarter-turned Texture view as affine UV axes', async () => {
|
|
109
107
|
const state = await createWgpuRenderStateForTest();
|
|
110
|
-
|
|
108
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
111
109
|
registerWgpuRenderTextureResolver(state);
|
|
112
110
|
registerWgpuStandardMaterial(state);
|
|
113
111
|
const texture = createRenderTexture({ height: 50, width: 100 });
|
|
114
|
-
renderIntoWgpuRenderTexture(state, texture, () => {});
|
|
112
|
+
renderIntoWgpuRenderTexture(state, texture, () => {}, { color: [0, 0, 0, 0], depth: 1.0, stencil: 0 });
|
|
115
113
|
texture.uvOffset.x = 0.1;
|
|
116
114
|
texture.uvOffset.y = 0.4;
|
|
117
115
|
texture.uvScale.x = 0.3;
|
|
118
116
|
texture.uvScale.y = 0.2;
|
|
119
117
|
texture.uvRotation = -Math.PI / 2;
|
|
120
|
-
const sprite =
|
|
118
|
+
const sprite = ((created) => {
|
|
119
|
+
Object.assign(created.data, { texture });
|
|
120
|
+
return created;
|
|
121
|
+
})(createSprite());
|
|
121
122
|
prepareScene2DRender(state, sprite);
|
|
122
123
|
|
|
123
124
|
drawWgpuSprite(state, getOrCreateRenderProxy2D(state, sprite));
|
|
@@ -131,6 +132,14 @@ describe('drawWgpuSprite', () => {
|
|
|
131
132
|
expect(data[9]).toBeCloseTo(-0.3);
|
|
132
133
|
expect(data[10]).toBeCloseTo(0.2);
|
|
133
134
|
expect(data[11]).toBeCloseTo(0);
|
|
134
|
-
|
|
135
|
+
submitWgpuFrame(state);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe('wgpuSpriteRenderer', () => {
|
|
140
|
+
it('has createData and submit functions', () => {
|
|
141
|
+
expect(typeof wgpuSpriteRenderer.createData).toBe('function');
|
|
142
|
+
expect(typeof wgpuSpriteRenderer.isDirty).toBe('function');
|
|
143
|
+
expect(wgpuSpriteRenderer.submit).toBe(drawWgpuSprite);
|
|
135
144
|
});
|
|
136
145
|
});
|
|
@@ -1,29 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EntityRuntimeKey } from '@flighthq/entity/contract';
|
|
2
|
+
import { StandardMaterialKind } from '@flighthq/materials/contract';
|
|
2
3
|
import {
|
|
3
|
-
createEmptyWgpuRegistries,
|
|
4
4
|
createWgpuDeviceState,
|
|
5
|
-
createWgpuPipeline,
|
|
6
5
|
createWgpuRenderStateRuntime,
|
|
6
|
+
getWgpuQuadMaterialRenderer,
|
|
7
7
|
} from '@flighthq/render-wgpu/contract';
|
|
8
|
-
import type { WgpuRenderState } from '@flighthq/
|
|
9
|
-
import { EntityRuntimeKey, StandardMaterialKind } from '@flighthq/types/contract';
|
|
8
|
+
import type { WgpuDevice, WgpuRenderState } from '@flighthq/render-wgpu/contract';
|
|
10
9
|
|
|
11
|
-
import { registerWgpuStandardMaterial,
|
|
10
|
+
import { registerWgpuStandardMaterial, standardWgpuQuadMaterialRenderer } from './wgpuStandardMaterial.ts';
|
|
12
11
|
|
|
13
12
|
describe('registerWgpuStandardMaterial', () => {
|
|
14
13
|
it('registers the default renderer under StandardMaterialKind', () => {
|
|
15
14
|
const state = {} as WgpuRenderState;
|
|
16
|
-
state[EntityRuntimeKey] = createWgpuRenderStateRuntime(
|
|
17
|
-
createWgpuDeviceState({} as GPUDevice),
|
|
18
|
-
createWgpuPipeline(createEmptyWgpuRegistries()),
|
|
19
|
-
);
|
|
15
|
+
state[EntityRuntimeKey] = createWgpuRenderStateRuntime(createWgpuDeviceState({} as WgpuDevice));
|
|
20
16
|
registerWgpuStandardMaterial(state);
|
|
21
|
-
expect(
|
|
17
|
+
expect(getWgpuQuadMaterialRenderer(state, StandardMaterialKind)).toBe(standardWgpuQuadMaterialRenderer);
|
|
22
18
|
});
|
|
23
19
|
});
|
|
24
20
|
|
|
25
|
-
describe('
|
|
21
|
+
describe('standardWgpuQuadMaterialRenderer', () => {
|
|
26
22
|
it('declares no per-instance float data', () => {
|
|
27
|
-
expect(
|
|
23
|
+
expect(standardWgpuQuadMaterialRenderer.instanceFloatCount).toBe(0);
|
|
28
24
|
});
|
|
29
25
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { beginWgpuScreenRenderPassForTest, submitWgpuFrame } from '@flighthq/render-wgpu/contract';
|
|
2
2
|
import { createWgpuRenderStateForTest, installWgpuMock } from '@flighthq/render-wgpu/contract';
|
|
3
3
|
import { getOrCreateRenderProxy2D, prepareScene2DRender } from '@flighthq/render/contract';
|
|
4
4
|
import { createRichText } from '@flighthq/text/contract';
|
|
5
5
|
import { enableTextInput } from '@flighthq/textinput/contract';
|
|
6
6
|
|
|
7
|
-
import { drawWgpuRichText } from './wgpuRichText';
|
|
8
|
-
import { drawWgpuTextInputOverlay, enableWgpuTextInput } from './wgpuTextInput';
|
|
7
|
+
import { drawWgpuRichText } from './wgpuRichText.ts';
|
|
8
|
+
import { drawWgpuTextInputOverlay, enableWgpuTextInput } from './wgpuTextInput.ts';
|
|
9
9
|
|
|
10
10
|
beforeAll(() => {
|
|
11
11
|
installWgpuMock();
|
|
@@ -19,14 +19,17 @@ describe('drawWgpuTextInputOverlay', () => {
|
|
|
19
19
|
it('rasterizes a focused editable field without throwing', async () => {
|
|
20
20
|
enableWgpuTextInput();
|
|
21
21
|
const state = await createWgpuRenderStateForTest();
|
|
22
|
-
|
|
23
|
-
const input =
|
|
22
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
23
|
+
const input = ((created) => {
|
|
24
|
+
Object.assign(created.data, { height: 40, text: 'hi', width: 100 });
|
|
25
|
+
return created;
|
|
26
|
+
})(createRichText());
|
|
24
27
|
enableTextInput(input).focused = true;
|
|
25
28
|
prepareScene2DRender(state, input);
|
|
26
29
|
const renderProxy = getOrCreateRenderProxy2D(state, input);
|
|
27
30
|
|
|
28
31
|
expect(() => drawWgpuRichText(state, renderProxy)).not.toThrow();
|
|
29
|
-
|
|
32
|
+
submitWgpuFrame(state);
|
|
30
33
|
});
|
|
31
34
|
});
|
|
32
35
|
|