@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,70 +1,72 @@
1
- import { bindGlImageResourceTexture, bindGlVideoTexture } from './glDraw';
1
+ import { getTextureSampleColorSpace, getTextureSource, getTextureSourceKind } from '@flighthq/texture/contract';
2
+ import { BitmapTextureSourceKind, CompressedImageTextureSourceKind, ImageTextureSourceKind, RenderRegistry, RenderTargetTextureSourceKind, } from '@flighthq/types/contract';
3
+ import { bindGlBitmapTexture, bindGlCompressedImageTexture, bindGlImageResourceTexture } from './glDraw';
2
4
  import { getGlRenderStateRuntime } from './glRenderState';
3
5
  import { bindGlRenderTexture } from './glRenderTexture';
4
- // General CPU-origin 2D image matcher. More-specific backing resolvers registered later take
5
- // precedence because resolveGlTexture walks the state registry newest-first.
6
- export const glImageTextureBackingKind = (storage) => storage.dimension === '2d' && storage.image !== null;
7
- // GPU-origin produced backing. Unlike CPU-origin images this is keyed by the Texture in
8
- // glRenderTexture's hidden target cache; resolving returns its attachment without an upload.
9
- export const glProducedTextureBackingKind = (storage) => storage.target !== undefined;
10
- // Host-video specialization over the same ImageResource backing family. Structural host capabilities
11
- // avoid a public source-kind field and also work for canvas-backed test/adapter shims.
12
- export const glVideoTextureBackingKind = (storage) => {
13
- const source = storage.image?.source;
14
- return source != null && 'readyState' in source && 'videoHeight' in source && 'videoWidth' in source;
15
- };
16
- // Installs the ordinary ImageResource realization. It delegates upload/version caching to the
17
- // existing backing-keyed bindGlImageResourceTexture seam and keeps Texture.sampler off that key.
6
+ export function registerGlBitmapTextureResolver(state) {
7
+ registerGlTextureResolver(state, BitmapTextureSourceKind, resolveGlBitmapTexture);
8
+ }
9
+ export function registerGlCompressedImageTextureResolver(state) {
10
+ registerGlTextureResolver(state, CompressedImageTextureSourceKind, resolveGlCompressedImageTexture);
11
+ }
18
12
  export function registerGlImageTextureResolver(state) {
19
- registerGlTextureResolver(state, glImageTextureBackingKind, resolveGlImageTexture);
13
+ registerGlTextureResolver(state, ImageTextureSourceKind, resolveGlImageTexture);
20
14
  }
21
- // Installs the produced-target realization. Register after CPU-origin resolvers so a target
22
- // descriptor wins even if a future transitional storage record also carries an image.
23
- export function registerGlProducedTextureResolver(state) {
24
- registerGlTextureResolver(state, glProducedTextureBackingKind, resolveGlProducedTexture);
15
+ // Installs the render-target realization.
16
+ export function registerGlRenderTextureResolver(state) {
17
+ registerGlTextureResolver(state, RenderTargetTextureSourceKind, resolveGlRenderTexture);
25
18
  }
26
- // Registers or replaces one backing-family resolver on this render state. The matcher function is
27
- // the registration identity. Passing null removes it. No module-global registry exists.
28
- export function registerGlTextureResolver(state, backingKind, resolver) {
19
+ // Registers or replaces one declared source-kind resolver on this render state. Map.set is
20
+ // last-write-wins; passing null removes the key. No registration ordering or matcher scan exists.
21
+ export function registerGlTextureResolver(state, sourceKind, resolver) {
29
22
  const runtime = getGlRenderStateRuntime(state);
30
- const registry = (runtime.glTextureResolverRegistry ??= []);
31
- const index = registry.findIndex((registration) => registration.backingKind === backingKind);
32
- if (index !== -1)
33
- registry.splice(index, 1);
34
- if (resolver !== null)
35
- registry.push({ backingKind, resolver });
23
+ const registry = (runtime.glTextureResolverRegistry ??= new Map());
24
+ if (resolver === null)
25
+ registry.delete(sourceKind);
26
+ else
27
+ registry.set(sourceKind, resolver);
36
28
  }
37
- // Installs the dynamic host-video specialization. Registering after the general image resolver makes
38
- // it win the newest-first match while both continue to share the ImageResource storage shape.
39
- export function registerGlVideoTextureResolver(state) {
40
- registerGlTextureResolver(state, glVideoTextureBackingKind, resolveGlVideoTexture);
29
+ export function registerStandardGlTextureResolvers(state) {
30
+ registerGlBitmapTextureResolver(state);
31
+ registerGlImageTextureResolver(state);
32
+ registerGlRenderTextureResolver(state);
41
33
  }
42
- // Resolves through the render state's open backing registry. Newest matching registration wins,
43
- // letting video/produced/vendor backings specialize the general image match without a switch.
44
- export function resolveGlTexture(state, texture) {
45
- const registry = getGlRenderStateRuntime(state).glTextureResolverRegistry;
46
- if (registry == null)
34
+ // Resolves through one keyed lookup using the source's declared kind. Resolution is deliberately not
35
+ // pure: each built-in resolver leaves its result bound to TEXTURE_2D on the active texture unit because
36
+ // GL upload and sampler application require that binding. Callers must not reorder this call across
37
+ // activeTexture/bind operations as though it only returned a handle. The CPU source owns its kind; a
38
+ // GPU-origin target owns its own. An unbound or undeclared source is the null sentinel.
39
+ // `workingColorSpace` is the space the DESTINATION composites in, not a claim about this texture —
40
+ // `texture.colorSpace` already says what the content is. The sample format is derived from the pair by
41
+ // getTextureSampleColorSpace, so a path flips one value (its working space) rather than misdescribing
42
+ // every texture it draws. 3D composites linear; 2D composites in the encoded domain and passes 'srgb'.
43
+ export function resolveGlTexture(state, texture, premultiply = false, workingColorSpace = 'linear') {
44
+ const sourceKind = getTextureSourceKind(texture);
45
+ if (sourceKind === null)
46
+ return null;
47
+ const runtime = getGlRenderStateRuntime(state);
48
+ const resolver = runtime.glTextureResolverRegistry?.get(sourceKind);
49
+ if (resolver === undefined) {
50
+ runtime.registryMiss?.(RenderRegistry.TextureResolver, sourceKind);
47
51
  return null;
48
- for (let i = registry.length - 1; i >= 0; i--) {
49
- const registration = registry[i];
50
- if (registration.backingKind(texture.storage))
51
- return registration.resolver(state, texture);
52
52
  }
53
- return null;
53
+ return resolver(state, texture, premultiply, getTextureSampleColorSpace(texture.colorSpace, workingColorSpace));
54
54
  }
55
- function resolveGlImageTexture(state, texture) {
56
- const image = texture.storage.image;
57
- if (image === null || (image.source === null && image.data === null && image.compressed === null))
58
- return null;
59
- return bindGlImageResourceTexture(state, image, texture.sampler);
55
+ function resolveGlBitmapTexture(state, texture, premultiply, colorSpace) {
56
+ const bitmap = getTextureSource(texture);
57
+ return bitmap === null ? null : bindGlBitmapTexture(state, bitmap, texture.sampler, null, premultiply, colorSpace);
60
58
  }
61
- function resolveGlProducedTexture(state, texture) {
62
- return bindGlRenderTexture(state, texture);
59
+ function resolveGlCompressedImageTexture(state, texture, _premultiply, colorSpace) {
60
+ const image = getTextureSource(texture);
61
+ return image === null ? null : bindGlCompressedImageTexture(state, image, texture.sampler, null, colorSpace);
63
62
  }
64
- function resolveGlVideoTexture(state, texture) {
65
- const source = texture.storage.image?.source;
66
- if (source == null || source.readyState < 2 || source.videoWidth <= 0 || source.videoHeight <= 0)
67
- return null;
68
- return bindGlVideoTexture(state, texture);
63
+ function resolveGlImageTexture(state, texture, premultiply, colorSpace) {
64
+ const image = getTextureSource(texture);
65
+ return image === null
66
+ ? null
67
+ : bindGlImageResourceTexture(state, image, texture.sampler, null, premultiply, colorSpace);
68
+ }
69
+ function resolveGlRenderTexture(state, texture) {
70
+ return bindGlRenderTexture(state, texture);
69
71
  }
70
72
  //# sourceMappingURL=glTextureResolver.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"glTextureResolver.js","sourceRoot":"","sources":["../src/glTextureResolver.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,6FAA6F;AAC7F,6EAA6E;AAC7E,MAAM,CAAC,MAAM,yBAAyB,GAAyB,CAAC,OAAiC,EAAW,EAAE,CAC5G,OAAO,CAAC,SAAS,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,KAAK,IAAI,CAAC;AAEvD,wFAAwF;AACxF,6FAA6F;AAC7F,MAAM,CAAC,MAAM,4BAA4B,GAAyB,CAAC,OAAiC,EAAW,EAAE,CAC/G,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC;AAE/B,qGAAqG;AACrG,uFAAuF;AACvF,MAAM,CAAC,MAAM,yBAAyB,GAAyB,CAAC,OAAiC,EAAW,EAAE;IAC5G,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,EAAE,MAAsF,CAAC;IACrH,OAAO,MAAM,IAAI,IAAI,IAAI,YAAY,IAAI,MAAM,IAAI,aAAa,IAAI,MAAM,IAAI,YAAY,IAAI,MAAM,CAAC;AACvG,CAAC,CAAC;AAEF,8FAA8F;AAC9F,iGAAiG;AACjG,MAAM,UAAU,8BAA8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AAW,EAAE,UAAU,CAAC,CAAC;AACrH,CAAC;AAED,SAAS,+BAA+B,CACtC,KAAoB,EACpB,OAA8B,EAC9B,YAAqB,EACrB,UAA6B;IAE7B,MAAM,KAAK,GAAG,gBAAgB,CAAC,OAAO,CAAqC,CAAC;IAC5E,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,4BAA4B,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;AAC/G,CAAC;AAED,SAAS,qBAAqB,CAC5B,KAAoB,EACpB,OAA8B,EAC9B,WAAoB,EACpB,UAA6B;IAE7B,MAAM,KAAK,GAAG,gBAAgB,CAAC,OAAO,CAA2B,CAAC;IAClE,OAAO,KAAK,KAAK,IAAI;QACnB,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,0BAA0B,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;AAC/F,CAAC;AAED,SAAS,sBAAsB,CAAC,KAAoB,EAAE,OAA8B;IAClF,OAAO,mBAAmB,CAAC,KAAK,EAAE,OAAkC,CAAC,CAAC;AACxE,CAAC"}
@@ -1,5 +1,5 @@
1
- import type { ImageResource } from '@flighthq/types/contract';
2
- export declare function uploadGlTextureData(gl: WebGL2RenderingContext, target: number, width: number, height: number, data: Readonly<Uint8ClampedArray<ArrayBuffer>>): void;
3
- export declare function uploadGlTextureElement(gl: WebGL2RenderingContext, target: number, source: TexImageSource): void;
4
- export declare function uploadGlTextureImageResource(gl: WebGL2RenderingContext, target: number, image: Readonly<ImageResource>): void;
1
+ import type { Image } from '@flighthq/types/contract';
2
+ export declare function uploadGlTextureData(gl: WebGL2RenderingContext, target: number, width: number, height: number, data: Readonly<Uint8ClampedArray<ArrayBuffer>>, internalFormat?: number): void;
3
+ export declare function uploadGlTextureElement(gl: WebGL2RenderingContext, target: number, source: TexImageSource, internalFormat?: number): void;
4
+ export declare function uploadGlTextureImageResource(gl: WebGL2RenderingContext, target: number, image: Readonly<Image>, internalFormat?: number): void;
5
5
  //# sourceMappingURL=glTextureUpload.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"glTextureUpload.d.ts","sourceRoot":"","sources":["../src/glTextureUpload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAW9D,wBAAgB,mBAAmB,CACjC,EAAE,EAAE,sBAAsB,EAC1B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,QAAQ,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,GAC7C,IAAI,CAYN;AAID,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,sBAAsB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,IAAI,CAE/G;AAMD,wBAAgB,4BAA4B,CAC1C,EAAE,EAAE,sBAAsB,EAC1B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,QAAQ,CAAC,aAAa,CAAC,GAC7B,IAAI,CAGN"}
1
+ {"version":3,"file":"glTextureUpload.d.ts","sourceRoot":"","sources":["../src/glTextureUpload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAWtD,wBAAgB,mBAAmB,CACjC,EAAE,EAAE,sBAAsB,EAC1B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,QAAQ,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,EAC9C,cAAc,GAAE,MAAgB,GAC/B,IAAI,CAYN;AAID,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,sBAAsB,EAC1B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,cAAc,EACtB,cAAc,GAAE,MAAgB,GAC/B,IAAI,CAEN;AAGD,wBAAgB,4BAA4B,CAC1C,EAAE,EAAE,sBAAsB,EAC1B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,EACtB,cAAc,GAAE,MAAgB,GAC/B,IAAI,CAEN"}
@@ -3,25 +3,19 @@
3
3
  // no sampler or pixel-store state: premultiply, wrap, and filter are the caller's policy applied around
4
4
  // the call, so one primitive serves both the premultiplied 2D sprite path and the raw-radiance cube path.
5
5
  // The caller owns creating and binding the texture and choosing the target.
6
- // Uploads raw CPU pixels (rgba8, straight from a Surface's `data`) through the ArrayBufferView overload.
6
+ // Uploads raw CPU pixels (rgba8, straight from a Bitmap's `data`) through the ArrayBufferView overload.
7
7
  // The portable bedrock upload — no web types in the signature — so a native GL/Vulkan backend reimplements
8
8
  // it 1:1. `width`/`height` are the pixel dimensions the data fills.
9
- export function uploadGlTextureData(gl, target, width, height, data) {
10
- gl.texImage2D(target, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
9
+ export function uploadGlTextureData(gl, target, width, height, data, internalFormat = gl.RGBA) {
10
+ gl.texImage2D(target, 0, internalFormat, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
11
11
  }
12
12
  // Uploads a decoded DOM element (image, canvas, ImageBitmap, VideoFrame) through the TexImageSource
13
13
  // overload — the web fast-path, a zero-CPU-copy GPU DMA. Absent on non-web hosts, which carry only `data`.
14
- export function uploadGlTextureElement(gl, target, source) {
15
- gl.texImage2D(target, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
14
+ export function uploadGlTextureElement(gl, target, source, internalFormat = gl.RGBA) {
15
+ gl.texImage2D(target, 0, internalFormat, gl.RGBA, gl.UNSIGNED_BYTE, source);
16
16
  }
17
- // Dispatches an ImageResource to whichever representation it carries: the element fast-path when a decoded
18
- // `source` is present, else the portable `data` path (a generated Surface). The seam that makes data-backed
19
- // resources first-class — the same texture uploads whether it was loaded (element) or generated in memory
20
- // (data). Assumes the resource has pixels in at least one form.
21
- export function uploadGlTextureImageResource(gl, target, image) {
22
- if (image.source !== null)
23
- uploadGlTextureElement(gl, target, image.source);
24
- else
25
- uploadGlTextureData(gl, target, image.width, image.height, image.data);
17
+ // Uploads a host-backed Image through the decoded-element fast path.
18
+ export function uploadGlTextureImageResource(gl, target, image, internalFormat = gl.RGBA) {
19
+ uploadGlTextureElement(gl, target, image.source, internalFormat);
26
20
  }
27
21
  //# sourceMappingURL=glTextureUpload.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"glTextureUpload.js","sourceRoot":"","sources":["../src/glTextureUpload.ts"],"names":[],"mappings":"AAEA,uGAAuG;AACvG,yGAAyG;AACzG,wGAAwG;AACxG,0GAA0G;AAC1G,4EAA4E;AAE5E,yGAAyG;AACzG,2GAA2G;AAC3G,oEAAoE;AACpE,MAAM,UAAU,mBAAmB,CACjC,EAA0B,EAC1B,MAAc,EACd,KAAa,EACb,MAAc,EACd,IAA8C;IAE9C,EAAE,CAAC,UAAU,CACX,MAAM,EACN,CAAC,EACD,EAAE,CAAC,IAAI,EACP,KAAK,EACL,MAAM,EACN,CAAC,EACD,EAAE,CAAC,IAAI,EACP,EAAE,CAAC,aAAa,EAChB,IAAsC,CACvC,CAAC;AACJ,CAAC;AAED,oGAAoG;AACpG,2GAA2G;AAC3G,MAAM,UAAU,sBAAsB,CAAC,EAA0B,EAAE,MAAc,EAAE,MAAsB;IACvG,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;AACvE,CAAC;AAED,2GAA2G;AAC3G,4GAA4G;AAC5G,0GAA0G;AAC1G,gEAAgE;AAChE,MAAM,UAAU,4BAA4B,CAC1C,EAA0B,EAC1B,MAAc,EACd,KAA8B;IAE9B,IAAI,KAAK,CAAC,MAAM,KAAK,IAAI;QAAE,sBAAsB,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,MAAwB,CAAC,CAAC;;QACzF,mBAAmB,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,IAAK,CAAC,CAAC;AAC/E,CAAC"}
1
+ {"version":3,"file":"glTextureUpload.js","sourceRoot":"","sources":["../src/glTextureUpload.ts"],"names":[],"mappings":"AAEA,uGAAuG;AACvG,yGAAyG;AACzG,wGAAwG;AACxG,0GAA0G;AAC1G,4EAA4E;AAE5E,wGAAwG;AACxG,2GAA2G;AAC3G,oEAAoE;AACpE,MAAM,UAAU,mBAAmB,CACjC,EAA0B,EAC1B,MAAc,EACd,KAAa,EACb,MAAc,EACd,IAA8C,EAC9C,iBAAyB,EAAE,CAAC,IAAI;IAEhC,EAAE,CAAC,UAAU,CACX,MAAM,EACN,CAAC,EACD,cAAc,EACd,KAAK,EACL,MAAM,EACN,CAAC,EACD,EAAE,CAAC,IAAI,EACP,EAAE,CAAC,aAAa,EAChB,IAAsC,CACvC,CAAC;AACJ,CAAC;AAED,oGAAoG;AACpG,2GAA2G;AAC3G,MAAM,UAAU,sBAAsB,CACpC,EAA0B,EAC1B,MAAc,EACd,MAAsB,EACtB,iBAAyB,EAAE,CAAC,IAAI;IAEhC,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,cAAc,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;AAC9E,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,4BAA4B,CAC1C,EAA0B,EAC1B,MAAc,EACd,KAAsB,EACtB,iBAAyB,EAAE,CAAC,IAAI;IAEhC,sBAAsB,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,MAAwB,EAAE,cAAc,CAAC,CAAC;AACrF,CAAC"}
@@ -1,3 +1,3 @@
1
- import type { ImageResource } from '@flighthq/types/contract';
2
- export declare function uploadGlTextureVideoFrame(gl: WebGL2RenderingContext, image: Readonly<ImageResource>, uploadedVersion: number): number;
1
+ import type { Image } from '@flighthq/types/contract';
2
+ export declare function uploadGlTextureVideoFrame(gl: WebGL2RenderingContext, image: Readonly<Image>, uploadedVersion: number, internalFormat?: number): number;
3
3
  //# sourceMappingURL=glTextureVideoUpload.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"glTextureVideoUpload.d.ts","sourceRoot":"","sources":["../src/glTextureVideoUpload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAc9D,wBAAgB,yBAAyB,CACvC,EAAE,EAAE,sBAAsB,EAC1B,KAAK,EAAE,QAAQ,CAAC,aAAa,CAAC,EAC9B,eAAe,EAAE,MAAM,GACtB,MAAM,CAUR"}
1
+ {"version":3,"file":"glTextureVideoUpload.d.ts","sourceRoot":"","sources":["../src/glTextureVideoUpload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AActD,wBAAgB,yBAAyB,CACvC,EAAE,EAAE,sBAAsB,EAC1B,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,EACtB,eAAe,EAAE,MAAM,EACvB,cAAc,GAAE,MAAgB,GAC/B,MAAM,CAUR"}
@@ -1,15 +1,15 @@
1
1
  import { uploadGlTextureElement } from './glTextureUpload';
2
- // The per-frame video-to-GPU upload path. An ImageResource's borrowed HTMLVideoElement decodes new pixels
2
+ // The per-frame video-to-GPU upload path. An Image's borrowed HTMLVideoElement decodes new pixels
3
3
  // continuously, so a driver re-uploads the currently-bound GL texture whenever the element's frame
4
4
  // advances — but not on frames where nothing changed (a paused or stalled stream), which would waste a
5
- // full-frame DMA. `uploadedVersion` is the backing revision the caller last uploaded; this compares it to the
6
- // backing's `version` and re-uploads through the element fast-path only on a change, returning the
5
+ // full-frame DMA. `uploadedVersion` is the source revision the caller last uploaded; this compares it to the
6
+ // source's `version` and re-uploads through the element fast-path only on a change, returning the
7
7
  // id now on the GPU so the caller stores it for the next frame.
8
8
  //
9
9
  // The caller owns creating, binding, and setting sampler/pixel-store state on the texture; this writes
10
10
  // level 0 at gl.TEXTURE_2D. Returns `uploadedVersion` unchanged (no GL call) when the frame has not
11
11
  // advanced or the element has no decoded frame yet, so it is safe to call every frame unconditionally.
12
- export function uploadGlTextureVideoFrame(gl, image, uploadedVersion) {
12
+ export function uploadGlTextureVideoFrame(gl, image, uploadedVersion, internalFormat = gl.RGBA) {
13
13
  if (image.version === uploadedVersion)
14
14
  return uploadedVersion;
15
15
  const element = image.source;
@@ -18,7 +18,7 @@ export function uploadGlTextureVideoFrame(gl, image, uploadedVersion) {
18
18
  if (element === null || element.readyState < 2 || element.videoWidth <= 0 || element.videoHeight <= 0) {
19
19
  return uploadedVersion;
20
20
  }
21
- uploadGlTextureElement(gl, gl.TEXTURE_2D, element);
21
+ uploadGlTextureElement(gl, gl.TEXTURE_2D, element, internalFormat);
22
22
  return image.version;
23
23
  }
24
24
  //# sourceMappingURL=glTextureVideoUpload.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"glTextureVideoUpload.js","sourceRoot":"","sources":["../src/glTextureVideoUpload.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,0GAA0G;AAC1G,mGAAmG;AACnG,uGAAuG;AACvG,8GAA8G;AAC9G,mGAAmG;AACnG,gEAAgE;AAChE,EAAE;AACF,uGAAuG;AACvG,oGAAoG;AACpG,uGAAuG;AACvG,MAAM,UAAU,yBAAyB,CACvC,EAA0B,EAC1B,KAA8B,EAC9B,eAAuB;IAEvB,IAAI,KAAK,CAAC,OAAO,KAAK,eAAe;QAAE,OAAO,eAAe,CAAC;IAC9D,MAAM,OAAO,GAAG,KAAK,CAAC,MAAiC,CAAC;IACxD,qGAAqG;IACrG,+FAA+F;IAC/F,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,CAAC,UAAU,GAAG,CAAC,IAAI,OAAO,CAAC,UAAU,IAAI,CAAC,IAAI,OAAO,CAAC,WAAW,IAAI,CAAC,EAAE,CAAC;QACtG,OAAO,eAAe,CAAC;IACzB,CAAC;IACD,sBAAsB,CAAC,EAAE,EAAE,EAAE,CAAC,UAAU,EAAE,OAAoC,CAAC,CAAC;IAChF,OAAO,KAAK,CAAC,OAAO,CAAC;AACvB,CAAC"}
1
+ {"version":3,"file":"glTextureVideoUpload.js","sourceRoot":"","sources":["../src/glTextureVideoUpload.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,kGAAkG;AAClG,mGAAmG;AACnG,uGAAuG;AACvG,6GAA6G;AAC7G,kGAAkG;AAClG,gEAAgE;AAChE,EAAE;AACF,uGAAuG;AACvG,oGAAoG;AACpG,uGAAuG;AACvG,MAAM,UAAU,yBAAyB,CACvC,EAA0B,EAC1B,KAAsB,EACtB,eAAuB,EACvB,iBAAyB,EAAE,CAAC,IAAI;IAEhC,IAAI,KAAK,CAAC,OAAO,KAAK,eAAe;QAAE,OAAO,eAAe,CAAC;IAC9D,MAAM,OAAO,GAAG,KAAK,CAAC,MAAiC,CAAC;IACxD,qGAAqG;IACrG,+FAA+F;IAC/F,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,CAAC,UAAU,GAAG,CAAC,IAAI,OAAO,CAAC,UAAU,IAAI,CAAC,IAAI,OAAO,CAAC,WAAW,IAAI,CAAC,EAAE,CAAC;QACtG,OAAO,eAAe,CAAC;IACzB,CAAC;IACD,sBAAsB,CAAC,EAAE,EAAE,EAAE,CAAC,UAAU,EAAE,OAAoC,EAAE,cAAc,CAAC,CAAC;IAChG,OAAO,KAAK,CAAC,OAAO,CAAC;AACvB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { beginGlRenderPass, bindGlImageResourceTexture, bindGlRenderTexture, bindGlTexture, createGlCanvasElement, createGlRenderState, createGlRenderTarget, destroyGlRenderTexture, enableGlRenderTextureGuards, enableGlBlendModeSupport, endGlRenderPass, explainGlRenderTexture, registerGlCompressedTextureDecoder, registerGlCompressedTextureUpload, registerGlImageTextureResolver, registerGlProducedTextureResolver, registerGlTextureResolver, registerGlVideoTextureResolver, renderGlBackground, renderIntoGlRenderTexture, resolveGlTexture, uploadGlCompressedTextureContainer, } from './contract';
1
+ export { acquireGlRenderTexture, beginGlRenderPass, bindGlImageResourceTexture, bindGlRenderTexture, bindGlTexture, clearGlRenderTexture, copyGlRenderStateRegistrations, createGlCanvasElement, createExternalGlTexture, createGlOffscreenRenderState, createGlRenderState, createGlRenderTexturePool, createGlRenderTarget, destroyGlRenderTexture, destroyGlRenderTexturePool, destroyGlRenderState, disposeExternalGlTexture, enableGlRenderTextureGuards, enableGlRenderStateGuards, enableGlTextureResolverGuards, enableGlBlendModeSupport, endGlRenderPass, explainGlRenderTarget, explainGlRenderTexture, explainGlTextureResolution, isGlRenderTargetFormatSupported, registerGlBitmapTextureResolver, registerGlCompressedTextureDecoder, registerGlCompressedImageTextureResolver, registerGlCompressedTextureUpload, registerGlImageTextureResolver, registerGlRenderTextureResolver, registerStandardGlTextureResolvers, registerGlTextureResolver, renderGlBackground, renderIntoGlRenderTexture, releaseGlRenderTexture, resolveGlRenderTargetAxes, resolveGlTexture, setGlRenderTransform2D, uploadGlCompressedTextureContainer, withGlRenderTextures, } from './contract';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,mBAAmB,EACnB,aAAa,EACb,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,2BAA2B,EAC3B,wBAAwB,EACxB,eAAe,EACf,sBAAsB,EACtB,kCAAkC,EAClC,iCAAiC,EACjC,8BAA8B,EAC9B,iCAAiC,EACjC,yBAAyB,EACzB,8BAA8B,EAC9B,kBAAkB,EAClB,yBAAyB,EACzB,gBAAgB,EAChB,kCAAkC,GACnC,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,0BAA0B,EAC1B,mBAAmB,EACnB,aAAa,EACb,oBAAoB,EACpB,8BAA8B,EAC9B,qBAAqB,EACrB,uBAAuB,EACvB,4BAA4B,EAC5B,mBAAmB,EACnB,yBAAyB,EACzB,oBAAoB,EACpB,sBAAsB,EACtB,0BAA0B,EAC1B,oBAAoB,EACpB,wBAAwB,EACxB,2BAA2B,EAC3B,yBAAyB,EACzB,6BAA6B,EAC7B,wBAAwB,EACxB,eAAe,EACf,qBAAqB,EACrB,sBAAsB,EACtB,0BAA0B,EAC1B,+BAA+B,EAC/B,+BAA+B,EAC/B,kCAAkC,EAClC,wCAAwC,EACxC,iCAAiC,EACjC,8BAA8B,EAC9B,+BAA+B,EAC/B,kCAAkC,EAClC,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,sBAAsB,EACtB,yBAAyB,EACzB,gBAAgB,EAChB,sBAAsB,EACtB,kCAAkC,EAClC,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { beginGlRenderPass, bindGlImageResourceTexture, bindGlRenderTexture, bindGlTexture, createGlCanvasElement, createGlRenderState, createGlRenderTarget, destroyGlRenderTexture, enableGlRenderTextureGuards, enableGlBlendModeSupport, endGlRenderPass, explainGlRenderTexture, registerGlCompressedTextureDecoder, registerGlCompressedTextureUpload, registerGlImageTextureResolver, registerGlProducedTextureResolver, registerGlTextureResolver, registerGlVideoTextureResolver, renderGlBackground, renderIntoGlRenderTexture, resolveGlTexture, uploadGlCompressedTextureContainer, } from './contract';
1
+ export { acquireGlRenderTexture, beginGlRenderPass, bindGlImageResourceTexture, bindGlRenderTexture, bindGlTexture, clearGlRenderTexture, copyGlRenderStateRegistrations, createGlCanvasElement, createExternalGlTexture, createGlOffscreenRenderState, createGlRenderState, createGlRenderTexturePool, createGlRenderTarget, destroyGlRenderTexture, destroyGlRenderTexturePool, destroyGlRenderState, disposeExternalGlTexture, enableGlRenderTextureGuards, enableGlRenderStateGuards, enableGlTextureResolverGuards, enableGlBlendModeSupport, endGlRenderPass, explainGlRenderTarget, explainGlRenderTexture, explainGlTextureResolution, isGlRenderTargetFormatSupported, registerGlBitmapTextureResolver, registerGlCompressedTextureDecoder, registerGlCompressedImageTextureResolver, registerGlCompressedTextureUpload, registerGlImageTextureResolver, registerGlRenderTextureResolver, registerStandardGlTextureResolvers, registerGlTextureResolver, renderGlBackground, renderIntoGlRenderTexture, releaseGlRenderTexture, resolveGlRenderTargetAxes, resolveGlTexture, setGlRenderTransform2D, uploadGlCompressedTextureContainer, withGlRenderTextures, } from './contract';
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,mBAAmB,EACnB,aAAa,EACb,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,2BAA2B,EAC3B,wBAAwB,EACxB,eAAe,EACf,sBAAsB,EACtB,kCAAkC,EAClC,iCAAiC,EACjC,8BAA8B,EAC9B,iCAAiC,EACjC,yBAAyB,EACzB,8BAA8B,EAC9B,kBAAkB,EAClB,yBAAyB,EACzB,gBAAgB,EAChB,kCAAkC,GACnC,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,0BAA0B,EAC1B,mBAAmB,EACnB,aAAa,EACb,oBAAoB,EACpB,8BAA8B,EAC9B,qBAAqB,EACrB,uBAAuB,EACvB,4BAA4B,EAC5B,mBAAmB,EACnB,yBAAyB,EACzB,oBAAoB,EACpB,sBAAsB,EACtB,0BAA0B,EAC1B,oBAAoB,EACpB,wBAAwB,EACxB,2BAA2B,EAC3B,yBAAyB,EACzB,6BAA6B,EAC7B,wBAAwB,EACxB,eAAe,EACf,qBAAqB,EACrB,sBAAsB,EACtB,0BAA0B,EAC1B,+BAA+B,EAC/B,+BAA+B,EAC/B,kCAAkC,EAClC,wCAAwC,EACxC,iCAAiC,EACjC,8BAA8B,EAC9B,+BAA+B,EAC/B,kCAAkC,EAClC,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,sBAAsB,EACtB,yBAAyB,EACzB,gBAAgB,EAChB,sBAAsB,EACtB,kCAAkC,EAClC,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,8 @@
1
1
  {
2
2
  "name": "@flighthq/render-gl",
3
- "version": "0.3.0-next.906.07cea63",
3
+ "version": "0.3.1-next.209.43ef1bc",
4
+ "author": "Joshua Granick and other contributors",
5
+ "license": "MIT",
4
6
  "repository": {
5
7
  "type": "git",
6
8
  "url": "https://github.com/flighthq/flight.git",
@@ -36,11 +38,15 @@
36
38
  "clean:dist": "tsx ../../scripts/clean-package-dist.ts"
37
39
  },
38
40
  "dependencies": {
39
- "@flighthq/log": "0.3.0-next.906.07cea63",
40
- "@flighthq/scene2d": "0.3.0-next.906.07cea63",
41
- "@flighthq/geometry": "0.3.0-next.906.07cea63",
42
- "@flighthq/render": "0.3.0-next.906.07cea63",
43
- "@flighthq/types": "0.3.0-next.906.07cea63"
41
+ "@flighthq/color": "0.3.1-next.209.43ef1bc",
42
+ "@flighthq/entity": "0.3.1-next.209.43ef1bc",
43
+ "@flighthq/log": "0.3.1-next.209.43ef1bc",
44
+ "@flighthq/scene2d": "0.3.1-next.209.43ef1bc",
45
+ "@flighthq/geometry": "0.3.1-next.209.43ef1bc",
46
+ "@flighthq/render": "0.3.1-next.209.43ef1bc",
47
+ "@flighthq/signals": "0.3.1-next.209.43ef1bc",
48
+ "@flighthq/texture": "0.3.1-next.209.43ef1bc",
49
+ "@flighthq/types": "0.3.1-next.209.43ef1bc"
44
50
  },
45
51
  "devDependencies": {
46
52
  "typescript": "^5.3.0"
@@ -0,0 +1,70 @@
1
+ import { setLogSink } from '@flighthq/log/contract';
2
+ import type { LogEntry } from '@flighthq/types/contract';
3
+
4
+ import { areGlRenderStateGuardsEnabled, enableGlRenderStateGuards } from './enableGlRenderStateGuards';
5
+ import { useGlProgram } from './glDraw';
6
+ import { createGlRenderState, getGlRenderStateRuntime } from './glRenderState';
7
+ import { makeGL } from './glTestHelper';
8
+
9
+ function createState() {
10
+ const canvas = document.createElement('canvas');
11
+ canvas.getContext = vi.fn().mockReturnValue(makeGL()) as typeof canvas.getContext;
12
+ return createGlRenderState(canvas);
13
+ }
14
+
15
+ describe('areGlRenderStateGuardsEnabled', () => {
16
+ it('reports whether the state-local multiple-root guard is installed', () => {
17
+ const state = createState();
18
+ expect(areGlRenderStateGuardsEnabled(state)).toBe(false);
19
+ enableGlRenderStateGuards(state);
20
+ expect(areGlRenderStateGuardsEnabled(state)).toBe(true);
21
+ });
22
+ });
23
+
24
+ describe('enableGlRenderStateGuards', () => {
25
+ it('installs the state-local multiple-root guard idempotently', () => {
26
+ const state = createState();
27
+ enableGlRenderStateGuards(state);
28
+ enableGlRenderStateGuards(state);
29
+ expect(areGlRenderStateGuardsEnabled(state)).toBe(true);
30
+ });
31
+ });
32
+
33
+ describe('foreign GL binding guard', () => {
34
+ afterEach(() => setLogSink(null));
35
+
36
+ function messages(entries: LogEntry[]): string {
37
+ return entries.map((e) => String((e.data as { message?: unknown } | undefined)?.message ?? '')).join('\n');
38
+ }
39
+
40
+ // Both directions live in ONE test on purpose: logOnce suppresses a key for the process, so a
41
+ // separate silence test would pass whether or not the guard checks anything, once the warn test has
42
+ // consumed the key. Silence is asserted FIRST, while the key is still unconsumed.
43
+ //
44
+ // render-gl skips a redundant useProgram by trusting its cache, which is only sound while it is the
45
+ // sole writer of GL state. A guest renderer that binds its own program without calling
46
+ // invalidateGlRenderStateCache breaks that, and the real symptom is a GL error blamed on a LATER
47
+ // uniform call in render-gl rather than on the renderer that changed the binding.
48
+ it('warns only when the bound program differs from the one render-gl cached', () => {
49
+ const entries: LogEntry[] = [];
50
+ setLogSink((entry) => entries.push(entry));
51
+ const state = createState();
52
+ enableGlRenderStateGuards(state);
53
+ const runtime = getGlRenderStateRuntime(state);
54
+ const cached = {} as WebGLProgram;
55
+
56
+ // Matching: GL has exactly what render-gl believes, so the skip is sound and nothing is reported.
57
+ state.gl.getParameter = vi.fn().mockReturnValue(cached) as typeof state.gl.getParameter;
58
+ runtime.bindingCacheGuard!(state, cached);
59
+ expect(messages(entries)).toBe('');
60
+
61
+ // Mismatching: a guest renderer bound something else and never restored it.
62
+ state.gl.getParameter = vi.fn().mockReturnValue({} as WebGLProgram) as typeof state.gl.getParameter;
63
+ runtime.bindingCacheGuard!(state, cached);
64
+ expect(messages(entries)).toContain('invalidateGlRenderStateCache');
65
+ });
66
+
67
+ it('installs no binding guard until the guards are enabled', () => {
68
+ expect(getGlRenderStateRuntime(createState()).bindingCacheGuard).toBeNull();
69
+ });
70
+ });
@@ -0,0 +1,58 @@
1
+ import { addLogSink, createMemoryLogSink, getMemoryLogSinkEntries, removeLogSink } from '@flighthq/log/contract';
2
+ import { createTexture } from '@flighthq/texture/contract';
3
+ import type { Image } from '@flighthq/types/contract';
4
+
5
+ import { areGlTextureResolverGuardsEnabled, enableGlTextureResolverGuards } from './enableGlTextureResolverGuards';
6
+ import { createGlState } from './glTestHelper';
7
+ import { registerGlTextureResolver, resolveGlTexture } from './glTextureResolver';
8
+
9
+ describe('areGlTextureResolverGuardsEnabled', () => {
10
+ it('reports whether diagnostics were installed for the state', () => {
11
+ const { state } = createGlState();
12
+ expect(areGlTextureResolverGuardsEnabled(state)).toBe(false);
13
+
14
+ enableGlTextureResolverGuards(state);
15
+ expect(areGlTextureResolverGuardsEnabled(state)).toBe(true);
16
+ });
17
+ });
18
+
19
+ describe('enableGlTextureResolverGuards', () => {
20
+ it('is idempotent', () => {
21
+ const { state } = createGlState();
22
+ enableGlTextureResolverGuards(state);
23
+ enableGlTextureResolverGuards(state);
24
+ expect(areGlTextureResolverGuardsEnabled(state)).toBe(true);
25
+ });
26
+
27
+ it('warns once for a missing resolver and stays silent for a registered resolver returning null', () => {
28
+ const { state } = createGlState();
29
+ const missing = textureWithKind('acme.missing.gl');
30
+ const registered = textureWithKind('acme.registered.gl');
31
+ const sink = createMemoryLogSink(4);
32
+ addLogSink(sink.sink);
33
+ enableGlTextureResolverGuards(state);
34
+ registerGlTextureResolver(state, 'acme.registered.gl', () => null);
35
+ try {
36
+ expect(resolveGlTexture(state, missing)).toBeNull();
37
+ expect(resolveGlTexture(state, missing)).toBeNull();
38
+ expect(resolveGlTexture(state, registered)).toBeNull();
39
+
40
+ const entries = getMemoryLogSinkEntries(sink);
41
+ expect(entries).toHaveLength(1);
42
+ expect(entries[0]?.data).toMatchObject({
43
+ kind: 'acme.missing.gl',
44
+ message:
45
+ 'resolveGlTexture: texture source kind has no registered resolver — call registerGlTextureResolver(state, sourceKind, resolver), or copyGlRenderStateRegistrations(offscreenState, screenState) after a late screen registration',
46
+ });
47
+ } finally {
48
+ removeLogSink(sink.sink);
49
+ }
50
+ });
51
+ });
52
+
53
+ function textureWithKind(kind: string) {
54
+ return createTexture({
55
+ dimension: '2d',
56
+ source: { kind } as Image,
57
+ });
58
+ }
@@ -0,0 +1,32 @@
1
+ import { createEntity } from '@flighthq/entity/contract';
2
+ import { createTexture } from '@flighthq/texture/contract';
3
+ import type { TextureSource } from '@flighthq/types/contract';
4
+
5
+ import { explainGlTextureResolution } from './explainGlTextureResolution';
6
+ import { createGlState } from './glTestHelper';
7
+ import { registerGlTextureResolver } from './glTextureResolver';
8
+
9
+ describe('explainGlTextureResolution', () => {
10
+ it('distinguishes missing kinds, missing resolvers, and registered resolvers', () => {
11
+ const { state } = createGlState();
12
+ const texture = createTexture({
13
+ dimension: '2d',
14
+ source: createEntity({ height: 1, kind: 'acme.test', version: 0, width: 1 }) as TextureSource,
15
+ });
16
+
17
+ expect(explainGlTextureResolution(state, createTexture())).toEqual({
18
+ kind: null,
19
+ status: 'missing-kind',
20
+ });
21
+ expect(explainGlTextureResolution(state, texture)).toEqual({
22
+ kind: 'acme.test',
23
+ status: 'missing-resolver',
24
+ });
25
+
26
+ registerGlTextureResolver(state, 'acme.test', () => null);
27
+ expect(explainGlTextureResolution(state, texture)).toEqual({
28
+ kind: 'acme.test',
29
+ status: 'registered',
30
+ });
31
+ });
32
+ });
@@ -1,3 +1,4 @@
1
+ import { srgbChannelToLinear } from '@flighthq/color/contract';
1
2
  import { BlendMode } from '@flighthq/types/contract';
2
3
 
3
4
  import { renderGlBackground } from './glBackground';
@@ -29,6 +30,15 @@ describe('renderGlBackground', () => {
29
30
  expect(gl.clear).toHaveBeenCalledWith((gl as unknown as { COLOR_BUFFER_BIT: number }).COLOR_BUFFER_BIT);
30
31
  });
31
32
 
33
+ it('preserves an active partial-target viewport origin', () => {
34
+ const { state, gl } = createGlState();
35
+ getGlRenderStateRuntime(state).renderTargetViewport = { height: 40, width: 30, x: 10, y: 20 };
36
+
37
+ renderGlBackground(state);
38
+
39
+ expect(gl.viewport).toHaveBeenLastCalledWith(10, 20, 30, 40);
40
+ });
41
+
32
42
  it('resets currentBlendMode to null', () => {
33
43
  const { state } = createGlState();
34
44
  const runtime = getGlRenderStateRuntime(state);
@@ -42,4 +52,18 @@ describe('renderGlBackground', () => {
42
52
  renderGlBackground(state);
43
53
  expect(gl.clearColor).toHaveBeenCalledWith(0.5, 0.25, 0.75, 0.8);
44
54
  });
55
+
56
+ it('decodes an sRGB background when the active target stores linear scene color', () => {
57
+ const { state, gl } = createGlState({ backgroundColorRgba: [0.5, 0.25, 0.75, 0.8] });
58
+ getGlRenderStateRuntime(state).currentRenderTarget = { colorSpace: 'linear' } as never;
59
+
60
+ renderGlBackground(state);
61
+
62
+ expect(gl.clearColor).toHaveBeenCalledWith(
63
+ srgbChannelToLinear(0.5),
64
+ srgbChannelToLinear(0.25),
65
+ srgbChannelToLinear(0.75),
66
+ 0.8,
67
+ );
68
+ });
45
69
  });
@@ -1,4 +1,5 @@
1
- import type { GlCompressedTextureSupport, ImageResource, TextureContainer } from '@flighthq/types/contract';
1
+ import type { CompressedImage, GlCompressedTextureSupport, TextureContainer } from '@flighthq/types/contract';
2
+ import { CompressedImageTextureSourceKind } from '@flighthq/types/contract';
2
3
 
3
4
  import {
4
5
  detectGlCompressedTextureSupport,
@@ -46,17 +47,14 @@ function makeContainer(): TextureContainer {
46
47
  };
47
48
  }
48
49
 
49
- // A compressed-only ImageResource wrapping makeContainer, for exercising the installed upload seam.
50
- function uploadableCompressedImage(containerOverrides?: Partial<TextureContainer>): ImageResource {
50
+ function uploadableCompressedImage(containerOverrides?: Partial<TextureContainer>): CompressedImage {
51
51
  return {
52
- source: null,
53
- data: null,
54
52
  compressed: { container: { ...makeContainer(), ...containerOverrides }, payload: new Uint8Array(16) },
55
- width: 4,
56
53
  height: 4,
54
+ kind: CompressedImageTextureSourceKind,
57
55
  version: 1,
58
- alphaType: 'straight',
59
- } as unknown as ImageResource;
56
+ width: 4,
57
+ } as unknown as CompressedImage;
60
58
  }
61
59
 
62
60
  describe('detectGlCompressedTextureSupport', () => {
@@ -140,7 +138,7 @@ describe('registerGlCompressedTextureUpload', () => {
140
138
  expect(getGlRenderStateRuntime(state).compressedTextureUpload).toBeNull();
141
139
  });
142
140
 
143
- it('uploads a compressed-only ImageResource once installed, threading the registered decoder', () => {
141
+ it('uploads a CompressedImage once installed, threading the registered decoder', () => {
144
142
  const { state, gl } = createGlState();
145
143
  const rgba = new Uint8ClampedArray(4 * 4 * 4);
146
144
  const decode = vi.fn(() => rgba);
@@ -152,14 +150,6 @@ describe('registerGlCompressedTextureUpload', () => {
152
150
  expect(decode).toHaveBeenCalledWith('bc3', 4, 4, expect.any(Uint8Array));
153
151
  });
154
152
 
155
- it('reports false for a resource with no compressed payload', () => {
156
- const { state, gl } = createGlState();
157
- registerGlCompressedTextureUpload(state);
158
- const uploader = getGlRenderStateRuntime(state).compressedTextureUpload!;
159
- const plain = { source: null, data: null, compressed: null } as unknown as ImageResource;
160
- expect(uploader(gl, plain, null)).toBe(false);
161
- });
162
-
163
153
  it('rejects non-2D containers because the installed image bridge is bound to TEXTURE_2D', () => {
164
154
  const { state } = createGlState();
165
155
  registerGlCompressedTextureUpload(state);