@flighthq/render-gl 0.3.0-next.906.07cea63 → 0.3.1-next.209.43ef1bc

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 (112) hide show
  1. package/dist/contract.d.ts +5 -0
  2. package/dist/contract.d.ts.map +1 -1
  3. package/dist/contract.js +5 -0
  4. package/dist/contract.js.map +1 -1
  5. package/dist/enableGlRenderStateGuards.d.ts +4 -0
  6. package/dist/enableGlRenderStateGuards.d.ts.map +1 -0
  7. package/dist/enableGlRenderStateGuards.js +52 -0
  8. package/dist/enableGlRenderStateGuards.js.map +1 -0
  9. package/dist/enableGlRenderTextureGuards.d.ts.map +1 -1
  10. package/dist/enableGlRenderTextureGuards.js +2 -2
  11. package/dist/enableGlRenderTextureGuards.js.map +1 -1
  12. package/dist/enableGlTextureResolverGuards.d.ts +4 -0
  13. package/dist/enableGlTextureResolverGuards.d.ts.map +1 -0
  14. package/dist/enableGlTextureResolverGuards.js +8 -0
  15. package/dist/enableGlTextureResolverGuards.js.map +1 -0
  16. package/dist/explainGlTextureResolution.d.ts +3 -0
  17. package/dist/explainGlTextureResolution.d.ts.map +1 -0
  18. package/dist/explainGlTextureResolution.js +12 -0
  19. package/dist/explainGlTextureResolution.js.map +1 -0
  20. package/dist/glBackground.d.ts.map +1 -1
  21. package/dist/glBackground.js +5 -3
  22. package/dist/glBackground.js.map +1 -1
  23. package/dist/glCompressedTexture.d.ts +2 -2
  24. package/dist/glCompressedTexture.d.ts.map +1 -1
  25. package/dist/glCompressedTexture.js +46 -17
  26. package/dist/glCompressedTexture.js.map +1 -1
  27. package/dist/glDraw.d.ts +4 -2
  28. package/dist/glDraw.d.ts.map +1 -1
  29. package/dist/glDraw.js +100 -65
  30. package/dist/glDraw.js.map +1 -1
  31. package/dist/glExternalTexture.d.ts +4 -0
  32. package/dist/glExternalTexture.d.ts.map +1 -0
  33. package/dist/glExternalTexture.js +46 -0
  34. package/dist/glExternalTexture.js.map +1 -0
  35. package/dist/glFullscreenPass.js +5 -6
  36. package/dist/glFullscreenPass.js.map +1 -1
  37. package/dist/glLinearToSrgbPass.js +3 -3
  38. package/dist/glLinearToSrgbPass.js.map +1 -1
  39. package/dist/glMaterialRegistry.d.ts.map +1 -1
  40. package/dist/glMaterialRegistry.js +12 -10
  41. package/dist/glMaterialRegistry.js.map +1 -1
  42. package/dist/glPresentRenderTarget.js +3 -3
  43. package/dist/glPresentRenderTarget.js.map +1 -1
  44. package/dist/glRenderPass.d.ts +2 -2
  45. package/dist/glRenderPass.d.ts.map +1 -1
  46. package/dist/glRenderPass.js +193 -33
  47. package/dist/glRenderPass.js.map +1 -1
  48. package/dist/glRenderState.d.ts +11 -1
  49. package/dist/glRenderState.d.ts.map +1 -1
  50. package/dist/glRenderState.js +206 -22
  51. package/dist/glRenderState.js.map +1 -1
  52. package/dist/glRenderStateBracket.d.ts.map +1 -1
  53. package/dist/glRenderStateBracket.js +16 -4
  54. package/dist/glRenderStateBracket.js.map +1 -1
  55. package/dist/glRenderTarget.d.ts +10 -1
  56. package/dist/glRenderTarget.d.ts.map +1 -1
  57. package/dist/glRenderTarget.js +154 -69
  58. package/dist/glRenderTarget.js.map +1 -1
  59. package/dist/glRenderTargetPool.d.ts +4 -1
  60. package/dist/glRenderTargetPool.d.ts.map +1 -1
  61. package/dist/glRenderTargetPool.js +32 -23
  62. package/dist/glRenderTargetPool.js.map +1 -1
  63. package/dist/glRenderTexture.d.ts +13 -8
  64. package/dist/glRenderTexture.d.ts.map +1 -1
  65. package/dist/glRenderTexture.js +94 -37
  66. package/dist/glRenderTexture.js.map +1 -1
  67. package/dist/glRenderTexturePool.d.ts +7 -0
  68. package/dist/glRenderTexturePool.d.ts.map +1 -0
  69. package/dist/glRenderTexturePool.js +88 -0
  70. package/dist/glRenderTexturePool.js.map +1 -0
  71. package/dist/glTestHelper.d.ts.map +1 -1
  72. package/dist/glTestHelper.js +12 -8
  73. package/dist/glTestHelper.js.map +1 -1
  74. package/dist/glTextureResolver.d.ts +7 -8
  75. package/dist/glTextureResolver.d.ts.map +1 -1
  76. package/dist/glTextureResolver.js +57 -55
  77. package/dist/glTextureResolver.js.map +1 -1
  78. package/dist/glTextureUpload.d.ts +4 -4
  79. package/dist/glTextureUpload.d.ts.map +1 -1
  80. package/dist/glTextureUpload.js +8 -14
  81. package/dist/glTextureUpload.js.map +1 -1
  82. package/dist/glTextureVideoUpload.d.ts +2 -2
  83. package/dist/glTextureVideoUpload.d.ts.map +1 -1
  84. package/dist/glTextureVideoUpload.js +5 -5
  85. package/dist/glTextureVideoUpload.js.map +1 -1
  86. package/dist/index.d.ts +1 -1
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/index.js +1 -1
  89. package/dist/index.js.map +1 -1
  90. package/package.json +12 -6
  91. package/src/enableGlRenderStateGuards.test.ts +70 -0
  92. package/src/enableGlTextureResolverGuards.test.ts +58 -0
  93. package/src/explainGlTextureResolution.test.ts +32 -0
  94. package/src/glBackground.test.ts +24 -0
  95. package/src/glCompressedTexture.test.ts +7 -17
  96. package/src/glDraw.test.ts +172 -80
  97. package/src/glExternalTexture.test.ts +30 -0
  98. package/src/glFullscreenPass.test.ts +15 -2
  99. package/src/glLinearToSrgbPass.test.ts +13 -0
  100. package/src/glMaterialRegistry.test.ts +42 -1
  101. package/src/glPresentRenderTarget.test.ts +15 -1
  102. package/src/glReadback.test.ts +13 -0
  103. package/src/glRenderPass.test.ts +257 -5
  104. package/src/glRenderState.test.ts +136 -1
  105. package/src/glRenderStateBracket.test.ts +31 -1
  106. package/src/glRenderTarget.test.ts +244 -3
  107. package/src/glRenderTargetPool.test.ts +110 -5
  108. package/src/glRenderTexture.test.ts +88 -14
  109. package/src/glRenderTexturePool.test.ts +137 -0
  110. package/src/glTextureResolver.test.ts +151 -72
  111. package/src/glTextureUpload.test.ts +2 -10
  112. package/src/glTextureVideoUpload.test.ts +20 -5
@@ -1,10 +1,19 @@
1
- import type { ImageResource, SamplerLike, Texture } from '@flighthq/types/contract';
2
- import { AdvancedBlendMode, BlendMode } from '@flighthq/types/contract';
1
+ import { getTextureSource } from '@flighthq/texture/contract';
2
+ import type { Bitmap, CompressedImage, Image, SamplerLike, Texture } from '@flighthq/types/contract';
3
+ import {
4
+ AdvancedBlendMode,
5
+ BitmapTextureSourceKind,
6
+ BlendMode,
7
+ CompressedImageTextureSourceKind,
8
+ ImageTextureSourceKind,
9
+ } from '@flighthq/types/contract';
3
10
 
4
11
  import { registerGlCompressedTextureDecoder, registerGlCompressedTextureUpload } from './glCompressedTexture';
5
12
  import {
6
13
  applyGlBlendMode,
7
14
  applyGlSamplerState,
15
+ bindGlBitmapTexture,
16
+ bindGlCompressedImageTexture,
8
17
  bindGlImageResourceTexture,
9
18
  bindGlTexture,
10
19
  bindGlVideoTexture,
@@ -22,12 +31,9 @@ import { getGlRenderStateRuntime } from './glRenderState';
22
31
  import { registerGlBitmapShader } from './glShaderRegistry';
23
32
  import { createGlState } from './glTestHelper';
24
33
 
25
- // A compressed-only ImageResource (single 4×4 bc3 level, no element/data) for exercising the opt-in
26
- // compressed upload seam.
27
- function compressedBc3ImageResource(): ImageResource {
34
+ // A single 4×4 bc3 level for exercising the opt-in compressed upload seam.
35
+ function compressedBc3Image(): CompressedImage {
28
36
  return {
29
- source: null,
30
- data: null,
31
37
  compressed: {
32
38
  container: {
33
39
  format: 'bc3',
@@ -45,8 +51,21 @@ function compressedBc3ImageResource(): ImageResource {
45
51
  width: 4,
46
52
  height: 4,
47
53
  version: 1,
54
+ kind: CompressedImageTextureSourceKind,
55
+ } as unknown as CompressedImage;
56
+ }
57
+
58
+ function bitmap(size: number, version: number): Bitmap {
59
+ return {
48
60
  alphaType: 'straight',
49
- } as unknown as ImageResource;
61
+ gamut: 'srgb',
62
+ data: new Uint8ClampedArray(size * size * 4),
63
+ format: 'rgba8unorm',
64
+ height: size,
65
+ kind: BitmapTextureSourceKind,
66
+ version,
67
+ width: size,
68
+ } as unknown as Bitmap;
50
69
  }
51
70
 
52
71
  // A plain SamplerLike with the AAA sampling defaults (clamp/linear/trilinear/mips, anisotropy off),
@@ -176,82 +195,44 @@ describe('applyGlSamplerState', () => {
176
195
  });
177
196
  });
178
197
 
179
- describe('bindGlImageResourceTexture', () => {
180
- function dataResource(size: number, version: number): ImageResource {
181
- return {
182
- source: null,
183
- data: new Uint8ClampedArray(size * size * 4),
184
- width: size,
185
- height: size,
186
- version,
187
- alphaType: 'straight',
188
- } as unknown as ImageResource;
189
- }
198
+ // A 1x1 bitmap with an explicit encoding and texel, for the alpha-encoding round trip below.
199
+ function encodedBitmap(alphaType: 'straight' | 'premultiplied', rgba: readonly number[]): Bitmap {
200
+ return {
201
+ alphaType,
202
+ data: new Uint8ClampedArray(rgba),
203
+ format: 'rgba8unorm',
204
+ gamut: 'srgb',
205
+ height: 1,
206
+ kind: BitmapTextureSourceKind,
207
+ version: 1,
208
+ width: 1,
209
+ } as unknown as Bitmap;
210
+ }
190
211
 
191
- it('uploads a data-only ImageResource (a generated Surface) via the raw-pixel path', () => {
212
+ describe('bindGlBitmapTexture', () => {
213
+ it('uploads CPU-readable pixels via the raw-pixel path', () => {
192
214
  const { state, gl } = createGlState();
193
- bindGlImageResourceTexture(state, dataResource(4, 1));
215
+ bindGlBitmapTexture(state, bitmap(4, 1));
194
216
  expect(gl.createTexture).toHaveBeenCalled();
195
217
  expect(gl.texImage2D).toHaveBeenCalled();
196
218
  });
197
219
 
198
- it('uploads an element-backed ImageResource via the element path', () => {
199
- const { state, gl } = createGlState();
200
- const image = {
201
- source: document.createElement('img'),
202
- data: null,
203
- width: 1,
204
- height: 1,
205
- version: 1,
206
- alphaType: 'straight',
207
- } as unknown as ImageResource;
208
- bindGlImageResourceTexture(state, image);
209
- expect(gl.texImage2D).toHaveBeenCalled();
210
- });
211
-
212
220
  it('caches by resource identity and re-uploads only when the version changes', () => {
213
221
  const { state, gl } = createGlState();
214
- const image = dataResource(1, 1);
215
- const t1 = bindGlImageResourceTexture(state, image);
222
+ const image = bitmap(1, 1);
223
+ const t1 = bindGlBitmapTexture(state, image);
216
224
  const uploads = (gl.texImage2D as ReturnType<typeof vi.fn>).mock.calls.length;
217
- const t2 = bindGlImageResourceTexture(state, image);
225
+ const t2 = bindGlBitmapTexture(state, image);
218
226
  expect(t2).toBe(t1);
219
227
  expect((gl.texImage2D as ReturnType<typeof vi.fn>).mock.calls.length).toBe(uploads);
220
228
  image.version = 2;
221
- bindGlImageResourceTexture(state, image);
229
+ bindGlBitmapTexture(state, image);
222
230
  expect((gl.texImage2D as ReturnType<typeof vi.fn>).mock.calls.length).toBe(uploads + 1);
223
231
  });
224
232
 
225
- it('routes a compressed-only ImageResource through the registered compressed upload seam (decode fallback)', () => {
226
- // The device mock exposes no block extension, so the compressed container falls back to the
227
- // registered RGBA decoder and uploads via texImage2D — proving the real bind/draw path reaches the
228
- // installed compressed uploader, not just the raw data/element branches.
229
- const { state, gl } = createGlState();
230
- const rgba = new Uint8ClampedArray(4 * 4 * 4);
231
- const decode = vi.fn(() => rgba);
232
- registerGlCompressedTextureUpload(state);
233
- registerGlCompressedTextureDecoder(state, decode);
234
- const image = compressedBc3ImageResource();
235
- bindGlImageResourceTexture(state, image);
236
- expect(decode).toHaveBeenCalledWith('bc3', 4, 4, expect.any(Uint8Array));
237
- expect(gl.texImage2D).toHaveBeenCalled();
238
- expect(getGlRenderStateRuntime(state).currentTextureStraightAlpha).toBe(true);
239
- });
240
-
241
- it('skips a compressed-only ImageResource when no compressed uploader is registered', () => {
242
- // The compressed path is an opt-in seam: without registerGlCompressedTextureUpload, a compressed
243
- // resource uploads nothing (the enum table tree-shakes out of a bitmap-only bundle) rather than
244
- // reaching texImage2D.
245
- const { state, gl } = createGlState();
246
- bindGlImageResourceTexture(state, compressedBc3ImageResource());
247
- expect(gl.texImage2D).not.toHaveBeenCalled();
248
- expect(gl.compressedTexImage2D).not.toHaveBeenCalled();
249
- });
250
-
251
- it('a per-bitmap smoothingOverride=false forces NEAREST even when allowSmoothing is true', () => {
252
- // A non-smoothed bitmap must sample NEAREST regardless of the global allowSmoothing default.
233
+ it('a smoothingOverride=false forces NEAREST even when allowSmoothing is true', () => {
253
234
  const { state, gl } = createGlState({ allowSmoothing: true });
254
- bindGlImageResourceTexture(state, dataResource(4, 1), null, false);
235
+ bindGlBitmapTexture(state, bitmap(4, 1), null, false);
255
236
  const g = gl as unknown as {
256
237
  TEXTURE_2D: number;
257
238
  TEXTURE_MIN_FILTER: number;
@@ -262,9 +243,9 @@ describe('bindGlImageResourceTexture', () => {
262
243
  expect(gl.texParameteri).toHaveBeenCalledWith(g.TEXTURE_2D, g.TEXTURE_MAG_FILTER, g.NEAREST);
263
244
  });
264
245
 
265
- it('a per-bitmap smoothingOverride=true forces LINEAR even when allowSmoothing is false', () => {
246
+ it('a smoothingOverride=true forces LINEAR even when allowSmoothing is false', () => {
266
247
  const { state, gl } = createGlState({ allowSmoothing: false });
267
- bindGlImageResourceTexture(state, dataResource(4, 1), null, true);
248
+ bindGlBitmapTexture(state, bitmap(4, 1), null, true);
268
249
  const g = gl as unknown as {
269
250
  TEXTURE_2D: number;
270
251
  TEXTURE_MIN_FILTER: number;
@@ -276,6 +257,93 @@ describe('bindGlImageResourceTexture', () => {
276
257
  });
277
258
  });
278
259
 
260
+ // The uploader resolves the source's DECLARED encoding to the one the caller asked for, in BOTH
261
+ // directions. The straight direction is what makes a premultiplied source safe as a 3D material map: 3D
262
+ // binds with premultiply=false and premultiplies in its fragment tail, so passing premultiplied rgb
263
+ // straight through would square the coverage and darken every translucent texel.
264
+ describe('bindGlBitmapTexture alpha encoding', () => {
265
+ const uploadedPixels = (gl: { texImage2D: unknown }): Uint8ClampedArray =>
266
+ (gl.texImage2D as ReturnType<typeof vi.fn>).mock.calls.at(-1)!.at(-1) as Uint8ClampedArray;
267
+
268
+ it('recovers straight rgb when a premultiplied source is bound for a straight realization', () => {
269
+ const { state, gl } = createGlState();
270
+ bindGlBitmapTexture(state, encodedBitmap('premultiplied', [64, 32, 16, 128]), undefined, null, false);
271
+ const pixels = uploadedPixels(gl);
272
+ // 64 stored at a=128 recovers to ~128 straight (64 * 255/128); alpha itself is untouched.
273
+ expect(pixels[0]).toBeGreaterThan(120);
274
+ expect(pixels[3]).toBe(128);
275
+ });
276
+
277
+ it('leaves a premultiplied source untouched for a premultiplied realization', () => {
278
+ const { state, gl } = createGlState();
279
+ bindGlBitmapTexture(state, encodedBitmap('premultiplied', [64, 32, 16, 128]), undefined, null, true);
280
+ expect(Array.from(uploadedPixels(gl).slice(0, 4))).toEqual([64, 32, 16, 128]);
281
+ });
282
+
283
+ it('leaves a fully transparent premultiplied texel at zero rather than dividing by zero', () => {
284
+ const { state, gl } = createGlState();
285
+ bindGlBitmapTexture(state, encodedBitmap('premultiplied', [0, 0, 0, 0]), undefined, null, false);
286
+ expect(Array.from(uploadedPixels(gl).slice(0, 4))).toEqual([0, 0, 0, 0]);
287
+ });
288
+ });
289
+
290
+ describe('bindGlCompressedImageTexture', () => {
291
+ it('routes through the registered compressed upload seam (decode fallback)', () => {
292
+ // The device mock exposes no block extension, so the compressed container falls back to the
293
+ // registered RGBA decoder and uploads via texImage2D — proving the real bind/draw path reaches the
294
+ // installed compressed uploader.
295
+ const { state, gl } = createGlState();
296
+ const rgba = new Uint8ClampedArray(4 * 4 * 4);
297
+ const decode = vi.fn(() => rgba);
298
+ registerGlCompressedTextureUpload(state);
299
+ registerGlCompressedTextureDecoder(state, decode);
300
+ const image = compressedBc3Image();
301
+ bindGlCompressedImageTexture(state, image);
302
+ expect(decode).toHaveBeenCalledWith('bc3', 4, 4, expect.any(Uint8Array));
303
+ expect(gl.texImage2D).toHaveBeenCalled();
304
+ expect(getGlRenderStateRuntime(state).currentTextureStraightAlpha).toBe(true);
305
+ });
306
+
307
+ it('preserves straight-alpha sampling on a cache hit', () => {
308
+ const { state } = createGlState();
309
+ registerGlCompressedTextureUpload(state);
310
+ registerGlCompressedTextureDecoder(
311
+ state,
312
+ vi.fn(() => new Uint8ClampedArray(4 * 4 * 4)),
313
+ );
314
+ const image = compressedBc3Image();
315
+ bindGlCompressedImageTexture(state, image);
316
+ getGlRenderStateRuntime(state).currentTextureStraightAlpha = false;
317
+ bindGlCompressedImageTexture(state, image);
318
+ expect(getGlRenderStateRuntime(state).currentTextureStraightAlpha).toBe(true);
319
+ });
320
+
321
+ it('skips the image when no compressed uploader is registered', () => {
322
+ // The compressed path is an opt-in seam: without registerGlCompressedTextureUpload, a compressed
323
+ // image uploads nothing (the enum table tree-shakes out of a bitmap-only bundle) rather than
324
+ // reaching texImage2D.
325
+ const { state, gl } = createGlState();
326
+ bindGlCompressedImageTexture(state, compressedBc3Image());
327
+ expect(gl.texImage2D).not.toHaveBeenCalled();
328
+ expect(gl.compressedTexImage2D).not.toHaveBeenCalled();
329
+ });
330
+ });
331
+
332
+ describe('bindGlImageResourceTexture', () => {
333
+ it('uploads a host-backed image via the element path', () => {
334
+ const { state, gl } = createGlState();
335
+ const image = {
336
+ source: document.createElement('img'),
337
+ width: 1,
338
+ height: 1,
339
+ kind: ImageTextureSourceKind,
340
+ version: 1,
341
+ } as unknown as Image;
342
+ bindGlImageResourceTexture(state, image);
343
+ expect(gl.texImage2D).toHaveBeenCalled();
344
+ });
345
+ });
346
+
279
347
  describe('bindGlTexture', () => {
280
348
  it('creates a new texture for an uncached image source', () => {
281
349
  const { state, gl } = createGlState();
@@ -493,18 +561,16 @@ describe('bindGlVideoTexture', () => {
493
561
  function videoTexture(version: number, readyState = 4, videoWidth = 320, videoHeight = 240): Texture {
494
562
  return {
495
563
  sampler: makeSampler(),
496
- storage: {
497
- dimension: '2d',
498
- image: {
499
- source: { readyState, videoWidth, videoHeight } as unknown as HTMLVideoElement,
500
- version,
501
- },
564
+ dimension: '2d',
565
+ source: {
566
+ source: { readyState, videoWidth, videoHeight } as unknown as HTMLVideoElement,
567
+ version,
502
568
  },
503
569
  version,
504
570
  } as unknown as Texture;
505
571
  }
506
572
 
507
- it('creates a texture, uploads the current frame, and caches by backing identity', () => {
573
+ it('creates a texture, uploads the current frame, and caches by source identity', () => {
508
574
  const { state, gl } = createGlState();
509
575
  const vt = videoTexture(3);
510
576
  const t1 = bindGlVideoTexture(state, vt);
@@ -515,24 +581,50 @@ describe('bindGlVideoTexture', () => {
515
581
  gl.RGBA,
516
582
  gl.RGBA,
517
583
  gl.UNSIGNED_BYTE,
518
- vt.storage.image!.source,
584
+ (getTextureSource(vt) as Image).source,
519
585
  );
520
586
  const t2 = bindGlVideoTexture(state, vt);
521
587
  expect(t2).toBe(t1);
522
588
  });
523
589
 
524
- it('re-uploads only when the backing version advances (the dirty-gate)', () => {
590
+ it('re-uploads only when the source version advances (the dirty-gate)', () => {
525
591
  const { state, gl } = createGlState();
526
592
  const vt = videoTexture(1);
527
593
  bindGlVideoTexture(state, vt);
528
594
  const uploads = (gl.texImage2D as ReturnType<typeof vi.fn>).mock.calls.length;
529
595
  bindGlVideoTexture(state, vt);
530
596
  expect((gl.texImage2D as ReturnType<typeof vi.fn>).mock.calls.length).toBe(uploads);
531
- vt.storage.image!.version = 2;
597
+ getTextureSource(vt)!.version = 2;
532
598
  bindGlVideoTexture(state, vt);
533
599
  expect((gl.texImage2D as ReturnType<typeof vi.fn>).mock.calls.length).toBe(uploads + 1);
534
600
  });
535
601
 
602
+ it('realizes distinct linear and sRGB textures for one video source', () => {
603
+ const { state, gl } = createGlState();
604
+ const vt = videoTexture(1);
605
+ vt.colorSpace = 'srgb';
606
+ const srgb = bindGlVideoTexture(state, vt);
607
+ expect(gl.texImage2D).toHaveBeenLastCalledWith(
608
+ gl.TEXTURE_2D,
609
+ 0,
610
+ gl.SRGB8_ALPHA8,
611
+ gl.RGBA,
612
+ gl.UNSIGNED_BYTE,
613
+ (getTextureSource(vt) as Image).source,
614
+ );
615
+ vt.colorSpace = 'linear';
616
+ const linear = bindGlVideoTexture(state, vt);
617
+ expect(linear).not.toBe(srgb);
618
+ expect(gl.texImage2D).toHaveBeenLastCalledWith(
619
+ gl.TEXTURE_2D,
620
+ 0,
621
+ gl.RGBA,
622
+ gl.RGBA,
623
+ gl.UNSIGNED_BYTE,
624
+ (getTextureSource(vt) as Image).source,
625
+ );
626
+ });
627
+
536
628
  it('does not upload when the element has no decoded frame yet', () => {
537
629
  const { state, gl } = createGlState();
538
630
  bindGlVideoTexture(state, videoTexture(1, 1, 0, 0));
@@ -0,0 +1,30 @@
1
+ import { getTextureSourceKind } from '@flighthq/texture/contract';
2
+ import { ExternalTextureSourceKind } from '@flighthq/types/contract';
3
+
4
+ import { createExternalGlTexture, disposeExternalGlTexture } from './glExternalTexture';
5
+ import { createGlState } from './glTestHelper';
6
+ import { resolveGlTexture } from './glTextureResolver';
7
+
8
+ describe('createExternalGlTexture', () => {
9
+ it('resolves a borrowed handle and forgets it without deleting the allocation', () => {
10
+ const { state } = createGlState();
11
+ const handle = state.gl.createTexture()!;
12
+ const deleteTexture = vi.spyOn(state.gl, 'deleteTexture');
13
+ const texture = createExternalGlTexture(state, handle, { height: 16, width: 32 });
14
+
15
+ expect(getTextureSourceKind(texture)).toBe(ExternalTextureSourceKind);
16
+ expect(resolveGlTexture(state, texture)).toBe(handle);
17
+ expect(disposeExternalGlTexture(state, texture)).toBe(true);
18
+ expect(resolveGlTexture(state, texture)).toBeNull();
19
+ expect(deleteTexture).not.toHaveBeenCalled();
20
+ });
21
+ });
22
+
23
+ describe('disposeExternalGlTexture', () => {
24
+ it('returns false after the borrowed handle has already been forgotten', () => {
25
+ const { state } = createGlState();
26
+ const texture = createExternalGlTexture(state, state.gl.createTexture()!, { height: 1, width: 1 });
27
+ expect(disposeExternalGlTexture(state, texture)).toBe(true);
28
+ expect(disposeExternalGlTexture(state, texture)).toBe(false);
29
+ });
30
+ });
@@ -16,9 +16,22 @@ void main() {
16
16
 
17
17
  function makeTarget(framebuffer: WebGLFramebuffer, width = 32, height = 16): GlRenderTarget {
18
18
  return {
19
+ requestedAxes: {
20
+ width,
21
+ height,
22
+ format: 'rgba8',
23
+ colorAttachments: 1,
24
+ colorFormats: ['rgba8'],
25
+ sampleCount: 1,
26
+ depth: 'none',
27
+ colorSpace: 'srgb',
28
+ },
19
29
  width,
20
30
  height,
21
31
  format: 'rgba8',
32
+ colorAttachments: 1,
33
+ colorFormats: ['rgba8'],
34
+ depth: 'none',
22
35
  colorSpace: 'srgb',
23
36
  clearColors: [],
24
37
  clearDepth: 1,
@@ -55,7 +68,7 @@ describe('clearGlRenderTarget', () => {
55
68
  clearGlRenderTarget(state, target);
56
69
 
57
70
  expect(viewportSpy).toHaveBeenCalledWith(0, 0, 48, 24);
58
- expect(getGlRenderStateRuntime(state).renderTargetViewport).toEqual({ width: 48, height: 24 });
71
+ expect(getGlRenderStateRuntime(state).renderTargetViewport).toEqual({ height: 24, width: 48, x: 0, y: 0 });
59
72
  });
60
73
 
61
74
  it('clears to fully transparent', () => {
@@ -132,7 +145,7 @@ describe('drawGlFullscreenPass', () => {
132
145
 
133
146
  expect(bindSpy).toHaveBeenCalledWith(gl.FRAMEBUFFER, dest.framebuffer);
134
147
  expect(viewportSpy).toHaveBeenCalledWith(0, 0, 40, 20);
135
- expect(getGlRenderStateRuntime(state).renderTargetViewport).toEqual({ width: 40, height: 20 });
148
+ expect(getGlRenderStateRuntime(state).renderTargetViewport).toEqual({ height: 20, width: 40, x: 0, y: 0 });
136
149
  });
137
150
 
138
151
  it('targets the canvas and clears renderTargetViewport when dest is null', () => {
@@ -5,9 +5,22 @@ import { createGlState } from './glTestHelper';
5
5
 
6
6
  function makeTarget(framebuffer: WebGLFramebuffer, texture: WebGLTexture, width = 32, height = 16): GlRenderTarget {
7
7
  return {
8
+ requestedAxes: {
9
+ width,
10
+ height,
11
+ format: 'rgba16f',
12
+ colorAttachments: 1,
13
+ colorFormats: ['rgba16f'],
14
+ sampleCount: 1,
15
+ depth: 'none',
16
+ colorSpace: 'linear',
17
+ },
8
18
  width,
9
19
  height,
10
20
  format: 'rgba16f',
21
+ colorAttachments: 1,
22
+ colorFormats: ['rgba16f'],
23
+ depth: 'none',
11
24
  colorSpace: 'linear',
12
25
  clearColors: [],
13
26
  clearDepth: 1,
@@ -1,5 +1,6 @@
1
+ import { enableRenderRegistryGuards, explainRenderRegistryMisses } from '@flighthq/render/contract';
1
2
  import type { GlMaterialRenderer, Material } from '@flighthq/types/contract';
2
- import { StandardMaterialKind } from '@flighthq/types/contract';
3
+ import { RenderRegistry, StandardMaterialKind } from '@flighthq/types/contract';
3
4
 
4
5
  import { getGlMaterialRenderer, registerGlMaterialRenderer, resolveGlMaterialRenderer } from './glMaterialRegistry';
5
6
  import { createGlState } from './glTestHelper';
@@ -45,4 +46,44 @@ describe('resolveGlMaterialRenderer', () => {
45
46
  expect(resolveGlMaterialRenderer(state, makeMaterial('Other'))).toBe(testRenderer);
46
47
  expect(resolveGlMaterialRenderer(state, null)).toBe(testRenderer);
47
48
  });
49
+
50
+ it('reports the missing kind, so an unresolved material is not an invisible node with clean logs', () => {
51
+ const { state } = createGlState();
52
+ enableRenderRegistryGuards(state);
53
+
54
+ resolveGlMaterialRenderer(state, makeMaterial(TestKind));
55
+ resolveGlMaterialRenderer(state, null);
56
+
57
+ expect(explainRenderRegistryMisses(state)).toEqual({
58
+ misses: [
59
+ { kind: TestKind, registry: RenderRegistry.MaterialRenderer },
60
+ { kind: StandardMaterialKind, registry: RenderRegistry.MaterialRenderer },
61
+ ],
62
+ status: 'misses-recorded',
63
+ });
64
+ });
65
+
66
+ it('reports a kind that StandardMaterialKind silently stood in for', () => {
67
+ const { state } = createGlState();
68
+ enableRenderRegistryGuards(state);
69
+ registerGlMaterialRenderer(state, StandardMaterialKind, testRenderer);
70
+
71
+ // Substituting a different shading family draws something, but not what was asked for, so it is
72
+ // reported even though the node is visible.
73
+ expect(resolveGlMaterialRenderer(state, makeMaterial('Other'))).toBe(testRenderer);
74
+
75
+ expect(explainRenderRegistryMisses(state).misses).toEqual([
76
+ { kind: 'Other', registry: RenderRegistry.MaterialRenderer },
77
+ ]);
78
+ });
79
+
80
+ it('records nothing once the kind resolves', () => {
81
+ const { state } = createGlState();
82
+ enableRenderRegistryGuards(state);
83
+ registerGlMaterialRenderer(state, TestKind, testRenderer);
84
+
85
+ resolveGlMaterialRenderer(state, makeMaterial(TestKind));
86
+
87
+ expect(explainRenderRegistryMisses(state)).toEqual({ misses: [], status: 'complete' });
88
+ });
48
89
  });
@@ -4,10 +4,24 @@ import { presentGlRenderTarget } from './glPresentRenderTarget';
4
4
  import { createGlState } from './glTestHelper';
5
5
 
6
6
  function makeTarget(colorSpace: 'linear' | 'srgb', texture: WebGLTexture): GlRenderTarget {
7
+ const format = colorSpace === 'linear' ? 'rgba16f' : 'rgba8';
7
8
  return {
9
+ requestedAxes: {
10
+ width: 32,
11
+ height: 16,
12
+ format,
13
+ colorAttachments: 1,
14
+ colorFormats: [format],
15
+ sampleCount: 1,
16
+ depth: 'none',
17
+ colorSpace,
18
+ },
8
19
  width: 32,
9
20
  height: 16,
10
- format: colorSpace === 'linear' ? 'rgba16f' : 'rgba8',
21
+ format,
22
+ colorAttachments: 1,
23
+ colorFormats: [format],
24
+ depth: 'none',
11
25
  colorSpace,
12
26
  clearColors: [],
13
27
  clearDepth: 1,
@@ -5,9 +5,22 @@ import { createGlState } from './glTestHelper';
5
5
 
6
6
  function makeTarget(overrides?: Partial<GlRenderTarget>): GlRenderTarget {
7
7
  return {
8
+ requestedAxes: {
9
+ width: 4,
10
+ height: 4,
11
+ format: 'rgba8',
12
+ colorAttachments: 1,
13
+ colorFormats: ['rgba8'],
14
+ sampleCount: 1,
15
+ depth: 'none',
16
+ colorSpace: 'srgb',
17
+ },
8
18
  width: 4,
9
19
  height: 4,
10
20
  format: 'rgba8',
21
+ colorAttachments: 1,
22
+ colorFormats: ['rgba8'],
23
+ depth: 'none',
11
24
  colorSpace: 'srgb',
12
25
  sampleCount: 1,
13
26
  framebuffer: {} as WebGLFramebuffer,