@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.
Files changed (194) hide show
  1. package/README.md +2 -2
  2. package/dist/.tsbuildinfo.contract +1 -0
  3. package/dist/.tsbuildinfo.runtime +1 -0
  4. package/dist/contract.d.ts +32 -34
  5. package/dist/contract.d.ts.map +1 -1
  6. package/dist/contract.js +32 -34
  7. package/dist/contract.js.map +1 -1
  8. package/dist/contract.scene2d-wgpu-types.d.ts +6 -0
  9. package/dist/contract.scene2d-wgpu-types.d.ts.map +1 -0
  10. package/dist/contract.scene2d-wgpu-types.js +2 -0
  11. package/dist/contract.scene2d-wgpu-types.js.map +1 -0
  12. package/dist/enableWgpuColorAdjustmentGuards.d.ts +3 -2
  13. package/dist/enableWgpuColorAdjustmentGuards.d.ts.map +1 -1
  14. package/dist/enableWgpuColorAdjustmentGuards.js +23 -14
  15. package/dist/enableWgpuColorAdjustmentGuards.js.map +1 -1
  16. package/dist/enableWgpuStrokePathTessellation.d.ts +1 -1
  17. package/dist/enableWgpuStrokePathTessellation.d.ts.map +1 -1
  18. package/dist/enableWgpuStrokePathTessellation.js +1 -6
  19. package/dist/enableWgpuStrokePathTessellation.js.map +1 -1
  20. package/dist/index.d.ts +23 -2
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +23 -2
  23. package/dist/index.js.map +1 -1
  24. package/dist/scene2DWgpuPipeline.d.ts +13 -0
  25. package/dist/scene2DWgpuPipeline.d.ts.map +1 -0
  26. package/dist/scene2DWgpuPipeline.js +59 -0
  27. package/dist/scene2DWgpuPipeline.js.map +1 -0
  28. package/dist/types/WgpuColorAdjustmentMaterialFeature.d.ts +2 -0
  29. package/dist/types/WgpuColorAdjustmentMaterialFeature.d.ts.map +1 -0
  30. package/dist/types/WgpuColorAdjustmentMaterialFeature.js +2 -0
  31. package/dist/types/WgpuColorAdjustmentMaterialFeature.js.map +1 -0
  32. package/dist/types/WgpuRenderStats.d.ts +12 -0
  33. package/dist/types/WgpuRenderStats.d.ts.map +1 -0
  34. package/dist/types/WgpuRenderStats.js +2 -0
  35. package/dist/types/WgpuRenderStats.js.map +1 -0
  36. package/dist/types/WgpuRichTextOverlay.d.ts +4 -0
  37. package/dist/types/WgpuRichTextOverlay.d.ts.map +1 -0
  38. package/dist/types/WgpuRichTextOverlay.js +2 -0
  39. package/dist/types/WgpuRichTextOverlay.js.map +1 -0
  40. package/dist/types/WgpuShapeMesh.d.ts +2 -0
  41. package/dist/types/WgpuShapeMesh.d.ts.map +1 -0
  42. package/dist/types/WgpuShapeMesh.js +2 -0
  43. package/dist/types/WgpuShapeMesh.js.map +1 -0
  44. package/dist/types/WgpuShapeRendererData.d.ts +17 -0
  45. package/dist/types/WgpuShapeRendererData.d.ts.map +1 -0
  46. package/dist/types/WgpuShapeRendererData.js +2 -0
  47. package/dist/types/WgpuShapeRendererData.js.map +1 -0
  48. package/dist/wgpuBitmapText.d.ts +2 -2
  49. package/dist/wgpuBitmapText.d.ts.map +1 -1
  50. package/dist/wgpuBitmapText.js +6 -6
  51. package/dist/wgpuBitmapText.js.map +1 -1
  52. package/dist/wgpuCache.d.ts +9 -6
  53. package/dist/wgpuCache.d.ts.map +1 -1
  54. package/dist/wgpuCache.js +17 -18
  55. package/dist/wgpuCache.js.map +1 -1
  56. package/dist/wgpuClip.d.ts +1 -1
  57. package/dist/wgpuClip.d.ts.map +1 -1
  58. package/dist/wgpuClip.js +2 -2
  59. package/dist/wgpuClip.js.map +1 -1
  60. package/dist/wgpuClipContours.d.ts +3 -1
  61. package/dist/wgpuClipContours.d.ts.map +1 -1
  62. package/dist/wgpuClipContours.js +7 -8
  63. package/dist/wgpuClipContours.js.map +1 -1
  64. package/dist/wgpuClipRectangle.d.ts +2 -1
  65. package/dist/wgpuClipRectangle.d.ts.map +1 -1
  66. package/dist/wgpuClipRectangle.js +4 -5
  67. package/dist/wgpuClipRectangle.js.map +1 -1
  68. package/dist/wgpuColorAdjustmentMaterialFeature.d.ts +1 -1
  69. package/dist/wgpuColorAdjustmentMaterialFeature.d.ts.map +1 -1
  70. package/dist/wgpuColorAdjustmentMaterialFeature.js +9 -13
  71. package/dist/wgpuColorAdjustmentMaterialFeature.js.map +1 -1
  72. package/dist/wgpuMeshShapeRenderer.d.ts +3 -2
  73. package/dist/wgpuMeshShapeRenderer.d.ts.map +1 -1
  74. package/dist/wgpuMeshShapeRenderer.js +9 -8
  75. package/dist/wgpuMeshShapeRenderer.js.map +1 -1
  76. package/dist/wgpuNode2D.d.ts +6 -3
  77. package/dist/wgpuNode2D.d.ts.map +1 -1
  78. package/dist/wgpuNode2D.js +20 -4
  79. package/dist/wgpuNode2D.js.map +1 -1
  80. package/dist/wgpuParticleEmitter2D.d.ts +4 -2
  81. package/dist/wgpuParticleEmitter2D.d.ts.map +1 -1
  82. package/dist/wgpuParticleEmitter2D.js +8 -8
  83. package/dist/wgpuParticleEmitter2D.js.map +1 -1
  84. package/dist/wgpuQuadBatch.d.ts +3 -3
  85. package/dist/wgpuQuadBatch.d.ts.map +1 -1
  86. package/dist/wgpuQuadBatch.js +6 -6
  87. package/dist/wgpuQuadBatch.js.map +1 -1
  88. package/dist/wgpuQuadBatchWriter.d.ts +9 -5
  89. package/dist/wgpuQuadBatchWriter.d.ts.map +1 -1
  90. package/dist/wgpuQuadBatchWriter.js +12 -8
  91. package/dist/wgpuQuadBatchWriter.js.map +1 -1
  92. package/dist/wgpuRasterShapeRenderer.d.ts +3 -2
  93. package/dist/wgpuRasterShapeRenderer.d.ts.map +1 -1
  94. package/dist/wgpuRasterShapeRenderer.js +41 -22
  95. package/dist/wgpuRasterShapeRenderer.js.map +1 -1
  96. package/dist/wgpuRenderStats.d.ts +2 -1
  97. package/dist/wgpuRenderStats.d.ts.map +1 -1
  98. package/dist/wgpuRenderStats.js.map +1 -1
  99. package/dist/wgpuRendererData.d.ts +2 -1
  100. package/dist/wgpuRendererData.d.ts.map +1 -1
  101. package/dist/wgpuRendererData.js +1 -1
  102. package/dist/wgpuRendererData.js.map +1 -1
  103. package/dist/wgpuRichText.d.ts +6 -3
  104. package/dist/wgpuRichText.d.ts.map +1 -1
  105. package/dist/wgpuRichText.js +67 -34
  106. package/dist/wgpuRichText.js.map +1 -1
  107. package/dist/wgpuScale9Mapper.d.ts +2 -1
  108. package/dist/wgpuScale9Mapper.d.ts.map +1 -1
  109. package/dist/wgpuScale9Mapper.js.map +1 -1
  110. package/dist/wgpuScale9Shape.d.ts +10 -5
  111. package/dist/wgpuScale9Shape.d.ts.map +1 -1
  112. package/dist/wgpuScale9Shape.js +54 -28
  113. package/dist/wgpuScale9Shape.js.map +1 -1
  114. package/dist/wgpuScale9Sprite.d.ts +3 -2
  115. package/dist/wgpuScale9Sprite.d.ts.map +1 -1
  116. package/dist/wgpuScale9Sprite.js +9 -10
  117. package/dist/wgpuScale9Sprite.js.map +1 -1
  118. package/dist/wgpuShape.d.ts +4 -3
  119. package/dist/wgpuShape.d.ts.map +1 -1
  120. package/dist/wgpuShape.js +7 -7
  121. package/dist/wgpuShape.js.map +1 -1
  122. package/dist/wgpuShapeData.d.ts +8 -3
  123. package/dist/wgpuShapeData.d.ts.map +1 -1
  124. package/dist/wgpuShapeData.js +12 -9
  125. package/dist/wgpuShapeData.js.map +1 -1
  126. package/dist/wgpuShapeMesh.d.ts +4 -2
  127. package/dist/wgpuShapeMesh.d.ts.map +1 -1
  128. package/dist/wgpuShapeMesh.js +9 -8
  129. package/dist/wgpuShapeMesh.js.map +1 -1
  130. package/dist/wgpuShapeRasterizer.d.ts +2 -1
  131. package/dist/wgpuShapeRasterizer.d.ts.map +1 -1
  132. package/dist/wgpuShapeRasterizer.js +3 -8
  133. package/dist/wgpuShapeRasterizer.js.map +1 -1
  134. package/dist/wgpuSprite.d.ts +3 -2
  135. package/dist/wgpuSprite.d.ts.map +1 -1
  136. package/dist/wgpuSprite.js +7 -8
  137. package/dist/wgpuSprite.js.map +1 -1
  138. package/dist/wgpuStandardMaterial.d.ts +2 -2
  139. package/dist/wgpuStandardMaterial.d.ts.map +1 -1
  140. package/dist/wgpuStandardMaterial.js +5 -5
  141. package/dist/wgpuStandardMaterial.js.map +1 -1
  142. package/dist/wgpuTextInput.d.ts +2 -1
  143. package/dist/wgpuTextInput.d.ts.map +1 -1
  144. package/dist/wgpuTextInput.js +6 -7
  145. package/dist/wgpuTextInput.js.map +1 -1
  146. package/dist/wgpuTextLabel.d.ts +3 -2
  147. package/dist/wgpuTextLabel.d.ts.map +1 -1
  148. package/dist/wgpuTextLabel.js +67 -35
  149. package/dist/wgpuTextLabel.js.map +1 -1
  150. package/dist/wgpuTilemap.d.ts +2 -2
  151. package/dist/wgpuTilemap.d.ts.map +1 -1
  152. package/dist/wgpuTilemap.js +6 -6
  153. package/dist/wgpuTilemap.js.map +1 -1
  154. package/dist/wgpuVelocity.d.ts +10 -7
  155. package/dist/wgpuVelocity.d.ts.map +1 -1
  156. package/dist/wgpuVelocity.js +89 -87
  157. package/dist/wgpuVelocity.js.map +1 -1
  158. package/package.json +31 -25
  159. package/src/contract.test.ts +13 -0
  160. package/src/enableWgpuColorAdjustmentGuards.test.ts +50 -28
  161. package/src/enableWgpuStrokePathTessellation.test.ts +4 -9
  162. package/src/scene2DWgpuPipeline.test.ts +53 -0
  163. package/src/wgpuBitmapText.test.ts +10 -10
  164. package/src/wgpuCache.test.ts +130 -168
  165. package/src/wgpuClip.test.ts +1 -1
  166. package/src/wgpuClipContours.test.ts +13 -6
  167. package/src/wgpuClipRectangle.test.ts +8 -8
  168. package/src/wgpuColorAdjustmentMaterialFeature.test.ts +20 -19
  169. package/src/wgpuMeshShapeRenderer.test.ts +51 -52
  170. package/src/wgpuNode2D.test.ts +14 -14
  171. package/src/wgpuParticleEmitter2D.test.ts +52 -45
  172. package/src/wgpuQuadBatch.test.ts +62 -60
  173. package/src/wgpuQuadBatchWriter.test.ts +76 -34
  174. package/src/wgpuRasterShapeRenderer.test.ts +95 -57
  175. package/src/wgpuRenderStats.test.ts +1 -1
  176. package/src/wgpuRendererData.test.ts +2 -2
  177. package/src/wgpuRichText.test.ts +109 -58
  178. package/src/wgpuScale9Mapper.test.ts +1 -1
  179. package/src/wgpuScale9Shape.test.ts +103 -62
  180. package/src/wgpuScale9Sprite.test.ts +31 -36
  181. package/src/wgpuShape.test.ts +111 -76
  182. package/src/wgpuShapeData.test.ts +96 -53
  183. package/src/wgpuShapeMesh.test.ts +39 -25
  184. package/src/wgpuShapeRasterizer.test.ts +11 -7
  185. package/src/wgpuSprite.test.ts +36 -27
  186. package/src/wgpuStandardMaterial.test.ts +9 -13
  187. package/src/wgpuTextInput.test.ts +9 -6
  188. package/src/wgpuTextLabel.test.ts +145 -88
  189. package/src/wgpuTilemap.test.ts +11 -11
  190. package/src/wgpuVelocity.test.ts +86 -86
  191. package/dist/scene2dWgpuPipeline.d.ts +0 -3
  192. package/dist/scene2dWgpuPipeline.d.ts.map +0 -1
  193. package/dist/scene2dWgpuPipeline.js +0 -40
  194. package/dist/scene2dWgpuPipeline.js.map +0 -1
@@ -1,18 +1,19 @@
1
- import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
2
- import { renderWgpuBackground, submitWgpuRenderPass } from '@flighthq/render-wgpu/contract';
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 { standardWgpuMaterialRenderer } from './wgpuStandardMaterial';
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] as const;
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
- renderWgpuBackground(state);
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 GPUTexture,
128
- view: {} as GPUTextureView,
128
+ texture: {} as WgpuTexture,
129
+ view: {} as WgpuTextureView,
129
130
  };
130
- prepareWgpuQuadBatchWrite(state, tex, null, null, null, standardWgpuMaterialRenderer, 2);
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
- submitWgpuRenderPass(state);
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 finishEntity(out);
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 finishEntity(out);
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 finishEntity(out);
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 { getWgpuRenderStateRuntime } from '@flighthq/render-wgpu/contract';
3
- import { createWgpuRenderStateForTest, installWgpuMock, renderWgpuBackground } from '@flighthq/render-wgpu/contract';
4
- import { enableRenderRegistryGuards, explainRenderRegistryMisses } from '@flighthq/render/contract';
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 { defaultWgpuMeshShapeRenderer, drawWgpuMeshShape } from './wgpuMeshShapeRenderer';
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(): GPURenderPassEncoder {
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 GPURenderPassEncoder;
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
- renderWgpuBackground(state);
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
- renderWgpuBackground(state);
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
- renderWgpuBackground(state);
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
+ });
@@ -1,36 +1,36 @@
1
- import { renderWgpuBackground, submitWgpuRenderPass } from '@flighthq/render-wgpu/contract';
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 { defaultWgpuScene2DRenderer, drawWgpuScene2D, renderWgpuScene2D } from './wgpuNode2D';
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
- renderWgpuBackground(state);
14
+ beginWgpuScreenRenderPassForTest(state);
22
15
  const renderProxy = { source: createDisplayObject() } as never;
23
16
  expect(() => drawWgpuScene2D(state, renderProxy)).not.toThrow();
24
- submitWgpuRenderPass(state);
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
- renderWgpuBackground(state);
24
+ const pass = beginWgpuScreenRenderPassForTest(state);
32
25
  const root = createDisplayObject();
33
- expect(() => renderWgpuScene2D(state, root)).not.toThrow();
34
- submitWgpuRenderPass(state);
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 { createImageResource } from '@flighthq/image/contract';
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
- renderWgpuBackground,
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 type { CompressedImageResource, RenderProxy2D } from '@flighthq/types/contract';
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 { defaultWgpuParticleEmitter2DRenderer, drawWgpuParticleEmitter2D } from './wgpuParticleEmitter2D';
24
+ import { wgpuParticleEmitter2DRenderer, drawWgpuParticleEmitter2D } from './wgpuParticleEmitter2D.ts';
22
25
 
23
- beforeAll(() => {
24
- installWgpuMock();
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
- describe('defaultWgpuParticleEmitter2DRenderer', () => {
28
- it('has a createData function', () => {
29
- expect(typeof defaultWgpuParticleEmitter2DRenderer.createData).toBe('function');
30
- });
32
+ afterEach(() => {
33
+ unregisterTestImageDimensionResolver();
34
+ });
31
35
 
32
- it('has a submit function', () => {
33
- expect(typeof defaultWgpuParticleEmitter2DRenderer.submit).toBe('function');
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
- renderWgpuBackground(state);
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
- submitWgpuRenderPass(state);
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
- renderWgpuBackground(state);
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
- ...runtime.registries.compressedTextureUpload,
65
- entry: {
66
- state: RegistryEntryState.Bound,
67
- value: () => {
68
- const texture = state.device.createTexture({
69
- size: [4, 4],
70
- format: 'bc3-rgba-unorm',
71
- usage: GPUTextureUsage.TEXTURE_BINDING,
72
- });
73
- const view = texture.createView();
74
- return {
75
- [EntityRuntimeKey]: undefined,
76
- bindings: new Map(),
77
- mipLevelCount: 1,
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
- renderWgpuBackground(state);
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
- renderWgpuBackground,
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/types/contract';
13
+ import { TextureAtlasRotation } from '@flighthq/textureatlas/contract';
14
14
 
15
- import { defaultWgpuQuadBatchRenderer, ensureWgpuQuadBatchResources, getWgpuQuadBatchPipeline } from './wgpuQuadBatch';
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('defaultWgpuQuadBatchRenderer', () => {
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 defaultWgpuQuadBatchRenderer.createData).toBe('function');
56
+ expect(typeof wgpuQuadBatchRenderer.createData).toBe('function');
26
57
  });
27
58
 
28
59
  it('has a submit function', () => {
29
- expect(typeof defaultWgpuQuadBatchRenderer.submit).toBe('function');
60
+ expect(typeof wgpuQuadBatchRenderer.submit).toBe('function');
30
61
  });
31
62
  });
32
63
 
33
- describe('defaultWgpuQuadBatchRenderer.submit', () => {
64
+ describe('wgpuQuadBatchRenderer.submit', () => {
34
65
  it('does not throw when atlas is null', async () => {
35
66
  const state = await createWgpuRenderStateForTest();
36
- renderWgpuBackground(state);
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
- defaultWgpuQuadBatchRenderer.submit(state, renderProxy);
74
+ wgpuQuadBatchRenderer.submit(state, renderProxy);
44
75
  flushWgpuQuadBatchWriter(state as any);
45
76
  }).not.toThrow();
46
- submitWgpuRenderPass(state);
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
- renderWgpuBackground(state);
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 = createQuadBatch({
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
- defaultWgpuQuadBatchRenderer.submit(state, getOrCreateRenderProxy2D(state, batch));
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
- submitWgpuRenderPass(state);
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
- renderWgpuBackground(state);
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 = createQuadBatch({
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
- defaultWgpuQuadBatchRenderer.submit(state, getOrCreateRenderProxy2D(state, batch));
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
- submitWgpuRenderPass(state);
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
  });