@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.
- package/dist/contract.d.ts +5 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +5 -0
- package/dist/contract.js.map +1 -1
- package/dist/enableGlRenderStateGuards.d.ts +4 -0
- package/dist/enableGlRenderStateGuards.d.ts.map +1 -0
- package/dist/enableGlRenderStateGuards.js +52 -0
- package/dist/enableGlRenderStateGuards.js.map +1 -0
- package/dist/enableGlRenderTextureGuards.d.ts.map +1 -1
- package/dist/enableGlRenderTextureGuards.js +2 -2
- package/dist/enableGlRenderTextureGuards.js.map +1 -1
- package/dist/enableGlTextureResolverGuards.d.ts +4 -0
- package/dist/enableGlTextureResolverGuards.d.ts.map +1 -0
- package/dist/enableGlTextureResolverGuards.js +8 -0
- package/dist/enableGlTextureResolverGuards.js.map +1 -0
- package/dist/explainGlTextureResolution.d.ts +3 -0
- package/dist/explainGlTextureResolution.d.ts.map +1 -0
- package/dist/explainGlTextureResolution.js +12 -0
- package/dist/explainGlTextureResolution.js.map +1 -0
- package/dist/glBackground.d.ts.map +1 -1
- package/dist/glBackground.js +5 -3
- package/dist/glBackground.js.map +1 -1
- package/dist/glCompressedTexture.d.ts +2 -2
- package/dist/glCompressedTexture.d.ts.map +1 -1
- package/dist/glCompressedTexture.js +46 -17
- package/dist/glCompressedTexture.js.map +1 -1
- package/dist/glDraw.d.ts +4 -2
- package/dist/glDraw.d.ts.map +1 -1
- package/dist/glDraw.js +100 -65
- package/dist/glDraw.js.map +1 -1
- package/dist/glExternalTexture.d.ts +4 -0
- package/dist/glExternalTexture.d.ts.map +1 -0
- package/dist/glExternalTexture.js +46 -0
- package/dist/glExternalTexture.js.map +1 -0
- package/dist/glFullscreenPass.js +5 -6
- package/dist/glFullscreenPass.js.map +1 -1
- package/dist/glLinearToSrgbPass.js +3 -3
- package/dist/glLinearToSrgbPass.js.map +1 -1
- package/dist/glMaterialRegistry.d.ts.map +1 -1
- package/dist/glMaterialRegistry.js +12 -10
- package/dist/glMaterialRegistry.js.map +1 -1
- package/dist/glPresentRenderTarget.js +3 -3
- package/dist/glPresentRenderTarget.js.map +1 -1
- package/dist/glRenderPass.d.ts +2 -2
- package/dist/glRenderPass.d.ts.map +1 -1
- package/dist/glRenderPass.js +193 -33
- package/dist/glRenderPass.js.map +1 -1
- package/dist/glRenderState.d.ts +11 -1
- package/dist/glRenderState.d.ts.map +1 -1
- package/dist/glRenderState.js +206 -22
- package/dist/glRenderState.js.map +1 -1
- package/dist/glRenderStateBracket.d.ts.map +1 -1
- package/dist/glRenderStateBracket.js +16 -4
- package/dist/glRenderStateBracket.js.map +1 -1
- package/dist/glRenderTarget.d.ts +10 -1
- package/dist/glRenderTarget.d.ts.map +1 -1
- package/dist/glRenderTarget.js +154 -69
- package/dist/glRenderTarget.js.map +1 -1
- package/dist/glRenderTargetPool.d.ts +4 -1
- package/dist/glRenderTargetPool.d.ts.map +1 -1
- package/dist/glRenderTargetPool.js +32 -23
- package/dist/glRenderTargetPool.js.map +1 -1
- package/dist/glRenderTexture.d.ts +13 -8
- package/dist/glRenderTexture.d.ts.map +1 -1
- package/dist/glRenderTexture.js +94 -37
- package/dist/glRenderTexture.js.map +1 -1
- package/dist/glRenderTexturePool.d.ts +7 -0
- package/dist/glRenderTexturePool.d.ts.map +1 -0
- package/dist/glRenderTexturePool.js +88 -0
- package/dist/glRenderTexturePool.js.map +1 -0
- package/dist/glTestHelper.d.ts.map +1 -1
- package/dist/glTestHelper.js +12 -8
- package/dist/glTestHelper.js.map +1 -1
- package/dist/glTextureResolver.d.ts +7 -8
- package/dist/glTextureResolver.d.ts.map +1 -1
- package/dist/glTextureResolver.js +57 -55
- package/dist/glTextureResolver.js.map +1 -1
- package/dist/glTextureUpload.d.ts +4 -4
- package/dist/glTextureUpload.d.ts.map +1 -1
- package/dist/glTextureUpload.js +8 -14
- package/dist/glTextureUpload.js.map +1 -1
- package/dist/glTextureVideoUpload.d.ts +2 -2
- package/dist/glTextureVideoUpload.d.ts.map +1 -1
- package/dist/glTextureVideoUpload.js +5 -5
- package/dist/glTextureVideoUpload.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +12 -6
- package/src/enableGlRenderStateGuards.test.ts +70 -0
- package/src/enableGlTextureResolverGuards.test.ts +58 -0
- package/src/explainGlTextureResolution.test.ts +32 -0
- package/src/glBackground.test.ts +24 -0
- package/src/glCompressedTexture.test.ts +7 -17
- package/src/glDraw.test.ts +172 -80
- package/src/glExternalTexture.test.ts +30 -0
- package/src/glFullscreenPass.test.ts +15 -2
- package/src/glLinearToSrgbPass.test.ts +13 -0
- package/src/glMaterialRegistry.test.ts +42 -1
- package/src/glPresentRenderTarget.test.ts +15 -1
- package/src/glReadback.test.ts +13 -0
- package/src/glRenderPass.test.ts +257 -5
- package/src/glRenderState.test.ts +136 -1
- package/src/glRenderStateBracket.test.ts +31 -1
- package/src/glRenderTarget.test.ts +244 -3
- package/src/glRenderTargetPool.test.ts +110 -5
- package/src/glRenderTexture.test.ts +88 -14
- package/src/glRenderTexturePool.test.ts +137 -0
- package/src/glTextureResolver.test.ts +151 -72
- package/src/glTextureUpload.test.ts +2 -10
- package/src/glTextureVideoUpload.test.ts +20 -5
|
@@ -1,70 +1,72 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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,
|
|
13
|
+
registerGlTextureResolver(state, ImageTextureSourceKind, resolveGlImageTexture);
|
|
20
14
|
}
|
|
21
|
-
// Installs the
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
27
|
-
//
|
|
28
|
-
export function registerGlTextureResolver(state,
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
export function registerStandardGlTextureResolvers(state) {
|
|
30
|
+
registerGlBitmapTextureResolver(state);
|
|
31
|
+
registerGlImageTextureResolver(state);
|
|
32
|
+
registerGlRenderTextureResolver(state);
|
|
41
33
|
}
|
|
42
|
-
// Resolves through the
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
|
53
|
+
return resolver(state, texture, premultiply, getTextureSampleColorSpace(texture.colorSpace, workingColorSpace));
|
|
54
54
|
}
|
|
55
|
-
function
|
|
56
|
-
const
|
|
57
|
-
|
|
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
|
|
62
|
-
|
|
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
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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":"
|
|
1
|
+
{"version":3,"file":"glTextureResolver.js","sourceRoot":"","sources":["../src/glTextureResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAahH,OAAO,EACL,uBAAuB,EACvB,gCAAgC,EAChC,sBAAsB,EACtB,cAAc,EACd,6BAA6B,GAC9B,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AACzG,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,MAAM,UAAU,+BAA+B,CAAC,KAAoB;IAClE,yBAAyB,CAAC,KAAK,EAAE,uBAAuB,EAAE,sBAAsB,CAAC,CAAC;AACpF,CAAC;AAED,MAAM,UAAU,wCAAwC,CAAC,KAAoB;IAC3E,yBAAyB,CAAC,KAAK,EAAE,gCAAgC,EAAE,+BAA+B,CAAC,CAAC;AACtG,CAAC;AAED,MAAM,UAAU,8BAA8B,CAAC,KAAoB;IACjE,yBAAyB,CAAC,KAAK,EAAE,sBAAsB,EAAE,qBAAqB,CAAC,CAAC;AAClF,CAAC;AAED,0CAA0C;AAC1C,MAAM,UAAU,+BAA+B,CAAC,KAAoB;IAClE,yBAAyB,CAAC,KAAK,EAAE,6BAA6B,EAAE,sBAAsB,CAAC,CAAC;AAC1F,CAAC;AAED,2FAA2F;AAC3F,kGAAkG;AAClG,MAAM,UAAU,yBAAyB,CACvC,KAAoB,EACpB,UAA6B,EAC7B,QAAkC;IAElC,MAAM,OAAO,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,yBAAyB,KAAK,IAAI,GAAG,EAAE,CAAC,CAAC;IACnE,IAAI,QAAQ,KAAK,IAAI;QAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;;QAC9C,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,kCAAkC,CAAC,KAAoB;IACrE,+BAA+B,CAAC,KAAK,CAAC,CAAC;IACvC,8BAA8B,CAAC,KAAK,CAAC,CAAC;IACtC,+BAA+B,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC;AAED,qGAAqG;AACrG,wGAAwG;AACxG,oGAAoG;AACpG,qGAAqG;AACrG,wFAAwF;AACxF,mGAAmG;AACnG,uGAAuG;AACvG,sGAAsG;AACtG,uGAAuG;AACvG,MAAM,UAAU,gBAAgB,CAC9B,KAAoB,EACpB,OAA8B,EAC9B,WAAW,GAAG,KAAK,EACnB,oBAA4C,QAAQ;IAEpD,MAAM,UAAU,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;IACjD,IAAI,UAAU,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACrC,MAAM,OAAO,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,OAAO,CAAC,yBAAyB,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;IACpE,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,CAAC,YAAY,EAAE,CAAC,cAAc,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;QACnE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,0BAA0B,CAAC,OAAO,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC;AAClH,CAAC;AAED,SAAS,sBAAsB,CAC7B,KAAoB,EACpB,OAA8B,EAC9B,WAAoB,EACpB,UAA6B;IAE7B,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAA4B,CAAC;IACpE,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,WAAW,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 {
|
|
2
|
-
export declare function uploadGlTextureData(gl: WebGL2RenderingContext, target: number, width: number, height: number, data: Readonly<Uint8ClampedArray<ArrayBuffer
|
|
3
|
-
export declare function uploadGlTextureElement(gl: WebGL2RenderingContext, target: number, source: TexImageSource): void;
|
|
4
|
-
export declare function uploadGlTextureImageResource(gl: WebGL2RenderingContext, target: number, image: Readonly<
|
|
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,
|
|
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"}
|
package/dist/glTextureUpload.js
CHANGED
|
@@ -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
|
|
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,
|
|
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,
|
|
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
|
-
//
|
|
18
|
-
|
|
19
|
-
|
|
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,
|
|
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 {
|
|
2
|
-
export declare function uploadGlTextureVideoFrame(gl: WebGL2RenderingContext, image: Readonly<
|
|
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,
|
|
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
|
|
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
|
|
6
|
-
//
|
|
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,
|
|
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,
|
|
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
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,
|
|
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,
|
|
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,
|
|
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.
|
|
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/
|
|
40
|
-
"@flighthq/
|
|
41
|
-
"@flighthq/
|
|
42
|
-
"@flighthq/
|
|
43
|
-
"@flighthq/
|
|
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
|
+
});
|
package/src/glBackground.test.ts
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
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
|
-
|
|
59
|
-
} as unknown as
|
|
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
|
|
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);
|