@flighthq/scene2d-wgpu 0.5.1-next.920.da8f530 → 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 +20 -19
- 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 +26 -14
- 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 +29 -25
- package/dist/wgpuQuadBatch.js.map +1 -1
- package/dist/wgpuQuadBatchWriter.d.ts +11 -5
- package/dist/wgpuQuadBatchWriter.d.ts.map +1 -1
- package/dist/wgpuQuadBatchWriter.js +45 -19
- 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 +49 -35
- 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 +30 -36
- 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 +17 -32
- 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 +68 -48
- 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 +20 -19
- 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 +95 -90
- package/dist/wgpuVelocity.js.map +1 -1
- package/package.json +31 -24
- 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 +99 -38
- package/src/wgpuQuadBatch.test.ts +126 -32
- package/src/wgpuQuadBatchWriter.test.ts +108 -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 +38 -41
- 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 +67 -24
- 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,14 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
createImageResource,
|
|
3
|
+
registerTestImageDimensionResolver,
|
|
4
|
+
unregisterTestImageDimensionResolver,
|
|
5
|
+
} from '@flighthq/image/contract';
|
|
6
|
+
import type { HostImageCapability, ImageResource } from '@flighthq/image/contract';
|
|
7
|
+
import { beginWgpuScreenRenderPassForTest, submitWgpuFrame } from '@flighthq/render-wgpu/contract';
|
|
3
8
|
import { getWgpuRenderStateRuntime } from '@flighthq/render-wgpu/contract';
|
|
4
9
|
import { createWgpuRenderStateForTest, installWgpuMock } from '@flighthq/render-wgpu/contract';
|
|
10
|
+
import { BatchFormat } from '@flighthq/render/contract';
|
|
11
|
+
import type { RenderProxy2D } from '@flighthq/render/contract';
|
|
12
|
+
import type { CanvasSurface, HostCanvasCapability } from '@flighthq/surface/contract';
|
|
5
13
|
import { createTextLabel } from '@flighthq/text/contract';
|
|
6
14
|
import * as textlayout from '@flighthq/textlayout/contract';
|
|
7
|
-
import type { Raster2DSurface, RenderProxy2D } from '@flighthq/types/contract';
|
|
8
|
-
import { BatchFormat, EntityRuntimeKey } from '@flighthq/types/contract';
|
|
9
15
|
|
|
10
|
-
import { registerWgpuStandardMaterial } from './wgpuStandardMaterial';
|
|
11
|
-
import {
|
|
16
|
+
import { registerWgpuStandardMaterial } from './wgpuStandardMaterial.ts';
|
|
17
|
+
import { wgpuTextLabelRenderer, drawWgpuTextLabel } from './wgpuTextLabel.ts';
|
|
18
|
+
|
|
19
|
+
// A test that wraps a host handle supplies the host: the resource measures through the registered
|
|
20
|
+
// resolver, and clearing after each test keeps this file from covering for another's missing one.
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
registerTestImageDimensionResolver();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
unregisterTestImageDimensionResolver();
|
|
27
|
+
});
|
|
12
28
|
|
|
13
29
|
beforeAll(() => installWgpuMock());
|
|
14
30
|
|
|
@@ -35,33 +51,70 @@ afterEach(() => {
|
|
|
35
51
|
vi.restoreAllMocks();
|
|
36
52
|
});
|
|
37
53
|
|
|
38
|
-
function
|
|
54
|
+
function createTestSurface(width: number, height: number): CanvasSurface {
|
|
39
55
|
const canvas = document.createElement('canvas');
|
|
40
56
|
canvas.width = width;
|
|
41
57
|
canvas.height = height;
|
|
42
58
|
const context = canvas.getContext('2d')!;
|
|
43
59
|
return {
|
|
44
|
-
[EntityRuntimeKey]: undefined,
|
|
45
60
|
get width() {
|
|
46
61
|
return canvas.width;
|
|
47
62
|
},
|
|
48
|
-
set width(value) {
|
|
63
|
+
set width(value: number) {
|
|
49
64
|
canvas.width = value;
|
|
50
65
|
},
|
|
51
66
|
get height() {
|
|
52
67
|
return canvas.height;
|
|
53
68
|
},
|
|
54
|
-
set height(value) {
|
|
69
|
+
set height(value: number) {
|
|
55
70
|
canvas.height = value;
|
|
56
71
|
},
|
|
57
72
|
context,
|
|
58
|
-
|
|
73
|
+
} as unknown as CanvasSurface;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function createTestCanvasHost(destroyFn: (surface: CanvasSurface) => void = () => {}): HostCanvasCapability {
|
|
77
|
+
return {
|
|
78
|
+
acquire: () => null,
|
|
79
|
+
create: () => null,
|
|
80
|
+
createSurface: createTestSurface,
|
|
81
|
+
destroySurface: destroyFn,
|
|
82
|
+
release() {},
|
|
59
83
|
};
|
|
60
84
|
}
|
|
61
85
|
|
|
62
|
-
function
|
|
86
|
+
function createTestImageHost(): HostImageCapability {
|
|
63
87
|
return {
|
|
64
|
-
surface
|
|
88
|
+
createImageFromSurface(surface) {
|
|
89
|
+
return createImageResource((surface as unknown as { context: CanvasRenderingContext2D }).context.canvas);
|
|
90
|
+
},
|
|
91
|
+
loadImageFromUrl: () => Promise.reject(new Error('not implemented')),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function setTestHosts(state: { canvasHost: unknown; imageHost: unknown }): void {
|
|
96
|
+
state.canvasHost = createTestCanvasHost();
|
|
97
|
+
state.imageHost = createTestImageHost();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface WgpuTextLabelDataView {
|
|
101
|
+
allocH: number;
|
|
102
|
+
allocW: number;
|
|
103
|
+
image: ImageResource | null;
|
|
104
|
+
surface: CanvasSurface | null;
|
|
105
|
+
lastContentId: number;
|
|
106
|
+
lastPixelRatio: number;
|
|
107
|
+
logW: number;
|
|
108
|
+
logH: number;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function makeTextData(): WgpuTextLabelDataView {
|
|
112
|
+
const surface = createTestSurface(1, 1);
|
|
113
|
+
return {
|
|
114
|
+
allocH: 0,
|
|
115
|
+
allocW: 0,
|
|
116
|
+
image: createImageResource((surface as unknown as { context: CanvasRenderingContext2D }).context.canvas),
|
|
117
|
+
surface,
|
|
65
118
|
lastContentId: -1,
|
|
66
119
|
lastPixelRatio: 0,
|
|
67
120
|
logW: 0,
|
|
@@ -86,118 +139,79 @@ function makeTextProxy(text = '', rendererData: unknown = null): RenderProxy2D {
|
|
|
86
139
|
} as unknown as RenderProxy2D;
|
|
87
140
|
}
|
|
88
141
|
|
|
89
|
-
function createTestRaster2DSurfaceProvider(destroyRaster2DSurface: (surface: Raster2DSurface) => void = () => {}) {
|
|
90
|
-
return {
|
|
91
|
-
[EntityRuntimeKey]: undefined,
|
|
92
|
-
createRaster2DSurface(width: number, height: number) {
|
|
93
|
-
return createTestRaster2DSurface(width, height);
|
|
94
|
-
},
|
|
95
|
-
destroyRaster2DSurface,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
describe('defaultWgpuTextLabelRenderer', () => {
|
|
100
|
-
it('declares BatchFormat.Quad', () => {
|
|
101
|
-
expect(defaultWgpuTextLabelRenderer.format).toBe(BatchFormat.Quad);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('has createData and submit functions', () => {
|
|
105
|
-
expect(typeof defaultWgpuTextLabelRenderer.createData).toBe('function');
|
|
106
|
-
expect(typeof defaultWgpuTextLabelRenderer.submit).toBe('function');
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('removes the GPU cache entry before returning the node surface to its creator', async () => {
|
|
110
|
-
const order: string[] = [];
|
|
111
|
-
const state = await createWgpuRenderStateForTest();
|
|
112
|
-
renderWgpuBackground(state);
|
|
113
|
-
const cache = getWgpuRenderStateRuntime(state).context.textureSourcePremultipliedTextureCache;
|
|
114
|
-
state.raster2DSurfaceProvider = createTestRaster2DSurfaceProvider((surface) => {
|
|
115
|
-
order.push('surface');
|
|
116
|
-
expect(cache.has(surface.image)).toBe(false);
|
|
117
|
-
});
|
|
118
|
-
registerWgpuStandardMaterial(state);
|
|
119
|
-
const data = defaultWgpuTextLabelRenderer.createData!(state, createTextLabel())!;
|
|
120
|
-
drawWgpuTextLabel(state, makeTextProxy('owned', data));
|
|
121
|
-
const surface = (data as unknown as { surface: Raster2DSurface }).surface;
|
|
122
|
-
const entry = cache.get(surface.image)!;
|
|
123
|
-
submitWgpuRenderPass(state);
|
|
124
|
-
vi.spyOn(entry.texture, 'destroy').mockImplementation(() => {
|
|
125
|
-
order.push('texture');
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
defaultWgpuTextLabelRenderer.destroyData!(state, data);
|
|
129
|
-
|
|
130
|
-
expect(cache.has(surface.image)).toBe(false);
|
|
131
|
-
expect(order).toEqual(['texture', 'surface']);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
142
|
describe('drawWgpuTextLabel', () => {
|
|
136
143
|
it('keeps different text nodes on distinct surfaces and GPU textures in one frame', async () => {
|
|
137
144
|
const state = await createWgpuRenderStateForTest();
|
|
138
|
-
state
|
|
139
|
-
|
|
145
|
+
setTestHosts(state);
|
|
146
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
140
147
|
registerWgpuStandardMaterial(state);
|
|
141
|
-
const firstData =
|
|
142
|
-
const secondData =
|
|
148
|
+
const firstData = wgpuTextLabelRenderer.createData!(state, createTextLabel())!;
|
|
149
|
+
const secondData = wgpuTextLabelRenderer.createData!(state, createTextLabel())!;
|
|
143
150
|
|
|
144
151
|
drawWgpuTextLabel(state, makeTextProxy('first', firstData));
|
|
145
152
|
drawWgpuTextLabel(state, makeTextProxy('second', secondData));
|
|
146
153
|
|
|
147
|
-
const
|
|
148
|
-
const
|
|
154
|
+
const firstView = firstData as unknown as WgpuTextLabelDataView;
|
|
155
|
+
const secondView = secondData as unknown as WgpuTextLabelDataView;
|
|
149
156
|
const cache = getWgpuRenderStateRuntime(state).context.textureSourcePremultipliedTextureCache;
|
|
150
|
-
|
|
151
|
-
expect(
|
|
152
|
-
expect(
|
|
153
|
-
expect(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
expect((firstData as unknown as { surface: Raster2DSurface }).surface).toBe(firstSurface);
|
|
157
|
-
expect(firstSurface.image).toBe(firstImage);
|
|
158
|
-
submitWgpuRenderPass(state);
|
|
157
|
+
expect(firstView.surface).not.toBeNull();
|
|
158
|
+
expect(secondView.surface).not.toBeNull();
|
|
159
|
+
expect(firstView.surface).not.toBe(secondView.surface);
|
|
160
|
+
expect(firstView.image).not.toBe(secondView.image);
|
|
161
|
+
expect(cache.get(firstView.image!)?.texture).not.toBe(cache.get(secondView.image!)?.texture);
|
|
162
|
+
submitWgpuFrame(state);
|
|
159
163
|
});
|
|
160
164
|
|
|
161
165
|
it('returns early when text is empty', async () => {
|
|
162
166
|
const state = await createWgpuRenderStateForTest();
|
|
163
|
-
|
|
167
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
164
168
|
registerWgpuStandardMaterial(state);
|
|
165
169
|
expect(() => drawWgpuTextLabel(state, makeTextProxy('', makeTextData()))).not.toThrow();
|
|
166
170
|
expect(getWgpuRenderStateRuntime(state).quadBatchWriterCount).toBe(0);
|
|
167
|
-
|
|
171
|
+
submitWgpuFrame(state);
|
|
168
172
|
});
|
|
169
173
|
|
|
170
174
|
it('writes one instance to the quad-batch writer when text has content', async () => {
|
|
171
175
|
const state = await createWgpuRenderStateForTest();
|
|
172
|
-
state
|
|
173
|
-
|
|
176
|
+
setTestHosts(state);
|
|
177
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
174
178
|
registerWgpuStandardMaterial(state);
|
|
175
179
|
drawWgpuTextLabel(state, makeTextProxy('hello', makeTextData()));
|
|
176
180
|
expect(getWgpuRenderStateRuntime(state).quadBatchWriterCount).toBe(1);
|
|
177
|
-
|
|
181
|
+
submitWgpuFrame(state);
|
|
178
182
|
});
|
|
179
183
|
|
|
180
184
|
it('rasterizes packed run alpha into the canvas color', async () => {
|
|
181
185
|
const state = await createWgpuRenderStateForTest();
|
|
182
|
-
state
|
|
183
|
-
renderWgpuBackground(state);
|
|
186
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
184
187
|
registerWgpuStandardMaterial(state);
|
|
185
|
-
const
|
|
188
|
+
const styles: Array<string | CanvasGradient | CanvasPattern> = [];
|
|
189
|
+
const wrappedCreateSurface = (w: number, h: number): CanvasSurface => {
|
|
190
|
+
const surface = createTestSurface(w, h);
|
|
191
|
+
vi.spyOn(surface.context, 'fillText').mockImplementation(function (this: CanvasRenderingContext2D) {
|
|
192
|
+
styles.push(this.fillStyle);
|
|
193
|
+
});
|
|
194
|
+
return surface;
|
|
195
|
+
};
|
|
196
|
+
state.canvasHost = {
|
|
197
|
+
...createTestCanvasHost(),
|
|
198
|
+
createSurface: wrappedCreateSurface,
|
|
199
|
+
} as unknown as typeof state.canvasHost;
|
|
200
|
+
state.imageHost = createTestImageHost() as unknown as typeof state.imageHost;
|
|
201
|
+
const data = wgpuTextLabelRenderer.createData!(state, createTextLabel())!;
|
|
186
202
|
const proxy = makeTextProxy('hello', data);
|
|
187
203
|
(proxy.source as ReturnType<typeof createTextLabel>).data.textFormat = { color: 0xff000080 };
|
|
188
|
-
const styles: Array<string | CanvasGradient | CanvasPattern> = [];
|
|
189
|
-
vi.spyOn(data.surface.context, 'fillText').mockImplementation(() => styles.push(data.surface.context.fillStyle));
|
|
190
204
|
|
|
191
205
|
drawWgpuTextLabel(state, proxy);
|
|
192
206
|
|
|
193
207
|
expect(styles).toEqual(['rgba(255, 0, 0, 0.5019607843137255)']);
|
|
194
|
-
|
|
208
|
+
submitWgpuFrame(state);
|
|
195
209
|
});
|
|
196
210
|
|
|
197
211
|
it('does not re-rasterize when only alpha changes (content version unchanged)', async () => {
|
|
198
212
|
const state = await createWgpuRenderStateForTest();
|
|
199
|
-
state
|
|
200
|
-
|
|
213
|
+
setTestHosts(state);
|
|
214
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
201
215
|
registerWgpuStandardMaterial(state);
|
|
202
216
|
const proxy = makeTextProxy('hello', makeTextData());
|
|
203
217
|
drawWgpuTextLabel(state, proxy);
|
|
@@ -206,7 +220,50 @@ describe('drawWgpuTextLabel', () => {
|
|
|
206
220
|
drawWgpuTextLabel(state, proxy);
|
|
207
221
|
// Version is unchanged, so the rasterization block is skipped entirely on the second draw.
|
|
208
222
|
expect((proxy.rendererData as any).lastContentId).toBe(0);
|
|
209
|
-
|
|
223
|
+
submitWgpuFrame(state);
|
|
210
224
|
updateSpy.mockRestore();
|
|
211
225
|
});
|
|
212
226
|
});
|
|
227
|
+
|
|
228
|
+
describe('wgpuTextLabelRenderer', () => {
|
|
229
|
+
it('declares BatchFormat.Quad', () => {
|
|
230
|
+
expect(wgpuTextLabelRenderer.format).toBe(BatchFormat.Quad);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('has createData and submit functions', () => {
|
|
234
|
+
expect(typeof wgpuTextLabelRenderer.createData).toBe('function');
|
|
235
|
+
expect(typeof wgpuTextLabelRenderer.submit).toBe('function');
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('removes the GPU cache entry before returning the node surface to its creator', async () => {
|
|
239
|
+
const order: string[] = [];
|
|
240
|
+
let trackOrder = false;
|
|
241
|
+
const state = await createWgpuRenderStateForTest();
|
|
242
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
243
|
+
const cache = getWgpuRenderStateRuntime(state).context.textureSourcePremultipliedTextureCache;
|
|
244
|
+
let trackedImage: ImageResource | null = null;
|
|
245
|
+
state.canvasHost = createTestCanvasHost(() => {
|
|
246
|
+
if (!trackOrder) return;
|
|
247
|
+
order.push('surface');
|
|
248
|
+
if (trackedImage !== null) expect(cache.has(trackedImage)).toBe(false);
|
|
249
|
+
});
|
|
250
|
+
state.imageHost = createTestImageHost();
|
|
251
|
+
registerWgpuStandardMaterial(state);
|
|
252
|
+
const data = wgpuTextLabelRenderer.createData!(state, createTextLabel())!;
|
|
253
|
+
drawWgpuTextLabel(state, makeTextProxy('owned', data));
|
|
254
|
+
const dataView = data as unknown as WgpuTextLabelDataView;
|
|
255
|
+
const image = dataView.image!;
|
|
256
|
+
trackedImage = image;
|
|
257
|
+
const entry = cache.get(image)!;
|
|
258
|
+
submitWgpuFrame(state);
|
|
259
|
+
vi.spyOn(entry.texture, 'destroy').mockImplementation(() => {
|
|
260
|
+
order.push('texture');
|
|
261
|
+
});
|
|
262
|
+
trackOrder = true;
|
|
263
|
+
|
|
264
|
+
wgpuTextLabelRenderer.destroyData!(state, data);
|
|
265
|
+
|
|
266
|
+
expect(cache.has(image)).toBe(false);
|
|
267
|
+
expect(order).toEqual(['texture', 'surface']);
|
|
268
|
+
});
|
|
269
|
+
});
|
package/src/wgpuTilemap.test.ts
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { beginWgpuScreenRenderPassForTest, submitWgpuFrame } from '@flighthq/render-wgpu/contract';
|
|
2
2
|
import { createWgpuRenderStateForTest, installWgpuMock } from '@flighthq/render-wgpu/contract';
|
|
3
3
|
import { getRenderProxy2D, prepareScene2DRender } from '@flighthq/render/contract';
|
|
4
4
|
import { createTilemap } from '@flighthq/tilemap/contract';
|
|
5
5
|
|
|
6
|
-
import { flushWgpuQuadBatchWriter } from './wgpuQuadBatchWriter';
|
|
7
|
-
import {
|
|
6
|
+
import { flushWgpuQuadBatchWriter } from './wgpuQuadBatchWriter.ts';
|
|
7
|
+
import { wgpuTilemapRenderer } from './wgpuTilemap.ts';
|
|
8
8
|
|
|
9
9
|
beforeAll(() => {
|
|
10
10
|
installWgpuMock();
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
describe('
|
|
13
|
+
describe('wgpuTilemapRenderer', () => {
|
|
14
14
|
it('has a createData function', () => {
|
|
15
|
-
expect(typeof
|
|
15
|
+
expect(typeof wgpuTilemapRenderer.createData).toBe('function');
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
it('has a submit function', () => {
|
|
19
|
-
expect(typeof
|
|
19
|
+
expect(typeof wgpuTilemapRenderer.submit).toBe('function');
|
|
20
20
|
});
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
describe('
|
|
23
|
+
describe('wgpuTilemapRenderer.submit', () => {
|
|
24
24
|
it('does not throw when atlas is null', async () => {
|
|
25
25
|
const state = await createWgpuRenderStateForTest();
|
|
26
|
-
|
|
26
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
27
27
|
|
|
28
28
|
const tilemap = createTilemap();
|
|
29
29
|
prepareScene2DRender(state, tilemap);
|
|
30
30
|
const renderProxy = getRenderProxy2D(state, tilemap)!;
|
|
31
31
|
|
|
32
32
|
expect(() => {
|
|
33
|
-
|
|
33
|
+
wgpuTilemapRenderer.submit(state, renderProxy);
|
|
34
34
|
flushWgpuQuadBatchWriter(state as any);
|
|
35
35
|
}).not.toThrow();
|
|
36
|
-
|
|
36
|
+
submitWgpuFrame(state);
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
it('does not throw when renderPass is null', async () => {
|
|
@@ -42,6 +42,6 @@ describe('defaultWgpuTilemapRenderer.submit', () => {
|
|
|
42
42
|
prepareScene2DRender(state, tilemap);
|
|
43
43
|
const renderProxy = getRenderProxy2D(state, tilemap)!;
|
|
44
44
|
|
|
45
|
-
expect(() =>
|
|
45
|
+
expect(() => wgpuTilemapRenderer.submit(state, renderProxy)).not.toThrow();
|
|
46
46
|
});
|
|
47
47
|
});
|
package/src/wgpuVelocity.test.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { createParticleEmitter2D, reserveParticleEmitter2D } from '@flighthq/particleemitter/contract';
|
|
2
2
|
import { createQuadBatch, getQuadBatchRuntime } from '@flighthq/quadbatch/contract';
|
|
3
|
+
import type { QuadBatchRuntime } from '@flighthq/quadbatch/contract';
|
|
4
|
+
import { QuadBatchKind } from '@flighthq/quadbatch/contract';
|
|
3
5
|
import {
|
|
6
|
+
beginWgpuScreenRenderPassForTest,
|
|
4
7
|
createWgpuOffscreenRenderState,
|
|
5
|
-
createWgpuPipeline,
|
|
6
8
|
getWgpuRenderStateRuntime,
|
|
7
|
-
renderWgpuBackground,
|
|
8
9
|
} from '@flighthq/render-wgpu/contract';
|
|
9
10
|
import { createWgpuRenderStateForTest, installWgpuMock } from '@flighthq/render-wgpu/contract';
|
|
10
11
|
import { createDisplayObject } from '@flighthq/scene2d/contract';
|
|
11
|
-
import type {
|
|
12
|
-
import { QuadBatchKind } from '@flighthq/types/contract';
|
|
12
|
+
import type { TextureAtlas, TextureAtlasRegion } from '@flighthq/textureatlas/contract';
|
|
13
13
|
import { beginVelocityFrame, contributeVelocity, createVelocityField } from '@flighthq/velocity/contract';
|
|
14
14
|
import { beforeAll, describe, expect, it } from 'vitest';
|
|
15
15
|
|
|
16
16
|
import {
|
|
17
17
|
createWgpuVelocityTarget,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
wgpuNode2DVelocityWriter,
|
|
19
|
+
wgpuParticleEmitter2DVelocityWriter,
|
|
20
|
+
wgpuQuadBatchVelocityWriter,
|
|
21
21
|
drawWgpuVelocityQuad,
|
|
22
22
|
getWgpuVelocityWriter,
|
|
23
23
|
registerWgpuVelocityWriter,
|
|
24
24
|
renderWgpuVelocity,
|
|
25
|
-
} from './wgpuVelocity';
|
|
25
|
+
} from './wgpuVelocity.ts';
|
|
26
26
|
|
|
27
27
|
beforeAll(() => {
|
|
28
28
|
installWgpuMock();
|
|
@@ -38,70 +38,6 @@ describe('createWgpuVelocityTarget', () => {
|
|
|
38
38
|
});
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
describe('defaultWgpuNode2DVelocityWriter', () => {
|
|
42
|
-
it('is a velocity writer function', () => {
|
|
43
|
-
expect(typeof defaultWgpuNode2DVelocityWriter).toBe('function');
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe('defaultWgpuParticleEmitter2DVelocityWriter', () => {
|
|
48
|
-
it('is a velocity writer function', () => {
|
|
49
|
-
expect(typeof defaultWgpuParticleEmitter2DVelocityWriter).toBe('function');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('emits per-particle velocity for an emitter with a velocities array without throwing', async () => {
|
|
53
|
-
const state = await createWgpuRenderStateForTest();
|
|
54
|
-
const target = createWgpuVelocityTarget(state, 128, 64);
|
|
55
|
-
const region = { id: 0, x: 0, y: 0, width: 16, height: 16, pivotX: null, pivotY: null } as TextureAtlasRegion;
|
|
56
|
-
const atlas = { texture: null, regions: [region] } as TextureAtlas;
|
|
57
|
-
const emitter = createParticleEmitter2D();
|
|
58
|
-
reserveParticleEmitter2D(emitter, 2);
|
|
59
|
-
emitter.data.atlas = atlas;
|
|
60
|
-
emitter.data.particleCount = 2;
|
|
61
|
-
emitter.data.ids[0] = 0;
|
|
62
|
-
emitter.data.ids[1] = 0;
|
|
63
|
-
emitter.data.transforms.set([10, 10, 0, 1, 40, 20, 0, 1]);
|
|
64
|
-
emitter.data.velocities.set([3, -2, -1, 4]);
|
|
65
|
-
|
|
66
|
-
registerWgpuVelocityWriter(state, emitter.kind, defaultWgpuParticleEmitter2DVelocityWriter);
|
|
67
|
-
const field = createVelocityField();
|
|
68
|
-
beginVelocityFrame(field);
|
|
69
|
-
|
|
70
|
-
renderWgpuBackground(state);
|
|
71
|
-
expect(() => renderWgpuVelocity(state, emitter, field, target)).not.toThrow();
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe('defaultWgpuQuadBatchVelocityWriter', () => {
|
|
76
|
-
it('is a velocity writer function', () => {
|
|
77
|
-
expect(typeof defaultWgpuQuadBatchVelocityWriter).toBe('function');
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('emits per-instance velocity for a batch with an instanceVelocities array without throwing', async () => {
|
|
81
|
-
const state = await createWgpuRenderStateForTest();
|
|
82
|
-
const target = createWgpuVelocityTarget(state, 128, 64);
|
|
83
|
-
const region = { id: 0, x: 0, y: 0, width: 32, height: 32, pivotX: null, pivotY: null } as TextureAtlasRegion;
|
|
84
|
-
const atlas = { texture: null, regions: [region] } as TextureAtlas;
|
|
85
|
-
const batch = createQuadBatch({
|
|
86
|
-
data: {
|
|
87
|
-
atlas,
|
|
88
|
-
ids: new Uint16Array([0, 0]),
|
|
89
|
-
instanceCount: 2,
|
|
90
|
-
transforms: new Float32Array([0, 0, 40, 10]),
|
|
91
|
-
transformType: 'vector2',
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
(getQuadBatchRuntime(batch) as QuadBatchRuntime).instanceVelocities = new Float32Array([3, -2, -1, 4]);
|
|
95
|
-
|
|
96
|
-
registerWgpuVelocityWriter(state, QuadBatchKind, defaultWgpuQuadBatchVelocityWriter);
|
|
97
|
-
const field = createVelocityField();
|
|
98
|
-
beginVelocityFrame(field);
|
|
99
|
-
|
|
100
|
-
renderWgpuBackground(state);
|
|
101
|
-
expect(() => renderWgpuVelocity(state, batch, field, target)).not.toThrow();
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
41
|
describe('drawWgpuVelocityQuad', () => {
|
|
106
42
|
it('is a no-op outside an active velocity pass', async () => {
|
|
107
43
|
const state = await createWgpuRenderStateForTest();
|
|
@@ -121,8 +57,8 @@ describe('registerWgpuVelocityWriter', () => {
|
|
|
121
57
|
it('registers a writer dispatched by kind', async () => {
|
|
122
58
|
const state = await createWgpuRenderStateForTest();
|
|
123
59
|
const root = createDisplayObject();
|
|
124
|
-
registerWgpuVelocityWriter(state, root.kind,
|
|
125
|
-
expect(getWgpuVelocityWriter(state, root.kind)).toBe(
|
|
60
|
+
registerWgpuVelocityWriter(state, root.kind, wgpuNode2DVelocityWriter);
|
|
61
|
+
expect(getWgpuVelocityWriter(state, root.kind)).toBe(wgpuNode2DVelocityWriter);
|
|
126
62
|
});
|
|
127
63
|
|
|
128
64
|
it('replaces persistent snapshots and preserves a derived pipeline snapshot', async () => {
|
|
@@ -131,20 +67,19 @@ describe('registerWgpuVelocityWriter', () => {
|
|
|
131
67
|
const replacement = vi.fn();
|
|
132
68
|
const before = getWgpuRenderStateRuntime(state).registries.velocityWriters;
|
|
133
69
|
|
|
134
|
-
registerWgpuVelocityWriter(state, kind,
|
|
70
|
+
registerWgpuVelocityWriter(state, kind, wgpuNode2DVelocityWriter);
|
|
135
71
|
const registered = getWgpuRenderStateRuntime(state).registries.velocityWriters;
|
|
136
|
-
const offscreen = createWgpuOffscreenRenderState(
|
|
137
|
-
state.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
);
|
|
72
|
+
const offscreen = createWgpuOffscreenRenderState(state.deviceState, {
|
|
73
|
+
...getWgpuRenderStateRuntime(state).registries,
|
|
74
|
+
format: state.format,
|
|
75
|
+
});
|
|
141
76
|
registerWgpuVelocityWriter(state, kind, replacement);
|
|
142
77
|
|
|
143
78
|
expect(registered).not.toBe(before);
|
|
144
|
-
expect(before.
|
|
145
|
-
expect(registered.
|
|
79
|
+
expect(before.has(kind)).toBe(false);
|
|
80
|
+
expect(registered.get(kind)).toEqual(wgpuNode2DVelocityWriter);
|
|
146
81
|
expect(getWgpuVelocityWriter(state, kind)).toBe(replacement);
|
|
147
|
-
expect(getWgpuVelocityWriter(offscreen, kind)).toBe(
|
|
82
|
+
expect(getWgpuVelocityWriter(offscreen, kind)).toBe(wgpuNode2DVelocityWriter);
|
|
148
83
|
});
|
|
149
84
|
});
|
|
150
85
|
|
|
@@ -153,17 +88,17 @@ describe('renderWgpuVelocity', () => {
|
|
|
153
88
|
const state = await createWgpuRenderStateForTest();
|
|
154
89
|
const target = createWgpuVelocityTarget(state, 128, 64);
|
|
155
90
|
const root = createDisplayObject();
|
|
156
|
-
registerWgpuVelocityWriter(state, root.kind,
|
|
91
|
+
registerWgpuVelocityWriter(state, root.kind, wgpuNode2DVelocityWriter);
|
|
157
92
|
|
|
158
93
|
const field = createVelocityField();
|
|
159
94
|
beginVelocityFrame(field);
|
|
160
95
|
contributeVelocity(field, root, 3, -2);
|
|
161
96
|
|
|
162
|
-
|
|
97
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
163
98
|
expect(() => renderWgpuVelocity(state, root, field, target)).not.toThrow();
|
|
164
99
|
});
|
|
165
100
|
|
|
166
|
-
it('throws when no command encoder is open (
|
|
101
|
+
it('throws when no command encoder is open (no pass has opened one)', async () => {
|
|
167
102
|
const state = await createWgpuRenderStateForTest();
|
|
168
103
|
const target = createWgpuVelocityTarget(state, 128, 64);
|
|
169
104
|
const root = createDisplayObject();
|
|
@@ -173,3 +108,68 @@ describe('renderWgpuVelocity', () => {
|
|
|
173
108
|
expect(() => renderWgpuVelocity(state, root, field, target)).toThrow(/command encoder/);
|
|
174
109
|
});
|
|
175
110
|
});
|
|
111
|
+
|
|
112
|
+
describe('wgpuNode2DVelocityWriter', () => {
|
|
113
|
+
it('is a velocity writer function', () => {
|
|
114
|
+
expect(typeof wgpuNode2DVelocityWriter).toBe('function');
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe('wgpuParticleEmitter2DVelocityWriter', () => {
|
|
119
|
+
it('is a velocity writer function', () => {
|
|
120
|
+
expect(typeof wgpuParticleEmitter2DVelocityWriter).toBe('function');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('emits per-particle velocity for an emitter with a velocities array without throwing', async () => {
|
|
124
|
+
const state = await createWgpuRenderStateForTest();
|
|
125
|
+
const target = createWgpuVelocityTarget(state, 128, 64);
|
|
126
|
+
const region = { id: 0, x: 0, y: 0, width: 16, height: 16, pivotX: null, pivotY: null } as TextureAtlasRegion;
|
|
127
|
+
const atlas = { texture: null, regions: [region] } as TextureAtlas;
|
|
128
|
+
const emitter = createParticleEmitter2D();
|
|
129
|
+
reserveParticleEmitter2D(emitter, 2);
|
|
130
|
+
emitter.data.atlas = atlas;
|
|
131
|
+
emitter.data.particleCount = 2;
|
|
132
|
+
emitter.data.ids[0] = 0;
|
|
133
|
+
emitter.data.ids[1] = 0;
|
|
134
|
+
emitter.data.transforms.set([10, 10, 0, 1, 40, 20, 0, 1]);
|
|
135
|
+
emitter.data.velocities.set([3, -2, -1, 4]);
|
|
136
|
+
|
|
137
|
+
registerWgpuVelocityWriter(state, emitter.kind, wgpuParticleEmitter2DVelocityWriter);
|
|
138
|
+
const field = createVelocityField();
|
|
139
|
+
beginVelocityFrame(field);
|
|
140
|
+
|
|
141
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
142
|
+
expect(() => renderWgpuVelocity(state, emitter, field, target)).not.toThrow();
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe('wgpuQuadBatchVelocityWriter', () => {
|
|
147
|
+
it('is a velocity writer function', () => {
|
|
148
|
+
expect(typeof wgpuQuadBatchVelocityWriter).toBe('function');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('emits per-instance velocity for a batch with an instanceVelocities array without throwing', async () => {
|
|
152
|
+
const state = await createWgpuRenderStateForTest();
|
|
153
|
+
const target = createWgpuVelocityTarget(state, 128, 64);
|
|
154
|
+
const region = { id: 0, x: 0, y: 0, width: 32, height: 32, pivotX: null, pivotY: null } as TextureAtlasRegion;
|
|
155
|
+
const atlas = { texture: null, regions: [region] } as TextureAtlas;
|
|
156
|
+
const batch = ((created) => {
|
|
157
|
+
Object.assign(created.data, {
|
|
158
|
+
atlas,
|
|
159
|
+
ids: new Uint16Array([0, 0]),
|
|
160
|
+
instanceCount: 2,
|
|
161
|
+
transforms: new Float32Array([0, 0, 40, 10]),
|
|
162
|
+
transformType: 'vector2',
|
|
163
|
+
});
|
|
164
|
+
return created;
|
|
165
|
+
})(createQuadBatch());
|
|
166
|
+
(getQuadBatchRuntime(batch) as QuadBatchRuntime).instanceVelocities = new Float32Array([3, -2, -1, 4]);
|
|
167
|
+
|
|
168
|
+
registerWgpuVelocityWriter(state, QuadBatchKind, wgpuQuadBatchVelocityWriter);
|
|
169
|
+
const field = createVelocityField();
|
|
170
|
+
beginVelocityFrame(field);
|
|
171
|
+
|
|
172
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
173
|
+
expect(() => renderWgpuVelocity(state, batch, field, target)).not.toThrow();
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scene2dWgpuPipeline.d.ts","sourceRoot":"","sources":["../src/scene2dWgpuPipeline.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAwB,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAoDnF,eAAO,MAAM,mBAAmB,EAAE,YAQhC,CAAC"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { withRegistryTableEntry } from '@flighthq/registry/contract';
|
|
2
|
-
import { createEmptyWgpuRegistries, createWgpuPipeline } from '@flighthq/render-wgpu/contract';
|
|
3
|
-
import { BitmapTextKind, DisplayObjectKind, MorphShapeKind, ParticleEmitter2DKind, QuadBatchKind, RenderCacheKind, RichTextKind, Scale9ShapeKind, Scale9SpriteKind, ShapeKind, SpriteKind, StandardMaterialKind, TextLabelKind, TilemapKind, } from '@flighthq/types/contract';
|
|
4
|
-
import { defaultWgpuBitmapTextRenderer } from './wgpuBitmapText';
|
|
5
|
-
import { defaultWgpuRenderCacheRenderer } from './wgpuCache';
|
|
6
|
-
import { defaultWgpuScene2DRenderer } from './wgpuNode2D';
|
|
7
|
-
import { defaultWgpuParticleEmitter2DRenderer } from './wgpuParticleEmitter2D';
|
|
8
|
-
import { defaultWgpuQuadBatchRenderer } from './wgpuQuadBatch';
|
|
9
|
-
import { defaultWgpuRichTextRenderer } from './wgpuRichText';
|
|
10
|
-
import { defaultWgpuScale9ShapeRenderer } from './wgpuScale9Shape';
|
|
11
|
-
import { defaultWgpuScale9SpriteRenderer } from './wgpuScale9Sprite';
|
|
12
|
-
import { defaultWgpuMorphShapeRenderer, defaultWgpuShapeRenderer } from './wgpuShape';
|
|
13
|
-
import { defaultWgpuSpriteRenderer } from './wgpuSprite';
|
|
14
|
-
import { standardWgpuMaterialRenderer } from './wgpuStandardMaterial';
|
|
15
|
-
import { defaultWgpuTextLabelRenderer } from './wgpuTextLabel';
|
|
16
|
-
import { defaultWgpuTilemapRenderer } from './wgpuTilemap';
|
|
17
|
-
function buildScene2dWgpuRenderers() {
|
|
18
|
-
let table = createEmptyWgpuRegistries().renderers;
|
|
19
|
-
table = withRegistryTableEntry(table, BitmapTextKind, defaultWgpuBitmapTextRenderer);
|
|
20
|
-
table = withRegistryTableEntry(table, DisplayObjectKind, defaultWgpuScene2DRenderer);
|
|
21
|
-
table = withRegistryTableEntry(table, MorphShapeKind, defaultWgpuMorphShapeRenderer);
|
|
22
|
-
table = withRegistryTableEntry(table, ParticleEmitter2DKind, defaultWgpuParticleEmitter2DRenderer);
|
|
23
|
-
table = withRegistryTableEntry(table, QuadBatchKind, defaultWgpuQuadBatchRenderer);
|
|
24
|
-
table = withRegistryTableEntry(table, RenderCacheKind, defaultWgpuRenderCacheRenderer);
|
|
25
|
-
table = withRegistryTableEntry(table, RichTextKind, defaultWgpuRichTextRenderer);
|
|
26
|
-
table = withRegistryTableEntry(table, Scale9ShapeKind, defaultWgpuScale9ShapeRenderer);
|
|
27
|
-
table = withRegistryTableEntry(table, Scale9SpriteKind, defaultWgpuScale9SpriteRenderer);
|
|
28
|
-
table = withRegistryTableEntry(table, ShapeKind, defaultWgpuShapeRenderer);
|
|
29
|
-
table = withRegistryTableEntry(table, SpriteKind, defaultWgpuSpriteRenderer);
|
|
30
|
-
table = withRegistryTableEntry(table, TextLabelKind, defaultWgpuTextLabelRenderer);
|
|
31
|
-
table = withRegistryTableEntry(table, TilemapKind, defaultWgpuTilemapRenderer);
|
|
32
|
-
return table;
|
|
33
|
-
}
|
|
34
|
-
const _registries = createEmptyWgpuRegistries();
|
|
35
|
-
export const scene2dWgpuPipeline = createWgpuPipeline({
|
|
36
|
-
..._registries,
|
|
37
|
-
materialRenderers: withRegistryTableEntry(_registries.materialRenderers, StandardMaterialKind, standardWgpuMaterialRenderer),
|
|
38
|
-
renderers: buildScene2dWgpuRenderers(),
|
|
39
|
-
});
|
|
40
|
-
//# sourceMappingURL=scene2dWgpuPipeline.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scene2dWgpuPipeline.js","sourceRoot":"","sources":["../src/scene2dWgpuPipeline.ts"],"names":[],"mappings":"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"}
|