@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
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { explainGlRenderTexture, isGlRenderTextureReady, writeGlRenderTextureTarget } from './glRenderTexture';
|
|
2
|
+
import {
|
|
3
|
+
acquireGlRenderTexture,
|
|
4
|
+
createGlRenderTexturePool,
|
|
5
|
+
destroyGlRenderTexturePool,
|
|
6
|
+
releaseGlRenderTexture,
|
|
7
|
+
withGlRenderTextures,
|
|
8
|
+
} from './glRenderTexturePool';
|
|
9
|
+
import { createGlState } from './glTestHelper';
|
|
10
|
+
|
|
11
|
+
describe('acquireGlRenderTexture', () => {
|
|
12
|
+
it('reuses a released handle and applies current dimensions on every acquisition', () => {
|
|
13
|
+
const { state } = createGlState();
|
|
14
|
+
const pool = createGlRenderTexturePool();
|
|
15
|
+
const first = acquireGlRenderTexture(state, pool, { width: 32, height: 16 });
|
|
16
|
+
writeGlRenderTextureTarget(state, first, () => {});
|
|
17
|
+
releaseGlRenderTexture(state, pool, first);
|
|
18
|
+
|
|
19
|
+
expect(explainGlRenderTexture(state, first).status).toBe('released');
|
|
20
|
+
expect(isGlRenderTextureReady(state, first)).toBe(false);
|
|
21
|
+
|
|
22
|
+
const second = acquireGlRenderTexture(state, pool, { width: 80, height: 48 });
|
|
23
|
+
expect(second).toBe(first);
|
|
24
|
+
expect(second.source.width).toBe(80);
|
|
25
|
+
expect(second.source.height).toBe(48);
|
|
26
|
+
expect(explainGlRenderTexture(state, second).status).toBe('unrendered');
|
|
27
|
+
|
|
28
|
+
writeGlRenderTextureTarget(state, second, () => {});
|
|
29
|
+
expect(explainGlRenderTexture(state, second)).toEqual({ width: 80, height: 48, status: 'ready' });
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('resets a released slab view before exposing the next logical target', () => {
|
|
33
|
+
const { state } = createGlState();
|
|
34
|
+
const pool = createGlRenderTexturePool();
|
|
35
|
+
const slabView = acquireGlRenderTexture(state, pool, { width: 720, height: 480 });
|
|
36
|
+
slabView.flipX = true;
|
|
37
|
+
slabView.flipY = true;
|
|
38
|
+
slabView.uvOffset.x = 140 / 720;
|
|
39
|
+
slabView.uvOffset.y = 160 / 480;
|
|
40
|
+
slabView.uvRotation = Math.PI / 2;
|
|
41
|
+
slabView.uvScale.x = 100 / 720;
|
|
42
|
+
slabView.uvScale.y = 80 / 480;
|
|
43
|
+
releaseGlRenderTexture(state, pool, slabView);
|
|
44
|
+
|
|
45
|
+
const logicalTarget = acquireGlRenderTexture(state, pool, { width: 100, height: 80 });
|
|
46
|
+
|
|
47
|
+
expect(logicalTarget).toBe(slabView);
|
|
48
|
+
expect(logicalTarget).toMatchObject({
|
|
49
|
+
flipX: false,
|
|
50
|
+
flipY: false,
|
|
51
|
+
uvOffset: { x: 0, y: 0 },
|
|
52
|
+
uvRotation: 0,
|
|
53
|
+
uvScale: { x: 1, y: 1 },
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('does not allow a pool to cross WebGL contexts', () => {
|
|
58
|
+
const a = createGlState();
|
|
59
|
+
const b = createGlState();
|
|
60
|
+
const pool = createGlRenderTexturePool();
|
|
61
|
+
acquireGlRenderTexture(a.state, pool, { width: 8, height: 8 });
|
|
62
|
+
|
|
63
|
+
expect(() => acquireGlRenderTexture(b.state, pool, { width: 8, height: 8 })).toThrow('cannot cross WebGL contexts');
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('createGlRenderTexturePool', () => {
|
|
68
|
+
it('creates an empty usable pool', () => {
|
|
69
|
+
const pool = createGlRenderTexturePool();
|
|
70
|
+
expect(pool.context).toBeNull();
|
|
71
|
+
expect(pool.destroyed).toBe(false);
|
|
72
|
+
expect(pool.free).toEqual([]);
|
|
73
|
+
expect(pool.leased.size).toBe(0);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('destroyGlRenderTexturePool', () => {
|
|
78
|
+
it('destroys hidden targets for both free and outstanding leases at shutdown', () => {
|
|
79
|
+
const { state, gl } = createGlState();
|
|
80
|
+
const pool = createGlRenderTexturePool();
|
|
81
|
+
const free = acquireGlRenderTexture(state, pool, { width: 8, height: 8 });
|
|
82
|
+
const leased = acquireGlRenderTexture(state, pool, { width: 16, height: 16 });
|
|
83
|
+
writeGlRenderTextureTarget(state, free, () => {});
|
|
84
|
+
writeGlRenderTextureTarget(state, leased, () => {});
|
|
85
|
+
releaseGlRenderTexture(state, pool, free);
|
|
86
|
+
const deletes = vi.mocked(gl.deleteTexture).mock.calls.length;
|
|
87
|
+
|
|
88
|
+
destroyGlRenderTexturePool(state, pool);
|
|
89
|
+
|
|
90
|
+
expect(gl.deleteTexture).toHaveBeenCalledTimes(deletes + 2);
|
|
91
|
+
expect(pool.free).toHaveLength(0);
|
|
92
|
+
expect(pool.leased.size).toBe(0);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('rejects acquisition after destruction', () => {
|
|
96
|
+
const { state } = createGlState();
|
|
97
|
+
const pool = createGlRenderTexturePool();
|
|
98
|
+
destroyGlRenderTexturePool(state, pool);
|
|
99
|
+
expect(() => acquireGlRenderTexture(state, pool, { width: 8, height: 8 })).toThrow('has been destroyed');
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('releaseGlRenderTexture', () => {
|
|
104
|
+
it('rejects a double release', () => {
|
|
105
|
+
const { state } = createGlState();
|
|
106
|
+
const pool = createGlRenderTexturePool();
|
|
107
|
+
const texture = acquireGlRenderTexture(state, pool, { width: 8, height: 8 });
|
|
108
|
+
releaseGlRenderTexture(state, pool, texture);
|
|
109
|
+
|
|
110
|
+
expect(() => releaseGlRenderTexture(state, pool, texture)).toThrow('texture is not leased');
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('withGlRenderTextures', () => {
|
|
115
|
+
it('releases every lease when the bracket callback throws', () => {
|
|
116
|
+
const { state } = createGlState();
|
|
117
|
+
const pool = createGlRenderTexturePool();
|
|
118
|
+
|
|
119
|
+
expect(() =>
|
|
120
|
+
withGlRenderTextures(
|
|
121
|
+
state,
|
|
122
|
+
pool,
|
|
123
|
+
[
|
|
124
|
+
{ width: 8, height: 8 },
|
|
125
|
+
{ width: 8, height: 8 },
|
|
126
|
+
{ width: 8, height: 8 },
|
|
127
|
+
],
|
|
128
|
+
() => {
|
|
129
|
+
throw new Error('capture failed');
|
|
130
|
+
},
|
|
131
|
+
),
|
|
132
|
+
).toThrow('capture failed');
|
|
133
|
+
|
|
134
|
+
expect(pool.leased.size).toBe(0);
|
|
135
|
+
expect(pool.free).toHaveLength(3);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -1,20 +1,26 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createEntity } from '@flighthq/entity/contract';
|
|
2
|
+
import type { Image, RenderTexture, TextureLike, TextureSource } from '@flighthq/types/contract';
|
|
3
|
+
import {
|
|
4
|
+
BitmapTextureSourceKind,
|
|
5
|
+
CompressedImageTextureSourceKind,
|
|
6
|
+
ImageTextureSourceKind,
|
|
7
|
+
RenderTargetTextureSourceKind,
|
|
8
|
+
} from '@flighthq/types/contract';
|
|
2
9
|
|
|
3
10
|
import { getGlRenderStateRuntime } from './glRenderState';
|
|
4
11
|
import { renderIntoGlRenderTexture } from './glRenderTexture';
|
|
5
12
|
import { createGlState } from './glTestHelper';
|
|
6
13
|
import {
|
|
7
|
-
glImageTextureBackingKind,
|
|
8
|
-
glProducedTextureBackingKind,
|
|
9
|
-
glVideoTextureBackingKind,
|
|
10
14
|
registerGlImageTextureResolver,
|
|
11
|
-
|
|
15
|
+
registerGlBitmapTextureResolver,
|
|
16
|
+
registerGlCompressedImageTextureResolver,
|
|
17
|
+
registerGlRenderTextureResolver,
|
|
18
|
+
registerStandardGlTextureResolvers,
|
|
12
19
|
registerGlTextureResolver,
|
|
13
|
-
registerGlVideoTextureResolver,
|
|
14
20
|
resolveGlTexture,
|
|
15
21
|
} from './glTextureResolver';
|
|
16
22
|
|
|
17
|
-
function textureWithImage(image:
|
|
23
|
+
function textureWithImage(image: TextureSource | null): TextureLike {
|
|
18
24
|
return {
|
|
19
25
|
colorSpace: 'srgb',
|
|
20
26
|
flipX: false,
|
|
@@ -28,7 +34,8 @@ function textureWithImage(image: ImageResource | null): TextureLike {
|
|
|
28
34
|
wrapU: 'clamp-to-edge',
|
|
29
35
|
wrapV: 'clamp-to-edge',
|
|
30
36
|
},
|
|
31
|
-
|
|
37
|
+
dimension: '2d',
|
|
38
|
+
source: image,
|
|
32
39
|
uvOffset: { x: 0, y: 0 },
|
|
33
40
|
uvRotation: 0,
|
|
34
41
|
uvScale: { x: 1, y: 1 },
|
|
@@ -36,52 +43,63 @@ function textureWithImage(image: ImageResource | null): TextureLike {
|
|
|
36
43
|
} as unknown as TextureLike;
|
|
37
44
|
}
|
|
38
45
|
|
|
39
|
-
function imageResource():
|
|
46
|
+
function imageResource(source: CanvasImageSource = document.createElement('img')): Image {
|
|
40
47
|
return {
|
|
48
|
+
height: 1,
|
|
41
49
|
alphaType: 'straight',
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
gamut: 'srgb',
|
|
51
|
+
kind: ImageTextureSourceKind,
|
|
52
|
+
source,
|
|
53
|
+
version: 0,
|
|
54
|
+
width: 1,
|
|
55
|
+
} as unknown as Image;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function textureSource(kind: string): TextureSource {
|
|
59
|
+
return {
|
|
45
60
|
height: 1,
|
|
46
|
-
|
|
61
|
+
kind,
|
|
47
62
|
version: 0,
|
|
48
63
|
width: 1,
|
|
49
|
-
} as
|
|
64
|
+
} as unknown as TextureSource;
|
|
50
65
|
}
|
|
51
66
|
|
|
52
67
|
function textureWithTarget(): TextureLike {
|
|
53
68
|
const texture = textureWithImage(null);
|
|
54
69
|
texture.colorSpace = 'linear';
|
|
55
|
-
texture.
|
|
70
|
+
if (texture.dimension !== '2d') throw new Error('test texture must be 2d');
|
|
71
|
+
texture.source = createEntity({
|
|
72
|
+
colorSpace: 'linear' as const,
|
|
73
|
+
alphaType: 'straight' as const,
|
|
74
|
+
gamut: 'srgb' as const,
|
|
75
|
+
height: 8,
|
|
76
|
+
kind: RenderTargetTextureSourceKind,
|
|
77
|
+
version: 0,
|
|
78
|
+
width: 8,
|
|
79
|
+
});
|
|
56
80
|
return texture;
|
|
57
81
|
}
|
|
58
82
|
|
|
59
|
-
describe('
|
|
60
|
-
it('
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe('glProducedTextureBackingKind', () => {
|
|
67
|
-
it('matches a produced target descriptor without a texture subtype', () => {
|
|
68
|
-
expect(glProducedTextureBackingKind(textureWithTarget().storage)).toBe(true);
|
|
69
|
-
expect(glProducedTextureBackingKind(textureWithImage(null).storage)).toBe(false);
|
|
83
|
+
describe('registerGlBitmapTextureResolver', () => {
|
|
84
|
+
it('registers only the Bitmap source key', () => {
|
|
85
|
+
const { state } = createGlState();
|
|
86
|
+
registerGlBitmapTextureResolver(state);
|
|
87
|
+
expect([...getGlRenderStateRuntime(state).glTextureResolverRegistry!.keys()]).toEqual([BitmapTextureSourceKind]);
|
|
70
88
|
});
|
|
71
89
|
});
|
|
72
90
|
|
|
73
|
-
describe('
|
|
74
|
-
it('
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
expect(
|
|
78
|
-
|
|
79
|
-
|
|
91
|
+
describe('registerGlCompressedImageTextureResolver', () => {
|
|
92
|
+
it('registers only the CompressedImage source key', () => {
|
|
93
|
+
const { state } = createGlState();
|
|
94
|
+
registerGlCompressedImageTextureResolver(state);
|
|
95
|
+
expect([...getGlRenderStateRuntime(state).glTextureResolverRegistry!.keys()]).toEqual([
|
|
96
|
+
CompressedImageTextureSourceKind,
|
|
97
|
+
]);
|
|
80
98
|
});
|
|
81
99
|
});
|
|
82
100
|
|
|
83
101
|
describe('registerGlImageTextureResolver', () => {
|
|
84
|
-
it('registers the 2D image matcher and resolves through the
|
|
102
|
+
it('registers the 2D image matcher and resolves through the source-keyed upload cache', () => {
|
|
85
103
|
const { state, gl } = createGlState();
|
|
86
104
|
const texture = textureWithImage(imageResource());
|
|
87
105
|
registerGlImageTextureResolver(state);
|
|
@@ -94,17 +112,86 @@ describe('registerGlImageTextureResolver', () => {
|
|
|
94
112
|
expect(gl.texImage2D).toHaveBeenCalledOnce();
|
|
95
113
|
});
|
|
96
114
|
|
|
97
|
-
|
|
115
|
+
// The sample format comes from the PAIR (what the content is, what the destination composites in), not
|
|
116
|
+
// from an override. One sRGB texture therefore realizes two ways: decoded for a linear-working path
|
|
117
|
+
// (3D), byte-through for an encoded-working one (2D), cached apart so both can be live at once.
|
|
118
|
+
it('derives the sample format from the texture and working color spaces', () => {
|
|
119
|
+
const { state, gl } = createGlState();
|
|
120
|
+
const texture = textureWithImage(imageResource());
|
|
121
|
+
registerGlImageTextureResolver(state);
|
|
122
|
+
|
|
123
|
+
const decoded = resolveGlTexture(state, texture, false, 'linear');
|
|
124
|
+
expect(gl.texImage2D).toHaveBeenLastCalledWith(
|
|
125
|
+
gl.TEXTURE_2D,
|
|
126
|
+
0,
|
|
127
|
+
gl.SRGB8_ALPHA8,
|
|
128
|
+
gl.RGBA,
|
|
129
|
+
gl.UNSIGNED_BYTE,
|
|
130
|
+
expect.anything(),
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
const byteThrough = resolveGlTexture(state, texture, false, 'srgb');
|
|
134
|
+
expect(byteThrough).not.toBe(decoded);
|
|
135
|
+
expect(gl.texImage2D).toHaveBeenLastCalledWith(
|
|
136
|
+
gl.TEXTURE_2D,
|
|
137
|
+
0,
|
|
138
|
+
gl.RGBA,
|
|
139
|
+
gl.RGBA,
|
|
140
|
+
gl.UNSIGNED_BYTE,
|
|
141
|
+
expect.anything(),
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
// Linear content never decodes, whichever space the destination works in.
|
|
145
|
+
const linearTexture = textureWithImage(imageResource());
|
|
146
|
+
(linearTexture as { colorSpace: string }).colorSpace = 'linear';
|
|
147
|
+
resolveGlTexture(state, linearTexture, false, 'linear');
|
|
148
|
+
expect(gl.texImage2D).toHaveBeenLastCalledWith(
|
|
149
|
+
gl.TEXTURE_2D,
|
|
150
|
+
0,
|
|
151
|
+
gl.RGBA,
|
|
152
|
+
gl.RGBA,
|
|
153
|
+
gl.UNSIGNED_BYTE,
|
|
154
|
+
expect.anything(),
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
expect(resolveGlTexture(state, texture, false, 'linear')).toBe(decoded);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('returns null for an unbound image source', () => {
|
|
98
161
|
const { state } = createGlState();
|
|
99
162
|
registerGlImageTextureResolver(state);
|
|
100
163
|
expect(resolveGlTexture(state, textureWithImage(null))).toBeNull();
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('uploads a host video through the image source kind and gates by version', () => {
|
|
167
|
+
const { state, gl } = createGlState();
|
|
168
|
+
const video = imageResource({
|
|
169
|
+
readyState: 4,
|
|
170
|
+
videoHeight: 240,
|
|
171
|
+
videoWidth: 320,
|
|
172
|
+
} as HTMLVideoElement);
|
|
173
|
+
const texture = textureWithImage(video);
|
|
174
|
+
registerGlImageTextureResolver(state);
|
|
175
|
+
|
|
176
|
+
const first = resolveGlTexture(state, texture);
|
|
177
|
+
const uploads = (gl.texImage2D as ReturnType<typeof vi.fn>).mock.calls.length;
|
|
178
|
+
const second = resolveGlTexture(state, texture);
|
|
179
|
+
|
|
180
|
+
expect(first).not.toBeNull();
|
|
181
|
+
expect(second).toBe(first);
|
|
182
|
+
expect(gl.texImage2D).toHaveBeenCalledWith(
|
|
183
|
+
gl.TEXTURE_2D,
|
|
184
|
+
0,
|
|
185
|
+
gl.SRGB8_ALPHA8,
|
|
186
|
+
gl.RGBA,
|
|
187
|
+
gl.UNSIGNED_BYTE,
|
|
188
|
+
video.source,
|
|
189
|
+
);
|
|
190
|
+
expect(gl.texImage2D).toHaveBeenCalledTimes(uploads);
|
|
104
191
|
});
|
|
105
192
|
});
|
|
106
193
|
|
|
107
|
-
describe('
|
|
194
|
+
describe('registerGlRenderTextureResolver', () => {
|
|
108
195
|
it('returns the hidden color attachment without uploading CPU pixels', () => {
|
|
109
196
|
const { state, gl } = createGlState();
|
|
110
197
|
const previous = vi.mocked(gl.getParameter).getMockImplementation();
|
|
@@ -113,8 +200,8 @@ describe('registerGlProducedTextureResolver', () => {
|
|
|
113
200
|
return previous?.(parameter);
|
|
114
201
|
});
|
|
115
202
|
const texture = textureWithTarget();
|
|
116
|
-
renderIntoGlRenderTexture(state, texture as
|
|
117
|
-
|
|
203
|
+
renderIntoGlRenderTexture(state, texture as RenderTexture, () => {});
|
|
204
|
+
registerGlRenderTextureResolver(state);
|
|
118
205
|
const uploads = vi.mocked(gl.texImage2D).mock.calls.length;
|
|
119
206
|
|
|
120
207
|
expect(resolveGlTexture(state, texture)).not.toBeNull();
|
|
@@ -123,58 +210,50 @@ describe('registerGlProducedTextureResolver', () => {
|
|
|
123
210
|
});
|
|
124
211
|
|
|
125
212
|
describe('registerGlTextureResolver', () => {
|
|
126
|
-
it('keeps registrations state-scoped, replaces by
|
|
213
|
+
it('keeps registrations state-scoped, replaces by string kind, and removes with null', () => {
|
|
127
214
|
const { state: a } = createGlState();
|
|
128
215
|
const { state: b } = createGlState();
|
|
129
|
-
const
|
|
216
|
+
const sourceKind = 'acme.generated';
|
|
130
217
|
const first = vi.fn(() => ({ first: true }) as unknown as WebGLTexture);
|
|
131
218
|
const second = vi.fn(() => ({ second: true }) as unknown as WebGLTexture);
|
|
132
|
-
const
|
|
219
|
+
const source = textureSource(sourceKind);
|
|
220
|
+
const texture = textureWithImage(source);
|
|
133
221
|
|
|
134
|
-
registerGlTextureResolver(a,
|
|
222
|
+
registerGlTextureResolver(a, sourceKind, first);
|
|
135
223
|
expect(resolveGlTexture(a, texture)).not.toBeNull();
|
|
136
224
|
expect(resolveGlTexture(b, texture)).toBeNull();
|
|
137
225
|
|
|
138
|
-
registerGlTextureResolver(a,
|
|
226
|
+
registerGlTextureResolver(a, sourceKind, second);
|
|
139
227
|
expect(resolveGlTexture(a, texture)).toEqual({ second: true });
|
|
140
|
-
expect(getGlRenderStateRuntime(a).glTextureResolverRegistry).
|
|
228
|
+
expect(getGlRenderStateRuntime(a).glTextureResolverRegistry?.size).toBe(1);
|
|
141
229
|
|
|
142
|
-
registerGlTextureResolver(a,
|
|
230
|
+
registerGlTextureResolver(a, sourceKind, null);
|
|
143
231
|
expect(resolveGlTexture(a, texture)).toBeNull();
|
|
144
232
|
});
|
|
145
233
|
|
|
146
|
-
it('
|
|
234
|
+
it('uses one exact keyed lookup and does not fall through to another kind', () => {
|
|
147
235
|
const { state } = createGlState();
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
registerGlTextureResolver(state,
|
|
151
|
-
|
|
152
|
-
expect(resolveGlTexture(state, textureWithImage(null))).toEqual({ kind: 'specific' });
|
|
236
|
+
const image = textureSource('acme.specific');
|
|
237
|
+
registerGlTextureResolver(state, 'image', () => ({ kind: 'image' }) as unknown as WebGLTexture);
|
|
238
|
+
registerGlTextureResolver(state, 'acme.specific', () => ({ kind: 'specific' }) as unknown as WebGLTexture);
|
|
239
|
+
expect(resolveGlTexture(state, textureWithImage(image))).toEqual({ kind: 'specific' });
|
|
153
240
|
});
|
|
154
241
|
});
|
|
155
242
|
|
|
156
|
-
describe('
|
|
157
|
-
it('
|
|
158
|
-
const { state
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const first = resolveGlTexture(state, texture);
|
|
166
|
-
const uploads = (gl.texImage2D as ReturnType<typeof vi.fn>).mock.calls.length;
|
|
167
|
-
const second = resolveGlTexture(state, texture);
|
|
168
|
-
|
|
169
|
-
expect(first).not.toBeNull();
|
|
170
|
-
expect(second).toBe(first);
|
|
171
|
-
expect(gl.texImage2D).toHaveBeenCalledWith(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, video.source);
|
|
172
|
-
expect(gl.texImage2D).toHaveBeenCalledTimes(uploads);
|
|
243
|
+
describe('registerStandardGlTextureResolvers', () => {
|
|
244
|
+
it('registers bitmap, image, and render texture sources without compressed images', () => {
|
|
245
|
+
const { state } = createGlState();
|
|
246
|
+
registerStandardGlTextureResolvers(state);
|
|
247
|
+
expect([...getGlRenderStateRuntime(state).glTextureResolverRegistry!.keys()]).toEqual([
|
|
248
|
+
BitmapTextureSourceKind,
|
|
249
|
+
ImageTextureSourceKind,
|
|
250
|
+
RenderTargetTextureSourceKind,
|
|
251
|
+
]);
|
|
173
252
|
});
|
|
174
253
|
});
|
|
175
254
|
|
|
176
255
|
describe('resolveGlTexture', () => {
|
|
177
|
-
it('returns null when the state has no registered
|
|
256
|
+
it('returns null when the state has no registered source resolver', () => {
|
|
178
257
|
const { state } = createGlState();
|
|
179
258
|
expect(resolveGlTexture(state, textureWithImage(imageResource()))).toBeNull();
|
|
180
259
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Image } from '@flighthq/types/contract';
|
|
2
2
|
|
|
3
3
|
import { uploadGlTextureData, uploadGlTextureElement, uploadGlTextureImageResource } from './glTextureUpload';
|
|
4
4
|
|
|
@@ -34,16 +34,8 @@ describe('uploadGlTextureImageResource', () => {
|
|
|
34
34
|
it('takes the element path when the resource carries a source', () => {
|
|
35
35
|
const gl = makeGl();
|
|
36
36
|
const source = {} as TexImageSource;
|
|
37
|
-
const image = { source,
|
|
37
|
+
const image = { source, width: 4, height: 4 } as unknown as Image;
|
|
38
38
|
uploadGlTextureImageResource(gl, gl.TEXTURE_2D, image);
|
|
39
39
|
expect(gl.texImage2D).toHaveBeenCalledWith(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
|
|
40
40
|
});
|
|
41
|
-
|
|
42
|
-
it('takes the raw-pixel path when the resource is data-only', () => {
|
|
43
|
-
const gl = makeGl();
|
|
44
|
-
const data = new Uint8ClampedArray(4 * 4 * 4);
|
|
45
|
-
const image = { source: null, data, width: 4, height: 4 } as ImageResource;
|
|
46
|
-
uploadGlTextureImageResource(gl, gl.TEXTURE_2D, image);
|
|
47
|
-
expect(gl.texImage2D).toHaveBeenCalledWith(gl.TEXTURE_2D, 0, gl.RGBA, 4, 4, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
|
|
48
|
-
});
|
|
49
41
|
});
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Image } from '@flighthq/types/contract';
|
|
2
2
|
|
|
3
3
|
import { uploadGlTextureVideoFrame } from './glTextureVideoUpload';
|
|
4
4
|
|
|
5
5
|
function makeGl(): WebGL2RenderingContext {
|
|
6
6
|
return {
|
|
7
7
|
RGBA: 0x1908,
|
|
8
|
+
SRGB8_ALPHA8: 0x8c43,
|
|
8
9
|
UNSIGNED_BYTE: 0x1401,
|
|
9
10
|
TEXTURE_2D: 0x0de1,
|
|
10
11
|
texImage2D: vi.fn(),
|
|
11
12
|
} as unknown as WebGL2RenderingContext;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
// A video
|
|
15
|
-
function makeVideoImage(version: number, readyState = 4, videoWidth = 320, videoHeight = 240):
|
|
15
|
+
// A video Image whose only relevant fields are version and the borrowed host element.
|
|
16
|
+
function makeVideoImage(version: number, readyState = 4, videoWidth = 320, videoHeight = 240): Image {
|
|
16
17
|
return {
|
|
17
18
|
source: { readyState, videoWidth, videoHeight } as unknown as HTMLVideoElement,
|
|
18
19
|
version,
|
|
19
|
-
} as unknown as
|
|
20
|
+
} as unknown as Image;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
describe('uploadGlTextureVideoFrame', () => {
|
|
@@ -28,6 +29,20 @@ describe('uploadGlTextureVideoFrame', () => {
|
|
|
28
29
|
expect(gl.texImage2D).toHaveBeenCalledWith(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image.source);
|
|
29
30
|
});
|
|
30
31
|
|
|
32
|
+
it('threads an explicit sRGB internal format to the video upload', () => {
|
|
33
|
+
const gl = makeGl();
|
|
34
|
+
const image = makeVideoImage(3);
|
|
35
|
+
uploadGlTextureVideoFrame(gl, image, -1, gl.SRGB8_ALPHA8);
|
|
36
|
+
expect(gl.texImage2D).toHaveBeenCalledWith(
|
|
37
|
+
gl.TEXTURE_2D,
|
|
38
|
+
0,
|
|
39
|
+
gl.SRGB8_ALPHA8,
|
|
40
|
+
gl.RGBA,
|
|
41
|
+
gl.UNSIGNED_BYTE,
|
|
42
|
+
image.source,
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
|
|
31
46
|
it('skips the upload and returns the same id when the frame has not advanced', () => {
|
|
32
47
|
const gl = makeGl();
|
|
33
48
|
const image = makeVideoImage(5);
|
|
@@ -46,7 +61,7 @@ describe('uploadGlTextureVideoFrame', () => {
|
|
|
46
61
|
|
|
47
62
|
it('skips when the element is null', () => {
|
|
48
63
|
const gl = makeGl();
|
|
49
|
-
const image = { source: null, version: 2 } as unknown as
|
|
64
|
+
const image = { source: null, version: 2 } as unknown as Image;
|
|
50
65
|
expect(uploadGlTextureVideoFrame(gl, image, -1)).toBe(-1);
|
|
51
66
|
expect(gl.texImage2D).not.toHaveBeenCalled();
|
|
52
67
|
});
|