@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.
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 +20 -19
  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 +26 -14
  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 +29 -25
  87. package/dist/wgpuQuadBatch.js.map +1 -1
  88. package/dist/wgpuQuadBatchWriter.d.ts +11 -5
  89. package/dist/wgpuQuadBatchWriter.d.ts.map +1 -1
  90. package/dist/wgpuQuadBatchWriter.js +45 -19
  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 +49 -35
  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 +30 -36
  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 +17 -32
  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 +68 -48
  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 +20 -19
  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 +95 -90
  157. package/dist/wgpuVelocity.js.map +1 -1
  158. package/package.json +31 -24
  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 +99 -38
  172. package/src/wgpuQuadBatch.test.ts +126 -32
  173. package/src/wgpuQuadBatchWriter.test.ts +108 -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 +38 -41
  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 +67 -24
  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,50 +1,60 @@
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';
1
8
  import { createParticleEmitter2D } from '@flighthq/particleemitter/contract';
2
9
  import {
10
+ WgpuTextureUsage,
11
+ beginWgpuScreenRenderPassForTest,
3
12
  getWgpuRenderStateRuntime,
4
13
  registerWgpuCompressedImageTextureResolver,
5
- renderWgpuBackground,
6
- submitWgpuRenderPass,
14
+ registerWgpuImageTextureResolver,
15
+ submitWgpuFrame,
7
16
  } from '@flighthq/render-wgpu/contract';
8
17
  import { createWgpuRenderStateForTest, installWgpuMock } from '@flighthq/render-wgpu/contract';
9
18
  import { getRenderProxy2D, prepareScene2DRender } from '@flighthq/render/contract';
19
+ import type { RenderProxy2D } from '@flighthq/render/contract';
10
20
  import { createTexture } from '@flighthq/texture/contract';
11
- import type { CompressedImageResource, RenderProxy2D } from '@flighthq/types/contract';
12
- import { CompressedImageTextureSourceKind, EntityRuntimeKey, RegistryEntryState } from '@flighthq/types/contract';
21
+ import { CompressedImageTextureSourceKind } from '@flighthq/texture/contract';
22
+ import { TextureAtlasRotation } from '@flighthq/textureatlas/contract';
13
23
 
14
- import { defaultWgpuParticleEmitter2DRenderer, drawWgpuParticleEmitter2D } from './wgpuParticleEmitter2D';
24
+ import { wgpuParticleEmitter2DRenderer, drawWgpuParticleEmitter2D } from './wgpuParticleEmitter2D.ts';
15
25
 
16
- beforeAll(() => {
17
- 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();
18
30
  });
19
31
 
20
- describe('defaultWgpuParticleEmitter2DRenderer', () => {
21
- it('has a createData function', () => {
22
- expect(typeof defaultWgpuParticleEmitter2DRenderer.createData).toBe('function');
23
- });
32
+ afterEach(() => {
33
+ unregisterTestImageDimensionResolver();
34
+ });
24
35
 
25
- it('has a submit function', () => {
26
- expect(typeof defaultWgpuParticleEmitter2DRenderer.submit).toBe('function');
27
- });
36
+ beforeAll(() => {
37
+ installWgpuMock();
28
38
  });
29
39
 
30
40
  describe('drawWgpuParticleEmitter2D', () => {
31
41
  it('does not throw when atlas is null', async () => {
32
42
  const state = await createWgpuRenderStateForTest();
33
- renderWgpuBackground(state);
43
+ beginWgpuScreenRenderPassForTest(state);
34
44
 
35
45
  const emitter = createParticleEmitter2D();
36
46
  prepareScene2DRender(state, emitter);
37
47
  const renderProxy = getRenderProxy2D(state, emitter)!;
38
48
 
39
49
  expect(() => drawWgpuParticleEmitter2D(state, renderProxy)).not.toThrow();
40
- submitWgpuRenderPass(state);
50
+ submitWgpuFrame(state);
41
51
  });
42
52
 
43
53
  it('threads a native compressed atlas straight-alpha flag through the particle uniform', async () => {
44
54
  const state = await createWgpuRenderStateForTest();
45
55
  const runtime = getWgpuRenderStateRuntime(state);
46
56
  registerWgpuCompressedImageTextureResolver(state);
47
- renderWgpuBackground(state);
57
+ beginWgpuScreenRenderPassForTest(state);
48
58
  const before = runtime.uniformOffset;
49
59
  const image = {
50
60
  compressed: { container: {}, payload: new Uint8Array() },
@@ -53,27 +63,21 @@ describe('drawWgpuParticleEmitter2D', () => {
53
63
  version: 1,
54
64
  width: 4,
55
65
  } as unknown as CompressedImageResource;
56
- runtime.registries.compressedTextureUpload = {
57
- ...runtime.registries.compressedTextureUpload,
58
- entry: {
59
- state: RegistryEntryState.Bound,
60
- value: () => {
61
- const texture = state.device.createTexture({
62
- size: [4, 4],
63
- format: 'bc3-rgba-unorm',
64
- usage: GPUTextureUsage.TEXTURE_BINDING,
65
- });
66
- const view = texture.createView();
67
- return {
68
- [EntityRuntimeKey]: undefined,
69
- bindings: new Map(),
70
- mipLevelCount: 1,
71
- straightAlpha: true,
72
- texture,
73
- view,
74
- };
75
- },
76
- },
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
+ };
77
81
  };
78
82
  const renderProxy = {
79
83
  alpha: 1,
@@ -99,4 +103,61 @@ describe('drawWgpuParticleEmitter2D', () => {
99
103
 
100
104
  expect(runtime.uniformDataU32[(before >> 2) + 14]).toBe(1);
101
105
  });
106
+
107
+ it('packs a rotated region at its upright logical size without growing the instance record', async () => {
108
+ const state = await createWgpuRenderStateForTest();
109
+ const runtime = getWgpuRenderStateRuntime(state);
110
+ registerWgpuImageTextureResolver(state);
111
+ beginWgpuScreenRenderPassForTest(state);
112
+ const canvas = document.createElement('canvas');
113
+ canvas.width = 64;
114
+ canvas.height = 64;
115
+ const region: {
116
+ height: number;
117
+ id: number;
118
+ rotation: TextureAtlasRotation;
119
+ width: number;
120
+ x: number;
121
+ y: number;
122
+ } = { height: 40, id: 0, rotation: TextureAtlasRotation.Clockwise90, width: 20, x: 0, y: 0 };
123
+ const renderProxy = {
124
+ alpha: 1,
125
+ blendMode: null,
126
+ source: {
127
+ data: {
128
+ alphas: new Float32Array([1]),
129
+ atlas: {
130
+ regions: [region],
131
+ texture: createTexture({ dimension: '2d', source: createImageResource(canvas) }),
132
+ },
133
+ colors: new Float32Array([1, 1, 1]),
134
+ ids: new Uint16Array([0]),
135
+ particleCount: 1,
136
+ transforms: new Float32Array([0, 0, 0, 1]),
137
+ worldSpace: false,
138
+ },
139
+ },
140
+ transform2D: { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 },
141
+ } as unknown as RenderProxy2D;
142
+
143
+ drawWgpuParticleEmitter2D(state, renderProxy);
144
+
145
+ expect(runtime.particleInstanceData![12]).toBe(-40);
146
+ expect(runtime.particleInstanceData![13]).toBe(20);
147
+
148
+ region.rotation = TextureAtlasRotation.Counterclockwise90;
149
+ drawWgpuParticleEmitter2D(state, renderProxy);
150
+ expect(runtime.particleInstanceData![12]).toBe(40);
151
+ expect(runtime.particleInstanceData![13]).toBe(-20);
152
+ });
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
+ });
102
163
  });
@@ -1,42 +1,25 @@
1
- import { createQuadBatch } from '@flighthq/quadbatch/contract';
2
- import { renderWgpuBackground, submitWgpuRenderPass } from '@flighthq/render-wgpu/contract';
1
+ import { createQuadBatch, reserveQuadBatch } from '@flighthq/quadbatch/contract';
2
+ import {
3
+ beginWgpuScreenRenderPassForTest,
4
+ getWgpuRenderStateRuntime,
5
+ registerWgpuRenderTextureResolver,
6
+ renderIntoWgpuRenderTexture,
7
+ submitWgpuFrame,
8
+ } from '@flighthq/render-wgpu/contract';
3
9
  import { createWgpuRenderStateForTest, installWgpuMock } from '@flighthq/render-wgpu/contract';
4
- import { getRenderProxy2D, prepareScene2DRender } from '@flighthq/render/contract';
10
+ import { getOrCreateRenderProxy2D, getRenderProxy2D, prepareScene2DRender } from '@flighthq/render/contract';
11
+ import { createRenderTexture } from '@flighthq/texture/contract';
12
+ import { createTextureAtlas, createTextureAtlasRegion } from '@flighthq/textureatlas/contract';
13
+ import { TextureAtlasRotation } from '@flighthq/textureatlas/contract';
5
14
 
6
- import { defaultWgpuQuadBatchRenderer, ensureWgpuQuadBatchResources, getWgpuQuadBatchPipeline } from './wgpuQuadBatch';
7
- import { flushWgpuQuadBatchWriter } from './wgpuQuadBatchWriter';
15
+ import { wgpuQuadBatchRenderer, ensureWgpuQuadBatchResources, getWgpuQuadBatchPipeline } from './wgpuQuadBatch.ts';
16
+ import { flushWgpuQuadBatchWriter } from './wgpuQuadBatchWriter.ts';
17
+ import { registerWgpuStandardMaterial } from './wgpuStandardMaterial.ts';
8
18
 
9
19
  beforeAll(() => {
10
20
  installWgpuMock();
11
21
  });
12
22
 
13
- describe('defaultWgpuQuadBatchRenderer', () => {
14
- it('has a createData function', () => {
15
- expect(typeof defaultWgpuQuadBatchRenderer.createData).toBe('function');
16
- });
17
-
18
- it('has a submit function', () => {
19
- expect(typeof defaultWgpuQuadBatchRenderer.submit).toBe('function');
20
- });
21
- });
22
-
23
- describe('defaultWgpuQuadBatchRenderer.submit', () => {
24
- it('does not throw when atlas is null', async () => {
25
- const state = await createWgpuRenderStateForTest();
26
- renderWgpuBackground(state);
27
-
28
- const batch = createQuadBatch();
29
- prepareScene2DRender(state, batch);
30
- const renderProxy = getRenderProxy2D(state, batch)!;
31
-
32
- expect(() => {
33
- defaultWgpuQuadBatchRenderer.submit(state, renderProxy);
34
- flushWgpuQuadBatchWriter(state as any);
35
- }).not.toThrow();
36
- submitWgpuRenderPass(state);
37
- });
38
- });
39
-
40
23
  describe('ensureWgpuQuadBatchResources', () => {
41
24
  it('returns resources with bind group layouts and a pipelines WeakMap', async () => {
42
25
  const state = await createWgpuRenderStateForTest();
@@ -67,3 +50,114 @@ describe('getWgpuQuadBatchPipeline', () => {
67
50
  expect(pipeline2).toBe(pipeline);
68
51
  });
69
52
  });
53
+
54
+ describe('wgpuQuadBatchRenderer', () => {
55
+ it('has a createData function', () => {
56
+ expect(typeof wgpuQuadBatchRenderer.createData).toBe('function');
57
+ });
58
+
59
+ it('has a submit function', () => {
60
+ expect(typeof wgpuQuadBatchRenderer.submit).toBe('function');
61
+ });
62
+ });
63
+
64
+ describe('wgpuQuadBatchRenderer.submit', () => {
65
+ it('does not throw when atlas is null', async () => {
66
+ const state = await createWgpuRenderStateForTest();
67
+ beginWgpuScreenRenderPassForTest(state);
68
+
69
+ const batch = createQuadBatch();
70
+ prepareScene2DRender(state, batch);
71
+ const renderProxy = getRenderProxy2D(state, batch)!;
72
+
73
+ expect(() => {
74
+ wgpuQuadBatchRenderer.submit(state, renderProxy);
75
+ flushWgpuQuadBatchWriter(state as any);
76
+ }).not.toThrow();
77
+ submitWgpuFrame(state);
78
+ });
79
+
80
+ it('packs a rotated region with upright geometry and affine UV axes', async () => {
81
+ const state = await createWgpuRenderStateForTest();
82
+ beginWgpuScreenRenderPassForTest(state);
83
+ registerWgpuRenderTextureResolver(state);
84
+ registerWgpuStandardMaterial(state);
85
+ const texture = createRenderTexture({ height: 64, width: 64 });
86
+ renderIntoWgpuRenderTexture(state, texture, () => {}, { color: [0, 0, 0, 0], depth: 1.0, stencil: 0 });
87
+ const batch = ((created) => {
88
+ Object.assign(created.data, {
89
+ atlas: createTextureAtlas({
90
+ regions: [
91
+ createTextureAtlasRegion({
92
+ height: 40,
93
+ id: 0,
94
+ rotation: TextureAtlasRotation.Clockwise90,
95
+ width: 20,
96
+ x: 0,
97
+ y: 0,
98
+ }),
99
+ ],
100
+ texture,
101
+ }),
102
+ });
103
+ return created;
104
+ })(createQuadBatch());
105
+ reserveQuadBatch(batch, 1);
106
+ batch.data.instanceCount = 1;
107
+ batch.data.ids[0] = 0;
108
+ prepareScene2DRender(state, batch);
109
+
110
+ wgpuQuadBatchRenderer.submit(state, getOrCreateRenderProxy2D(state, batch));
111
+
112
+ const data = getWgpuRenderStateRuntime(state).quadBatchWriterInstanceData;
113
+ expect(data[0]).toBeCloseTo(40);
114
+ expect(data[3]).toBeCloseTo(20);
115
+ expect(data[6]).toBeCloseTo(20 / 64);
116
+ expect(data[7]).toBeCloseTo(0);
117
+ expect(data[8]).toBeCloseTo(0);
118
+ expect(data[9]).toBeCloseTo(40 / 64);
119
+ expect(data[10]).toBeCloseTo(-20 / 64);
120
+ expect(data[11]).toBeCloseTo(0);
121
+ submitWgpuFrame(state);
122
+ });
123
+
124
+ it('packs libGDX counterclockwise regions with the opposite affine UV axes', async () => {
125
+ const state = await createWgpuRenderStateForTest();
126
+ beginWgpuScreenRenderPassForTest(state);
127
+ registerWgpuRenderTextureResolver(state);
128
+ registerWgpuStandardMaterial(state);
129
+ const texture = createRenderTexture({ height: 64, width: 64 });
130
+ renderIntoWgpuRenderTexture(state, texture, () => {}, { color: [0, 0, 0, 0], depth: 1.0, stencil: 0 });
131
+ const batch = ((created) => {
132
+ Object.assign(created.data, {
133
+ atlas: createTextureAtlas({
134
+ regions: [
135
+ createTextureAtlasRegion({
136
+ height: 40,
137
+ id: 0,
138
+ rotation: TextureAtlasRotation.Counterclockwise90,
139
+ width: 20,
140
+ x: 0,
141
+ y: 0,
142
+ }),
143
+ ],
144
+ texture,
145
+ }),
146
+ });
147
+ return created;
148
+ })(createQuadBatch());
149
+ reserveQuadBatch(batch, 1);
150
+ batch.data.instanceCount = 1;
151
+ batch.data.ids[0] = 0;
152
+ prepareScene2DRender(state, batch);
153
+
154
+ wgpuQuadBatchRenderer.submit(state, getOrCreateRenderProxy2D(state, batch));
155
+
156
+ const data = getWgpuRenderStateRuntime(state).quadBatchWriterInstanceData;
157
+ expect(data[6]).toBeCloseTo(0);
158
+ expect(data[7]).toBeCloseTo(40 / 64);
159
+ expect(data[9]).toBeCloseTo(-40 / 64);
160
+ expect(data[10]).toBeCloseTo(20 / 64);
161
+ submitWgpuFrame(state);
162
+ });
163
+ });