@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,18 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { ColorScaleBias } from '@flighthq/adjustments/contract';
|
|
2
|
+
import { allocateEntity } from '@flighthq/entity/contract';
|
|
3
|
+
import { EntityRuntimeKey } from '@flighthq/entity/contract';
|
|
4
|
+
import { beginWgpuScreenRenderPassForTest, submitWgpuFrame } from '@flighthq/render-wgpu/contract';
|
|
3
5
|
import { getWgpuColorAdjustmentMaterialFeature, getWgpuRenderStateRuntime } from '@flighthq/render-wgpu/contract';
|
|
4
6
|
import { createWgpuRenderStateForTest, installWgpuMock } from '@flighthq/render-wgpu/contract';
|
|
7
|
+
import type { WgpuTexture, WgpuTextureView } from '@flighthq/render-wgpu/contract';
|
|
5
8
|
import { areColorAdjustmentsEnabled } from '@flighthq/render/contract';
|
|
6
|
-
import type { ColorScaleBias } from '@flighthq/types/contract';
|
|
7
|
-
import { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
8
9
|
|
|
9
|
-
import { registerWgpuColorAdjustmentMaterialFeature } from './wgpuColorAdjustmentMaterialFeature';
|
|
10
|
+
import { registerWgpuColorAdjustmentMaterialFeature } from './wgpuColorAdjustmentMaterialFeature.ts';
|
|
10
11
|
import {
|
|
11
12
|
flushWgpuQuadBatchWriter,
|
|
12
13
|
prepareWgpuQuadBatchWrite,
|
|
13
14
|
recordWgpuQuadBatchColorScaleBias,
|
|
14
|
-
} from './wgpuQuadBatchWriter';
|
|
15
|
-
import {
|
|
15
|
+
} from './wgpuQuadBatchWriter.ts';
|
|
16
|
+
import { standardWgpuQuadMaterialRenderer } from './wgpuStandardMaterial.ts';
|
|
16
17
|
|
|
17
18
|
beforeAll(() => {
|
|
18
19
|
installWgpuMock();
|
|
@@ -45,7 +46,7 @@ const CT_MODE_UNIFORM = 1;
|
|
|
45
46
|
const CT_MODE_PACKED_TINT = 2;
|
|
46
47
|
const CT_MODE_PER_INSTANCE = 3;
|
|
47
48
|
const CT_MODE_MATRIX = 4;
|
|
48
|
-
const MIX_RED_GREEN = [1, 0.5, 0, 0, 0.25, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]
|
|
49
|
+
const MIX_RED_GREEN = new Float32Array([1, 0.5, 0, 0, 0.25, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]);
|
|
49
50
|
|
|
50
51
|
describe('registerWgpuColorAdjustmentMaterialFeature', () => {
|
|
51
52
|
it('installs the fold so recorded tints drive the color-adjustment state machine', async () => {
|
|
@@ -118,16 +119,16 @@ describe('registerWgpuColorAdjustmentMaterialFeature', () => {
|
|
|
118
119
|
it('replicates a uniform tint as four bytes per instance on flush', async () => {
|
|
119
120
|
const state = await createWgpuRenderStateForTest();
|
|
120
121
|
registerWgpuColorAdjustmentMaterialFeature(state);
|
|
121
|
-
|
|
122
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
122
123
|
const runtime = getWgpuRenderStateRuntime(state);
|
|
123
124
|
const tex = {
|
|
124
125
|
[EntityRuntimeKey]: undefined,
|
|
125
126
|
bindings: new Map(),
|
|
126
127
|
mipLevelCount: 1,
|
|
127
|
-
texture: {} as
|
|
128
|
-
view: {} as
|
|
128
|
+
texture: {} as WgpuTexture,
|
|
129
|
+
view: {} as WgpuTextureView,
|
|
129
130
|
};
|
|
130
|
-
prepareWgpuQuadBatchWrite(state, tex, null, null, null,
|
|
131
|
+
prepareWgpuQuadBatchWrite(state, tex, null, null, null, standardWgpuQuadMaterialRenderer, 2);
|
|
131
132
|
recordWgpuQuadBatchColorScaleBias(state, ct(0.5), 0);
|
|
132
133
|
recordWgpuQuadBatchColorScaleBias(state, ct(0.5), 1);
|
|
133
134
|
runtime.quadBatchWriterCount = 2;
|
|
@@ -135,7 +136,7 @@ describe('registerWgpuColorAdjustmentMaterialFeature', () => {
|
|
|
135
136
|
expect(Array.from(new Uint8Array(runtime.quadBatchWriterColorTintData!.buffer, 0, 8))).toEqual([
|
|
136
137
|
128, 255, 255, 255, 128, 255, 255, 255,
|
|
137
138
|
]);
|
|
138
|
-
|
|
139
|
+
submitWgpuFrame(state);
|
|
139
140
|
});
|
|
140
141
|
|
|
141
142
|
it('records compact per-item tint data directly as one storage word', async () => {
|
|
@@ -146,9 +147,9 @@ describe('registerWgpuColorAdjustmentMaterialFeature', () => {
|
|
|
146
147
|
recordWgpuQuadBatchColorScaleBias(
|
|
147
148
|
state,
|
|
148
149
|
(() => {
|
|
149
|
-
const out = allocateEntity<any>();
|
|
150
|
+
const out = allocateEntity<any>() as any;
|
|
150
151
|
out.tint = 0x12345678;
|
|
151
|
-
return
|
|
152
|
+
return out;
|
|
152
153
|
})(),
|
|
153
154
|
1,
|
|
154
155
|
);
|
|
@@ -165,9 +166,9 @@ describe('registerWgpuColorAdjustmentMaterialFeature', () => {
|
|
|
165
166
|
recordWgpuQuadBatchColorScaleBias(
|
|
166
167
|
state,
|
|
167
168
|
(() => {
|
|
168
|
-
const out = allocateEntity<any>();
|
|
169
|
+
const out = allocateEntity<any>() as any;
|
|
169
170
|
out.tint = 0x808080ff;
|
|
170
|
-
return
|
|
171
|
+
return out;
|
|
171
172
|
})(),
|
|
172
173
|
0,
|
|
173
174
|
);
|
|
@@ -184,9 +185,9 @@ describe('registerWgpuColorAdjustmentMaterialFeature', () => {
|
|
|
184
185
|
recordWgpuQuadBatchColorScaleBias(
|
|
185
186
|
state,
|
|
186
187
|
(() => {
|
|
187
|
-
const out = allocateEntity<any>();
|
|
188
|
+
const out = allocateEntity<any>() as any;
|
|
188
189
|
out.tint = 0x808080ff;
|
|
189
|
-
return
|
|
190
|
+
return out;
|
|
190
191
|
})(),
|
|
191
192
|
0,
|
|
192
193
|
);
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import * as flightNode from '@flighthq/node/contract';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import {
|
|
3
|
+
beginWgpuScreenRenderPassForTest,
|
|
4
|
+
createWgpuRenderStateForTest,
|
|
5
|
+
getWgpuRenderStateRuntime,
|
|
6
|
+
installWgpuMock,
|
|
7
|
+
} from '@flighthq/render-wgpu/contract';
|
|
8
|
+
import type { WgpuRenderPassEncoder } from '@flighthq/render-wgpu/contract';
|
|
9
|
+
import { enableRenderRegistriesGuards, explainRenderRegistriesMisses, BatchFormat } from '@flighthq/render/contract';
|
|
10
|
+
import { RenderRegistryTable } from '@flighthq/render/contract';
|
|
11
|
+
import type { RenderProxy2D } from '@flighthq/render/contract';
|
|
5
12
|
import {
|
|
6
13
|
appendShapeBeginFill,
|
|
7
14
|
appendShapeBeginGradientFill,
|
|
@@ -9,11 +16,9 @@ import {
|
|
|
9
16
|
appendShapeRectangle,
|
|
10
17
|
createShape,
|
|
11
18
|
} from '@flighthq/shape/contract';
|
|
12
|
-
import type { RenderProxy2D } from '@flighthq/types/contract';
|
|
13
|
-
import { BatchFormat, RenderRegistry } from '@flighthq/types/contract';
|
|
14
19
|
|
|
15
|
-
import {
|
|
16
|
-
import { registerWgpuShapeRasterizer } from './wgpuShapeRasterizer';
|
|
20
|
+
import { wgpuMeshShapeRenderer, drawWgpuMeshShape } from './wgpuMeshShapeRenderer.ts';
|
|
21
|
+
import { registerWgpuShapeRasterizer } from './wgpuShapeRasterizer.ts';
|
|
17
22
|
|
|
18
23
|
beforeAll(() => installWgpuMock());
|
|
19
24
|
|
|
@@ -65,7 +70,7 @@ function makeShapeProxy(data: Record<string, unknown>, rendererData: unknown = m
|
|
|
65
70
|
} as unknown as RenderProxy2D;
|
|
66
71
|
}
|
|
67
72
|
|
|
68
|
-
function makeMeshPassSpy():
|
|
73
|
+
function makeMeshPassSpy(): WgpuRenderPassEncoder {
|
|
69
74
|
return {
|
|
70
75
|
setPipeline: vi.fn(),
|
|
71
76
|
setBindGroup: vi.fn(),
|
|
@@ -75,7 +80,7 @@ function makeMeshPassSpy(): GPURenderPassEncoder {
|
|
|
75
80
|
draw: vi.fn(),
|
|
76
81
|
drawIndexed: vi.fn(),
|
|
77
82
|
end: vi.fn(),
|
|
78
|
-
} as unknown as
|
|
83
|
+
} as unknown as WgpuRenderPassEncoder;
|
|
79
84
|
}
|
|
80
85
|
|
|
81
86
|
function gradientShape() {
|
|
@@ -86,50 +91,10 @@ function gradientShape() {
|
|
|
86
91
|
return shape;
|
|
87
92
|
}
|
|
88
93
|
|
|
89
|
-
describe('defaultWgpuMeshShapeRenderer', () => {
|
|
90
|
-
it('declares BatchFormat.Quad and the shared shape data lifecycle', () => {
|
|
91
|
-
expect(defaultWgpuMeshShapeRenderer.format).toBe(BatchFormat.Quad);
|
|
92
|
-
expect(typeof defaultWgpuMeshShapeRenderer.createData).toBe('function');
|
|
93
|
-
expect(typeof defaultWgpuMeshShapeRenderer.destroyData).toBe('function');
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('never rasterizes, even with a rasterizer registered and a fill that cannot tessellate', async () => {
|
|
97
|
-
const state = await createWgpuRenderStateForTest();
|
|
98
|
-
renderWgpuBackground(state);
|
|
99
|
-
getWgpuRenderStateRuntime(state).renderPass = makeMeshPassSpy();
|
|
100
|
-
const rasterizer = vi.fn();
|
|
101
|
-
registerWgpuShapeRasterizer(state, rasterizer);
|
|
102
|
-
|
|
103
|
-
defaultWgpuMeshShapeRenderer.submit!(
|
|
104
|
-
state,
|
|
105
|
-
makeShapeProxy({ commands: gradientShape().data.commands, version: 1 }),
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
expect(rasterizer).not.toHaveBeenCalled();
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('reports a ShapeRasterizer miss rather than silently dropping an untessellatable fill', async () => {
|
|
112
|
-
const state = await createWgpuRenderStateForTest();
|
|
113
|
-
renderWgpuBackground(state);
|
|
114
|
-
getWgpuRenderStateRuntime(state).renderPass = makeMeshPassSpy();
|
|
115
|
-
enableRenderRegistryGuards(state);
|
|
116
|
-
|
|
117
|
-
defaultWgpuMeshShapeRenderer.submit!(
|
|
118
|
-
state,
|
|
119
|
-
makeShapeProxy({ commands: gradientShape().data.commands, version: 1 }),
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
expect(explainRenderRegistryMisses(state).misses).toContainEqual({
|
|
123
|
-
kind: 'Shape',
|
|
124
|
-
registry: RenderRegistry.ShapeRasterizer,
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
94
|
describe('drawWgpuMeshShape', () => {
|
|
130
95
|
it('draws a solid fill as a GPU mesh and reports that it drew', async () => {
|
|
131
96
|
const state = await createWgpuRenderStateForTest();
|
|
132
|
-
|
|
97
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
133
98
|
const pass = makeMeshPassSpy();
|
|
134
99
|
getWgpuRenderStateRuntime(state).renderPass = pass;
|
|
135
100
|
const shape = createShape();
|
|
@@ -143,7 +108,7 @@ describe('drawWgpuMeshShape', () => {
|
|
|
143
108
|
|
|
144
109
|
it('reports false for a fill with no tessellated form, which is the hybrid fall-through signal', async () => {
|
|
145
110
|
const state = await createWgpuRenderStateForTest();
|
|
146
|
-
|
|
111
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
147
112
|
getWgpuRenderStateRuntime(state).renderPass = makeMeshPassSpy();
|
|
148
113
|
expect(drawWgpuMeshShape(state, makeShapeProxy({ commands: gradientShape().data.commands, version: 1 }))).toBe(
|
|
149
114
|
false,
|
|
@@ -152,7 +117,7 @@ describe('drawWgpuMeshShape', () => {
|
|
|
152
117
|
|
|
153
118
|
it('reports false with no render pass, an empty command list, or absent renderer data', async () => {
|
|
154
119
|
const state = await createWgpuRenderStateForTest();
|
|
155
|
-
|
|
120
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
156
121
|
const shape = createShape();
|
|
157
122
|
appendShapeBeginFill(shape, 0x00cc00ff);
|
|
158
123
|
appendShapeRectangle(shape, 8, 8, 32, 24);
|
|
@@ -165,3 +130,37 @@ describe('drawWgpuMeshShape', () => {
|
|
|
165
130
|
expect(drawWgpuMeshShape(state, makeShapeProxy({ commands: shape.data.commands, version: 1 }, null))).toBe(false);
|
|
166
131
|
});
|
|
167
132
|
});
|
|
133
|
+
|
|
134
|
+
describe('wgpuMeshShapeRenderer', () => {
|
|
135
|
+
it('declares BatchFormat.Quad and the shared shape data lifecycle', () => {
|
|
136
|
+
expect(wgpuMeshShapeRenderer.format).toBe(BatchFormat.Quad);
|
|
137
|
+
expect(typeof wgpuMeshShapeRenderer.createData).toBe('function');
|
|
138
|
+
expect(typeof wgpuMeshShapeRenderer.destroyData).toBe('function');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('never rasterizes, even with a rasterizer registered and a fill that cannot tessellate', async () => {
|
|
142
|
+
const state = await createWgpuRenderStateForTest();
|
|
143
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
144
|
+
getWgpuRenderStateRuntime(state).renderPass = makeMeshPassSpy();
|
|
145
|
+
const rasterizer = vi.fn();
|
|
146
|
+
registerWgpuShapeRasterizer(state, rasterizer);
|
|
147
|
+
|
|
148
|
+
wgpuMeshShapeRenderer.submit!(state, makeShapeProxy({ commands: gradientShape().data.commands, version: 1 }));
|
|
149
|
+
|
|
150
|
+
expect(rasterizer).not.toHaveBeenCalled();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('reports a ShapeRasterizer miss rather than silently dropping an untessellatable fill', async () => {
|
|
154
|
+
const state = await createWgpuRenderStateForTest();
|
|
155
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
156
|
+
getWgpuRenderStateRuntime(state).renderPass = makeMeshPassSpy();
|
|
157
|
+
enableRenderRegistriesGuards(state, null);
|
|
158
|
+
|
|
159
|
+
wgpuMeshShapeRenderer.submit!(state, makeShapeProxy({ commands: gradientShape().data.commands, version: 1 }));
|
|
160
|
+
|
|
161
|
+
expect(explainRenderRegistriesMisses(state).misses).toContainEqual({
|
|
162
|
+
kind: 'Shape',
|
|
163
|
+
registry: RenderRegistryTable.ShapeRasterizer,
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
});
|
package/src/wgpuNode2D.test.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { beginWgpuScreenRenderPassForTest, submitWgpuFrame } from '@flighthq/render-wgpu/contract';
|
|
2
2
|
import { createWgpuRenderStateForTest, installWgpuMock } from '@flighthq/render-wgpu/contract';
|
|
3
3
|
import { createDisplayObject } from '@flighthq/scene2d/contract';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { wgpuScene2DRenderer, drawWgpuScene2D, renderWgpuScene2D } from './wgpuNode2D.ts';
|
|
6
6
|
|
|
7
7
|
beforeAll(() => {
|
|
8
8
|
installWgpuMock();
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
describe('defaultWgpuScene2DRenderer', () => {
|
|
12
|
-
it('has createData and draw functions', () => {
|
|
13
|
-
expect(typeof defaultWgpuScene2DRenderer.createData).toBe('function');
|
|
14
|
-
expect(typeof defaultWgpuScene2DRenderer.submit).toBe('function');
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
11
|
describe('drawWgpuScene2D', () => {
|
|
19
12
|
it('is a no-op (plain display objects have no geometry)', async () => {
|
|
20
13
|
const state = await createWgpuRenderStateForTest();
|
|
21
|
-
|
|
14
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
22
15
|
const renderProxy = { source: createDisplayObject() } as never;
|
|
23
16
|
expect(() => drawWgpuScene2D(state, renderProxy)).not.toThrow();
|
|
24
|
-
|
|
17
|
+
submitWgpuFrame(state);
|
|
25
18
|
});
|
|
26
19
|
});
|
|
27
20
|
|
|
28
21
|
describe('renderWgpuScene2D', () => {
|
|
29
22
|
it('traverses a display object without error', async () => {
|
|
30
23
|
const state = await createWgpuRenderStateForTest();
|
|
31
|
-
|
|
24
|
+
const pass = beginWgpuScreenRenderPassForTest(state);
|
|
32
25
|
const root = createDisplayObject();
|
|
33
|
-
expect(() => renderWgpuScene2D(
|
|
34
|
-
|
|
26
|
+
expect(() => renderWgpuScene2D(pass, root)).not.toThrow();
|
|
27
|
+
submitWgpuFrame(state);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('wgpuScene2DRenderer', () => {
|
|
32
|
+
it('has createData and draw functions', () => {
|
|
33
|
+
expect(typeof wgpuScene2DRenderer.createData).toBe('function');
|
|
34
|
+
expect(typeof wgpuScene2DRenderer.submit).toBe('function');
|
|
35
35
|
});
|
|
36
36
|
});
|
|
@@ -1,57 +1,60 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EntityRuntimeKey } from '@flighthq/entity/contract';
|
|
2
|
+
import {
|
|
3
|
+
createImageResource,
|
|
4
|
+
registerTestImageDimensionResolver,
|
|
5
|
+
unregisterTestImageDimensionResolver,
|
|
6
|
+
} from '@flighthq/image/contract';
|
|
7
|
+
import type { CompressedImageResource } from '@flighthq/image/contract';
|
|
2
8
|
import { createParticleEmitter2D } from '@flighthq/particleemitter/contract';
|
|
3
9
|
import {
|
|
10
|
+
WgpuTextureUsage,
|
|
11
|
+
beginWgpuScreenRenderPassForTest,
|
|
4
12
|
getWgpuRenderStateRuntime,
|
|
5
13
|
registerWgpuCompressedImageTextureResolver,
|
|
6
14
|
registerWgpuImageTextureResolver,
|
|
7
|
-
|
|
8
|
-
submitWgpuRenderPass,
|
|
15
|
+
submitWgpuFrame,
|
|
9
16
|
} from '@flighthq/render-wgpu/contract';
|
|
10
17
|
import { createWgpuRenderStateForTest, installWgpuMock } from '@flighthq/render-wgpu/contract';
|
|
11
18
|
import { getRenderProxy2D, prepareScene2DRender } from '@flighthq/render/contract';
|
|
19
|
+
import type { RenderProxy2D } from '@flighthq/render/contract';
|
|
12
20
|
import { createTexture } from '@flighthq/texture/contract';
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
CompressedImageTextureSourceKind,
|
|
16
|
-
EntityRuntimeKey,
|
|
17
|
-
RegistryEntryState,
|
|
18
|
-
TextureAtlasRotation,
|
|
19
|
-
} from '@flighthq/types/contract';
|
|
21
|
+
import { CompressedImageTextureSourceKind } from '@flighthq/texture/contract';
|
|
22
|
+
import { TextureAtlasRotation } from '@flighthq/textureatlas/contract';
|
|
20
23
|
|
|
21
|
-
import {
|
|
24
|
+
import { wgpuParticleEmitter2DRenderer, drawWgpuParticleEmitter2D } from './wgpuParticleEmitter2D.ts';
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
// A test that wraps a host handle supplies the host: the resource measures through the registered
|
|
27
|
+
// resolver, and clearing after each test keeps this file from covering for another's missing one.
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
registerTestImageDimensionResolver();
|
|
25
30
|
});
|
|
26
31
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
unregisterTestImageDimensionResolver();
|
|
34
|
+
});
|
|
31
35
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
36
|
+
beforeAll(() => {
|
|
37
|
+
installWgpuMock();
|
|
35
38
|
});
|
|
36
39
|
|
|
37
40
|
describe('drawWgpuParticleEmitter2D', () => {
|
|
38
41
|
it('does not throw when atlas is null', async () => {
|
|
39
42
|
const state = await createWgpuRenderStateForTest();
|
|
40
|
-
|
|
43
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
41
44
|
|
|
42
45
|
const emitter = createParticleEmitter2D();
|
|
43
46
|
prepareScene2DRender(state, emitter);
|
|
44
47
|
const renderProxy = getRenderProxy2D(state, emitter)!;
|
|
45
48
|
|
|
46
49
|
expect(() => drawWgpuParticleEmitter2D(state, renderProxy)).not.toThrow();
|
|
47
|
-
|
|
50
|
+
submitWgpuFrame(state);
|
|
48
51
|
});
|
|
49
52
|
|
|
50
53
|
it('threads a native compressed atlas straight-alpha flag through the particle uniform', async () => {
|
|
51
54
|
const state = await createWgpuRenderStateForTest();
|
|
52
55
|
const runtime = getWgpuRenderStateRuntime(state);
|
|
53
56
|
registerWgpuCompressedImageTextureResolver(state);
|
|
54
|
-
|
|
57
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
55
58
|
const before = runtime.uniformOffset;
|
|
56
59
|
const image = {
|
|
57
60
|
compressed: { container: {}, payload: new Uint8Array() },
|
|
@@ -60,27 +63,21 @@ describe('drawWgpuParticleEmitter2D', () => {
|
|
|
60
63
|
version: 1,
|
|
61
64
|
width: 4,
|
|
62
65
|
} as unknown as CompressedImageResource;
|
|
63
|
-
runtime.registries.compressedTextureUpload = {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
straightAlpha: true,
|
|
79
|
-
texture,
|
|
80
|
-
view,
|
|
81
|
-
};
|
|
82
|
-
},
|
|
83
|
-
},
|
|
66
|
+
runtime.registries.compressedTextureUpload = () => {
|
|
67
|
+
const texture = state.device.createTexture({
|
|
68
|
+
size: [4, 4],
|
|
69
|
+
format: 'bc3-rgba-unorm',
|
|
70
|
+
usage: WgpuTextureUsage.TEXTURE_BINDING,
|
|
71
|
+
});
|
|
72
|
+
const view = texture.createView();
|
|
73
|
+
return {
|
|
74
|
+
[EntityRuntimeKey]: undefined,
|
|
75
|
+
bindings: new Map(),
|
|
76
|
+
mipLevelCount: 1,
|
|
77
|
+
straightAlpha: true,
|
|
78
|
+
texture,
|
|
79
|
+
view,
|
|
80
|
+
};
|
|
84
81
|
};
|
|
85
82
|
const renderProxy = {
|
|
86
83
|
alpha: 1,
|
|
@@ -111,7 +108,7 @@ describe('drawWgpuParticleEmitter2D', () => {
|
|
|
111
108
|
const state = await createWgpuRenderStateForTest();
|
|
112
109
|
const runtime = getWgpuRenderStateRuntime(state);
|
|
113
110
|
registerWgpuImageTextureResolver(state);
|
|
114
|
-
|
|
111
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
115
112
|
const canvas = document.createElement('canvas');
|
|
116
113
|
canvas.width = 64;
|
|
117
114
|
canvas.height = 64;
|
|
@@ -154,3 +151,13 @@ describe('drawWgpuParticleEmitter2D', () => {
|
|
|
154
151
|
expect(runtime.particleInstanceData![13]).toBe(-20);
|
|
155
152
|
});
|
|
156
153
|
});
|
|
154
|
+
|
|
155
|
+
describe('wgpuParticleEmitter2DRenderer', () => {
|
|
156
|
+
it('has a createData function', () => {
|
|
157
|
+
expect(typeof wgpuParticleEmitter2DRenderer.createData).toBe('function');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('has a submit function', () => {
|
|
161
|
+
expect(typeof wgpuParticleEmitter2DRenderer.submit).toBe('function');
|
|
162
|
+
});
|
|
163
|
+
});
|
|
@@ -1,60 +1,91 @@
|
|
|
1
1
|
import { createQuadBatch, reserveQuadBatch } from '@flighthq/quadbatch/contract';
|
|
2
2
|
import {
|
|
3
|
+
beginWgpuScreenRenderPassForTest,
|
|
3
4
|
getWgpuRenderStateRuntime,
|
|
4
5
|
registerWgpuRenderTextureResolver,
|
|
5
6
|
renderIntoWgpuRenderTexture,
|
|
6
|
-
|
|
7
|
-
submitWgpuRenderPass,
|
|
7
|
+
submitWgpuFrame,
|
|
8
8
|
} from '@flighthq/render-wgpu/contract';
|
|
9
9
|
import { createWgpuRenderStateForTest, installWgpuMock } from '@flighthq/render-wgpu/contract';
|
|
10
10
|
import { getOrCreateRenderProxy2D, getRenderProxy2D, prepareScene2DRender } from '@flighthq/render/contract';
|
|
11
11
|
import { createRenderTexture } from '@flighthq/texture/contract';
|
|
12
12
|
import { createTextureAtlas, createTextureAtlasRegion } from '@flighthq/textureatlas/contract';
|
|
13
|
-
import { TextureAtlasRotation } from '@flighthq/
|
|
13
|
+
import { TextureAtlasRotation } from '@flighthq/textureatlas/contract';
|
|
14
14
|
|
|
15
|
-
import {
|
|
16
|
-
import { flushWgpuQuadBatchWriter } from './wgpuQuadBatchWriter';
|
|
17
|
-
import { registerWgpuStandardMaterial } from './wgpuStandardMaterial';
|
|
15
|
+
import { wgpuQuadBatchRenderer, ensureWgpuQuadBatchResources, getWgpuQuadBatchPipeline } from './wgpuQuadBatch.ts';
|
|
16
|
+
import { flushWgpuQuadBatchWriter } from './wgpuQuadBatchWriter.ts';
|
|
17
|
+
import { registerWgpuStandardMaterial } from './wgpuStandardMaterial.ts';
|
|
18
18
|
|
|
19
19
|
beforeAll(() => {
|
|
20
20
|
installWgpuMock();
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
describe('
|
|
23
|
+
describe('ensureWgpuQuadBatchResources', () => {
|
|
24
|
+
it('returns resources with bind group layouts and a pipelines WeakMap', async () => {
|
|
25
|
+
const state = await createWgpuRenderStateForTest();
|
|
26
|
+
const resources = ensureWgpuQuadBatchResources(state);
|
|
27
|
+
expect(resources.instanceBindGroupLayout).toBeDefined();
|
|
28
|
+
expect(resources.materialBindGroupLayout).toBeDefined();
|
|
29
|
+
expect(resources.basePipelineLayout).toBeDefined();
|
|
30
|
+
expect(resources.materialPipelineLayout).toBeDefined();
|
|
31
|
+
expect(resources.pipelines).toBeInstanceOf(WeakMap);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('is idempotent — returns the same resources on repeated calls', async () => {
|
|
35
|
+
const state = await createWgpuRenderStateForTest();
|
|
36
|
+
const r1 = ensureWgpuQuadBatchResources(state);
|
|
37
|
+
const r2 = ensureWgpuQuadBatchResources(state);
|
|
38
|
+
expect(r1).toBe(r2);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('getWgpuQuadBatchPipeline', () => {
|
|
43
|
+
it('creates and caches a pipeline for a given shader module', async () => {
|
|
44
|
+
const state = await createWgpuRenderStateForTest();
|
|
45
|
+
const resources = ensureWgpuQuadBatchResources(state);
|
|
46
|
+
const module = state.device.createShaderModule({ code: '' });
|
|
47
|
+
const pipeline = getWgpuQuadBatchPipeline(state, resources, module, false, null);
|
|
48
|
+
expect(pipeline).toBeDefined();
|
|
49
|
+
const pipeline2 = getWgpuQuadBatchPipeline(state, resources, module, false, null);
|
|
50
|
+
expect(pipeline2).toBe(pipeline);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe('wgpuQuadBatchRenderer', () => {
|
|
24
55
|
it('has a createData function', () => {
|
|
25
|
-
expect(typeof
|
|
56
|
+
expect(typeof wgpuQuadBatchRenderer.createData).toBe('function');
|
|
26
57
|
});
|
|
27
58
|
|
|
28
59
|
it('has a submit function', () => {
|
|
29
|
-
expect(typeof
|
|
60
|
+
expect(typeof wgpuQuadBatchRenderer.submit).toBe('function');
|
|
30
61
|
});
|
|
31
62
|
});
|
|
32
63
|
|
|
33
|
-
describe('
|
|
64
|
+
describe('wgpuQuadBatchRenderer.submit', () => {
|
|
34
65
|
it('does not throw when atlas is null', async () => {
|
|
35
66
|
const state = await createWgpuRenderStateForTest();
|
|
36
|
-
|
|
67
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
37
68
|
|
|
38
69
|
const batch = createQuadBatch();
|
|
39
70
|
prepareScene2DRender(state, batch);
|
|
40
71
|
const renderProxy = getRenderProxy2D(state, batch)!;
|
|
41
72
|
|
|
42
73
|
expect(() => {
|
|
43
|
-
|
|
74
|
+
wgpuQuadBatchRenderer.submit(state, renderProxy);
|
|
44
75
|
flushWgpuQuadBatchWriter(state as any);
|
|
45
76
|
}).not.toThrow();
|
|
46
|
-
|
|
77
|
+
submitWgpuFrame(state);
|
|
47
78
|
});
|
|
48
79
|
|
|
49
80
|
it('packs a rotated region with upright geometry and affine UV axes', async () => {
|
|
50
81
|
const state = await createWgpuRenderStateForTest();
|
|
51
|
-
|
|
82
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
52
83
|
registerWgpuRenderTextureResolver(state);
|
|
53
84
|
registerWgpuStandardMaterial(state);
|
|
54
85
|
const texture = createRenderTexture({ height: 64, width: 64 });
|
|
55
|
-
renderIntoWgpuRenderTexture(state, texture, () => {});
|
|
56
|
-
const batch =
|
|
57
|
-
data
|
|
86
|
+
renderIntoWgpuRenderTexture(state, texture, () => {}, { color: [0, 0, 0, 0], depth: 1.0, stencil: 0 });
|
|
87
|
+
const batch = ((created) => {
|
|
88
|
+
Object.assign(created.data, {
|
|
58
89
|
atlas: createTextureAtlas({
|
|
59
90
|
regions: [
|
|
60
91
|
createTextureAtlasRegion({
|
|
@@ -68,14 +99,15 @@ describe('defaultWgpuQuadBatchRenderer.submit', () => {
|
|
|
68
99
|
],
|
|
69
100
|
texture,
|
|
70
101
|
}),
|
|
71
|
-
}
|
|
72
|
-
|
|
102
|
+
});
|
|
103
|
+
return created;
|
|
104
|
+
})(createQuadBatch());
|
|
73
105
|
reserveQuadBatch(batch, 1);
|
|
74
106
|
batch.data.instanceCount = 1;
|
|
75
107
|
batch.data.ids[0] = 0;
|
|
76
108
|
prepareScene2DRender(state, batch);
|
|
77
109
|
|
|
78
|
-
|
|
110
|
+
wgpuQuadBatchRenderer.submit(state, getOrCreateRenderProxy2D(state, batch));
|
|
79
111
|
|
|
80
112
|
const data = getWgpuRenderStateRuntime(state).quadBatchWriterInstanceData;
|
|
81
113
|
expect(data[0]).toBeCloseTo(40);
|
|
@@ -86,18 +118,18 @@ describe('defaultWgpuQuadBatchRenderer.submit', () => {
|
|
|
86
118
|
expect(data[9]).toBeCloseTo(40 / 64);
|
|
87
119
|
expect(data[10]).toBeCloseTo(-20 / 64);
|
|
88
120
|
expect(data[11]).toBeCloseTo(0);
|
|
89
|
-
|
|
121
|
+
submitWgpuFrame(state);
|
|
90
122
|
});
|
|
91
123
|
|
|
92
124
|
it('packs libGDX counterclockwise regions with the opposite affine UV axes', async () => {
|
|
93
125
|
const state = await createWgpuRenderStateForTest();
|
|
94
|
-
|
|
126
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
95
127
|
registerWgpuRenderTextureResolver(state);
|
|
96
128
|
registerWgpuStandardMaterial(state);
|
|
97
129
|
const texture = createRenderTexture({ height: 64, width: 64 });
|
|
98
|
-
renderIntoWgpuRenderTexture(state, texture, () => {});
|
|
99
|
-
const batch =
|
|
100
|
-
data
|
|
130
|
+
renderIntoWgpuRenderTexture(state, texture, () => {}, { color: [0, 0, 0, 0], depth: 1.0, stencil: 0 });
|
|
131
|
+
const batch = ((created) => {
|
|
132
|
+
Object.assign(created.data, {
|
|
101
133
|
atlas: createTextureAtlas({
|
|
102
134
|
regions: [
|
|
103
135
|
createTextureAtlasRegion({
|
|
@@ -111,51 +143,21 @@ describe('defaultWgpuQuadBatchRenderer.submit', () => {
|
|
|
111
143
|
],
|
|
112
144
|
texture,
|
|
113
145
|
}),
|
|
114
|
-
}
|
|
115
|
-
|
|
146
|
+
});
|
|
147
|
+
return created;
|
|
148
|
+
})(createQuadBatch());
|
|
116
149
|
reserveQuadBatch(batch, 1);
|
|
117
150
|
batch.data.instanceCount = 1;
|
|
118
151
|
batch.data.ids[0] = 0;
|
|
119
152
|
prepareScene2DRender(state, batch);
|
|
120
153
|
|
|
121
|
-
|
|
154
|
+
wgpuQuadBatchRenderer.submit(state, getOrCreateRenderProxy2D(state, batch));
|
|
122
155
|
|
|
123
156
|
const data = getWgpuRenderStateRuntime(state).quadBatchWriterInstanceData;
|
|
124
157
|
expect(data[6]).toBeCloseTo(0);
|
|
125
158
|
expect(data[7]).toBeCloseTo(40 / 64);
|
|
126
159
|
expect(data[9]).toBeCloseTo(-40 / 64);
|
|
127
160
|
expect(data[10]).toBeCloseTo(20 / 64);
|
|
128
|
-
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe('ensureWgpuQuadBatchResources', () => {
|
|
133
|
-
it('returns resources with bind group layouts and a pipelines WeakMap', async () => {
|
|
134
|
-
const state = await createWgpuRenderStateForTest();
|
|
135
|
-
const resources = ensureWgpuQuadBatchResources(state);
|
|
136
|
-
expect(resources.instanceBindGroupLayout).toBeDefined();
|
|
137
|
-
expect(resources.materialBindGroupLayout).toBeDefined();
|
|
138
|
-
expect(resources.basePipelineLayout).toBeDefined();
|
|
139
|
-
expect(resources.materialPipelineLayout).toBeDefined();
|
|
140
|
-
expect(resources.pipelines).toBeInstanceOf(WeakMap);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('is idempotent — returns the same resources on repeated calls', async () => {
|
|
144
|
-
const state = await createWgpuRenderStateForTest();
|
|
145
|
-
const r1 = ensureWgpuQuadBatchResources(state);
|
|
146
|
-
const r2 = ensureWgpuQuadBatchResources(state);
|
|
147
|
-
expect(r1).toBe(r2);
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('getWgpuQuadBatchPipeline', () => {
|
|
152
|
-
it('creates and caches a pipeline for a given shader module', async () => {
|
|
153
|
-
const state = await createWgpuRenderStateForTest();
|
|
154
|
-
const resources = ensureWgpuQuadBatchResources(state);
|
|
155
|
-
const module = state.device.createShaderModule({ code: '' });
|
|
156
|
-
const pipeline = getWgpuQuadBatchPipeline(state, resources, module, false, null);
|
|
157
|
-
expect(pipeline).toBeDefined();
|
|
158
|
-
const pipeline2 = getWgpuQuadBatchPipeline(state, resources, module, false, null);
|
|
159
|
-
expect(pipeline2).toBe(pipeline);
|
|
161
|
+
submitWgpuFrame(state);
|
|
160
162
|
});
|
|
161
163
|
});
|