@flighthq/render-gl 0.2.1-next.841.373388f → 0.3.0-next.1032.e2b99fc
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 +25 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +25 -0
- package/dist/contract.js.map +1 -0
- package/dist/enableGlRenderTextureGuards.d.ts +4 -0
- package/dist/enableGlRenderTextureGuards.d.ts.map +1 -0
- package/dist/enableGlRenderTextureGuards.js +34 -0
- package/dist/enableGlRenderTextureGuards.js.map +1 -0
- package/dist/glBackground.d.ts +1 -1
- package/dist/glBackground.d.ts.map +1 -1
- package/dist/glBackground.js +2 -2
- package/dist/glBackground.js.map +1 -1
- package/dist/glCompressedTexture.d.ts +1 -1
- package/dist/glCompressedTexture.d.ts.map +1 -1
- package/dist/glCompressedTexture.js +8 -13
- package/dist/glCompressedTexture.js.map +1 -1
- package/dist/glDraw.d.ts +6 -3
- package/dist/glDraw.d.ts.map +1 -1
- package/dist/glDraw.js +94 -107
- 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 +41 -0
- package/dist/glExternalTexture.js.map +1 -0
- package/dist/glFullscreenPass.d.ts +1 -1
- package/dist/glFullscreenPass.d.ts.map +1 -1
- package/dist/glFullscreenPass.js +2 -2
- package/dist/glFullscreenPass.js.map +1 -1
- package/dist/glLinearToSrgbPass.d.ts +1 -1
- package/dist/glLinearToSrgbPass.d.ts.map +1 -1
- package/dist/glMaterialRegistry.d.ts +1 -1
- package/dist/glMaterialRegistry.d.ts.map +1 -1
- package/dist/glMaterialRegistry.js +3 -3
- package/dist/glMaterialRegistry.js.map +1 -1
- package/dist/glPresentRenderTarget.d.ts +1 -1
- package/dist/glPresentRenderTarget.d.ts.map +1 -1
- package/dist/glReadback.d.ts +1 -1
- package/dist/glReadback.d.ts.map +1 -1
- package/dist/glRenderPass.d.ts +2 -2
- package/dist/glRenderPass.d.ts.map +1 -1
- package/dist/glRenderPass.js +136 -22
- package/dist/glRenderPass.js.map +1 -1
- package/dist/glRenderState.d.ts +1 -1
- package/dist/glRenderState.d.ts.map +1 -1
- package/dist/glRenderState.js +30 -27
- package/dist/glRenderState.js.map +1 -1
- package/dist/glRenderStateBracket.d.ts +5 -0
- package/dist/glRenderStateBracket.d.ts.map +1 -0
- package/dist/glRenderStateBracket.js +111 -0
- package/dist/glRenderStateBracket.js.map +1 -0
- package/dist/glRenderTarget.d.ts +1 -1
- package/dist/glRenderTarget.d.ts.map +1 -1
- package/dist/glRenderTarget.js +26 -10
- package/dist/glRenderTarget.js.map +1 -1
- package/dist/glRenderTargetPool.d.ts +1 -1
- package/dist/glRenderTargetPool.d.ts.map +1 -1
- package/dist/glRenderTargetPool.js.map +1 -1
- package/dist/glRenderTexture.d.ts +13 -0
- package/dist/glRenderTexture.d.ts.map +1 -0
- package/dist/glRenderTexture.js +109 -0
- package/dist/glRenderTexture.js.map +1 -0
- package/dist/glShader.d.ts +2 -2
- package/dist/glShader.d.ts.map +1 -1
- package/dist/glShaderBinding.d.ts +2 -2
- package/dist/glShaderBinding.d.ts.map +1 -1
- package/dist/glShaderBinding.js +2 -2
- package/dist/glShaderBinding.js.map +1 -1
- package/dist/glShaderRegistry.d.ts +2 -2
- package/dist/glShaderRegistry.d.ts.map +1 -1
- package/dist/glSkinPaletteTexture.d.ts +1 -1
- package/dist/glSkinPaletteTexture.d.ts.map +1 -1
- package/dist/glTestHelper.d.ts +2 -2
- package/dist/glTestHelper.d.ts.map +1 -1
- package/dist/glTestHelper.js +16 -13
- package/dist/glTestHelper.js.map +1 -1
- package/dist/glTextureResolver.d.ts +9 -0
- package/dist/glTextureResolver.d.ts.map +1 -0
- package/dist/glTextureResolver.js +68 -0
- package/dist/glTextureResolver.js.map +1 -0
- package/dist/glTextureUpload.d.ts +1 -1
- package/dist/glTextureUpload.d.ts.map +1 -1
- package/dist/glTextureUpload.js +3 -9
- 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 +10 -10
- package/dist/glTextureVideoUpload.js.map +1 -1
- package/dist/index.d.ts +1 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -19
- package/dist/index.js.map +1 -1
- package/package.json +11 -5
- package/src/enableGlRenderTextureGuards.test.ts +22 -0
- package/src/glBackground.test.ts +10 -1
- package/src/glCompressedTexture.test.ts +7 -17
- package/src/glDraw.test.ts +130 -79
- package/src/glExternalTexture.test.ts +30 -0
- package/src/glFullscreenPass.test.ts +4 -4
- package/src/glLinearToSrgbPass.test.ts +1 -1
- package/src/glMaterialRegistry.test.ts +4 -4
- package/src/glPresentRenderTarget.test.ts +1 -1
- package/src/glReadback.test.ts +1 -1
- package/src/glRenderPass.test.ts +145 -6
- package/src/glRenderState.test.ts +2 -2
- package/src/glRenderStateBracket.test.ts +319 -0
- package/src/glRenderTarget.test.ts +61 -3
- package/src/glRenderTexture.test.ts +252 -0
- package/src/glShader.test.ts +25 -25
- package/src/glShaderBinding.test.ts +2 -2
- package/src/glSkinPaletteTexture.test.ts +1 -1
- package/src/glTextureResolver.test.ts +182 -0
- package/src/glTextureUpload.test.ts +2 -10
- package/src/glTextureVideoUpload.test.ts +15 -15
package/src/glShader.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityRuntimeKey } from '@flighthq/types';
|
|
1
|
+
import { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
compileDefaultGlProgram,
|
|
@@ -89,12 +89,12 @@ describe('createDefaultGlBitmapShader', () => {
|
|
|
89
89
|
expect(typeof shader.bind).toBe('function');
|
|
90
90
|
});
|
|
91
91
|
|
|
92
|
-
it('does not bind color
|
|
92
|
+
it('does not bind color adjustment uniforms for the default shader', () => {
|
|
93
93
|
const gl = makeGL();
|
|
94
94
|
const loc = makeShaderLoc();
|
|
95
|
-
loc.
|
|
96
|
-
loc.
|
|
97
|
-
loc.
|
|
95
|
+
loc.locColorScale = undefined;
|
|
96
|
+
loc.locColorBias = undefined;
|
|
97
|
+
loc.locHasColorScaleBias = undefined;
|
|
98
98
|
const m = new Float32Array(9);
|
|
99
99
|
const canvas = document.createElement('canvas');
|
|
100
100
|
canvas.width = 100;
|
|
@@ -102,18 +102,18 @@ describe('createDefaultGlBitmapShader', () => {
|
|
|
102
102
|
const shader = createDefaultGlBitmapShader(loc, m);
|
|
103
103
|
const renderProxy = {
|
|
104
104
|
alpha: 0.75,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
105
|
+
colorScaleBias: {
|
|
106
|
+
redScale: 0.5,
|
|
107
|
+
greenScale: 0.25,
|
|
108
|
+
blueScale: 1.5,
|
|
109
|
+
alphaScale: 0.8,
|
|
110
|
+
redBias: 10,
|
|
111
|
+
greenBias: 20,
|
|
112
|
+
blueBias: 30,
|
|
113
|
+
alphaBias: 40,
|
|
114
114
|
},
|
|
115
115
|
transform2D: { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 },
|
|
116
|
-
|
|
116
|
+
useColorScaleBias: true,
|
|
117
117
|
};
|
|
118
118
|
|
|
119
119
|
shader.bind(gl, { canvas, [EntityRuntimeKey]: { renderTargetViewport: null } } as never, renderProxy as never);
|
|
@@ -213,17 +213,17 @@ describe('setGlBaseUniforms', () => {
|
|
|
213
213
|
const loc = makeShaderLoc();
|
|
214
214
|
const renderProxy = {
|
|
215
215
|
alpha: 1,
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
216
|
+
colorScaleBias: {
|
|
217
|
+
redScale: 0.2,
|
|
218
|
+
greenScale: 0.4,
|
|
219
|
+
blueScale: 0.6,
|
|
220
|
+
alphaScale: 0.8,
|
|
221
|
+
redBias: 25.5,
|
|
222
|
+
greenBias: 51,
|
|
223
|
+
blueBias: 76.5,
|
|
224
|
+
alphaBias: 102,
|
|
225
225
|
},
|
|
226
|
-
|
|
226
|
+
useColorScaleBias: true,
|
|
227
227
|
};
|
|
228
228
|
|
|
229
229
|
setGlBaseUniforms(gl, loc, renderProxy as never);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getOrCreateRenderProxy2D } from '@flighthq/render';
|
|
2
|
-
import type { Node2D, Kind } from '@flighthq/types';
|
|
1
|
+
import { getOrCreateRenderProxy2D } from '@flighthq/render/contract';
|
|
2
|
+
import type { Node2D, Kind } from '@flighthq/types/contract';
|
|
3
3
|
|
|
4
4
|
import { getGlRenderStateRuntime } from './glRenderState';
|
|
5
5
|
import {
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import type { ImageResource, RenderTexture, TextureLike } from '@flighthq/types/contract';
|
|
2
|
+
import {
|
|
3
|
+
BitmapTextureBackingKind,
|
|
4
|
+
CompressedImageTextureBackingKind,
|
|
5
|
+
ImageTextureBackingKind,
|
|
6
|
+
RenderTextureBackingKind,
|
|
7
|
+
VideoTextureBackingKind,
|
|
8
|
+
} from '@flighthq/types/contract';
|
|
9
|
+
|
|
10
|
+
import { getGlRenderStateRuntime } from './glRenderState';
|
|
11
|
+
import { renderIntoGlRenderTexture } from './glRenderTexture';
|
|
12
|
+
import { createGlState } from './glTestHelper';
|
|
13
|
+
import {
|
|
14
|
+
registerGlImageTextureResolver,
|
|
15
|
+
registerGlBitmapTextureResolver,
|
|
16
|
+
registerGlCompressedImageTextureResolver,
|
|
17
|
+
registerGlRenderTextureResolver,
|
|
18
|
+
registerGlTextureResolver,
|
|
19
|
+
registerGlVideoTextureResolver,
|
|
20
|
+
resolveGlTexture,
|
|
21
|
+
} from './glTextureResolver';
|
|
22
|
+
|
|
23
|
+
function textureWithImage(image: ImageResource | null): TextureLike {
|
|
24
|
+
return {
|
|
25
|
+
colorSpace: 'srgb',
|
|
26
|
+
flipX: false,
|
|
27
|
+
flipY: false,
|
|
28
|
+
resource: null,
|
|
29
|
+
sampler: {
|
|
30
|
+
anisotropy: 1,
|
|
31
|
+
magFilter: 'linear',
|
|
32
|
+
minFilter: 'linear',
|
|
33
|
+
mipmaps: false,
|
|
34
|
+
wrapU: 'clamp-to-edge',
|
|
35
|
+
wrapV: 'clamp-to-edge',
|
|
36
|
+
},
|
|
37
|
+
storage: { dimension: '2d', image },
|
|
38
|
+
uvOffset: { x: 0, y: 0 },
|
|
39
|
+
uvRotation: 0,
|
|
40
|
+
uvScale: { x: 1, y: 1 },
|
|
41
|
+
version: 0,
|
|
42
|
+
} as unknown as TextureLike;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function imageResource(
|
|
46
|
+
source: CanvasImageSource = document.createElement('img'),
|
|
47
|
+
kind = ImageTextureBackingKind,
|
|
48
|
+
): ImageResource {
|
|
49
|
+
return {
|
|
50
|
+
height: 1,
|
|
51
|
+
kind,
|
|
52
|
+
source,
|
|
53
|
+
version: 0,
|
|
54
|
+
width: 1,
|
|
55
|
+
} as unknown as ImageResource;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function textureWithTarget(): TextureLike {
|
|
59
|
+
const texture = textureWithImage(null);
|
|
60
|
+
texture.colorSpace = 'linear';
|
|
61
|
+
texture.storage.target = { colorSpace: 'linear', height: 8, kind: RenderTextureBackingKind, width: 8 };
|
|
62
|
+
return texture;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
describe('registerGlBitmapTextureResolver', () => {
|
|
66
|
+
it('registers only the Bitmap backing key', () => {
|
|
67
|
+
const { state } = createGlState();
|
|
68
|
+
registerGlBitmapTextureResolver(state);
|
|
69
|
+
expect([...getGlRenderStateRuntime(state).glTextureResolverRegistry!.keys()]).toEqual([BitmapTextureBackingKind]);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('registerGlCompressedImageTextureResolver', () => {
|
|
74
|
+
it('registers only the CompressedImage backing key', () => {
|
|
75
|
+
const { state } = createGlState();
|
|
76
|
+
registerGlCompressedImageTextureResolver(state);
|
|
77
|
+
expect([...getGlRenderStateRuntime(state).glTextureResolverRegistry!.keys()]).toEqual([
|
|
78
|
+
CompressedImageTextureBackingKind,
|
|
79
|
+
]);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('registerGlImageTextureResolver', () => {
|
|
84
|
+
it('registers the 2D image matcher and resolves through the backing-keyed upload cache', () => {
|
|
85
|
+
const { state, gl } = createGlState();
|
|
86
|
+
const texture = textureWithImage(imageResource());
|
|
87
|
+
registerGlImageTextureResolver(state);
|
|
88
|
+
|
|
89
|
+
const first = resolveGlTexture(state, texture);
|
|
90
|
+
const second = resolveGlTexture(state, texture);
|
|
91
|
+
|
|
92
|
+
expect(first).not.toBeNull();
|
|
93
|
+
expect(second).toBe(first);
|
|
94
|
+
expect(gl.texImage2D).toHaveBeenCalledOnce();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('returns null for an unbound image backing', () => {
|
|
98
|
+
const { state } = createGlState();
|
|
99
|
+
registerGlImageTextureResolver(state);
|
|
100
|
+
expect(resolveGlTexture(state, textureWithImage(null))).toBeNull();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe('registerGlRenderTextureResolver', () => {
|
|
105
|
+
it('returns the hidden color attachment without uploading CPU pixels', () => {
|
|
106
|
+
const { state, gl } = createGlState();
|
|
107
|
+
const previous = vi.mocked(gl.getParameter).getMockImplementation();
|
|
108
|
+
vi.mocked(gl.getParameter).mockImplementation((parameter) => {
|
|
109
|
+
if (parameter === gl.VIEWPORT || parameter === gl.SCISSOR_BOX) return [0, 0, 16, 16];
|
|
110
|
+
return previous?.(parameter);
|
|
111
|
+
});
|
|
112
|
+
const texture = textureWithTarget();
|
|
113
|
+
renderIntoGlRenderTexture(state, texture as RenderTexture, () => {});
|
|
114
|
+
registerGlRenderTextureResolver(state);
|
|
115
|
+
const uploads = vi.mocked(gl.texImage2D).mock.calls.length;
|
|
116
|
+
|
|
117
|
+
expect(resolveGlTexture(state, texture)).not.toBeNull();
|
|
118
|
+
expect(gl.texImage2D).toHaveBeenCalledTimes(uploads);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe('registerGlTextureResolver', () => {
|
|
123
|
+
it('keeps registrations state-scoped, replaces by string kind, and removes with null', () => {
|
|
124
|
+
const { state: a } = createGlState();
|
|
125
|
+
const { state: b } = createGlState();
|
|
126
|
+
const backingKind = 'acme.generated';
|
|
127
|
+
const first = vi.fn(() => ({ first: true }) as unknown as WebGLTexture);
|
|
128
|
+
const second = vi.fn(() => ({ second: true }) as unknown as WebGLTexture);
|
|
129
|
+
const image = imageResource();
|
|
130
|
+
image.kind = backingKind;
|
|
131
|
+
const texture = textureWithImage(image);
|
|
132
|
+
|
|
133
|
+
registerGlTextureResolver(a, backingKind, first);
|
|
134
|
+
expect(resolveGlTexture(a, texture)).not.toBeNull();
|
|
135
|
+
expect(resolveGlTexture(b, texture)).toBeNull();
|
|
136
|
+
|
|
137
|
+
registerGlTextureResolver(a, backingKind, second);
|
|
138
|
+
expect(resolveGlTexture(a, texture)).toEqual({ second: true });
|
|
139
|
+
expect(getGlRenderStateRuntime(a).glTextureResolverRegistry?.size).toBe(1);
|
|
140
|
+
|
|
141
|
+
registerGlTextureResolver(a, backingKind, null);
|
|
142
|
+
expect(resolveGlTexture(a, texture)).toBeNull();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('uses one exact keyed lookup and does not fall through to another kind', () => {
|
|
146
|
+
const { state } = createGlState();
|
|
147
|
+
const image = imageResource();
|
|
148
|
+
image.kind = 'acme.specific';
|
|
149
|
+
registerGlTextureResolver(state, 'image', () => ({ kind: 'image' }) as unknown as WebGLTexture);
|
|
150
|
+
registerGlTextureResolver(state, 'acme.specific', () => ({ kind: 'specific' }) as unknown as WebGLTexture);
|
|
151
|
+
expect(resolveGlTexture(state, textureWithImage(image))).toEqual({ kind: 'specific' });
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe('registerGlVideoTextureResolver', () => {
|
|
156
|
+
it('specializes the general image resolver and gates uploads by backing version', () => {
|
|
157
|
+
const { state, gl } = createGlState();
|
|
158
|
+
const video = imageResource(
|
|
159
|
+
{ readyState: 4, videoHeight: 240, videoWidth: 320 } as HTMLVideoElement,
|
|
160
|
+
VideoTextureBackingKind,
|
|
161
|
+
);
|
|
162
|
+
const texture = textureWithImage(video);
|
|
163
|
+
registerGlImageTextureResolver(state);
|
|
164
|
+
registerGlVideoTextureResolver(state);
|
|
165
|
+
|
|
166
|
+
const first = resolveGlTexture(state, texture);
|
|
167
|
+
const uploads = (gl.texImage2D as ReturnType<typeof vi.fn>).mock.calls.length;
|
|
168
|
+
const second = resolveGlTexture(state, texture);
|
|
169
|
+
|
|
170
|
+
expect(first).not.toBeNull();
|
|
171
|
+
expect(second).toBe(first);
|
|
172
|
+
expect(gl.texImage2D).toHaveBeenCalledWith(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, video.source);
|
|
173
|
+
expect(gl.texImage2D).toHaveBeenCalledTimes(uploads);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
describe('resolveGlTexture', () => {
|
|
178
|
+
it('returns null when the state has no registered backing resolver', () => {
|
|
179
|
+
const { state } = createGlState();
|
|
180
|
+
expect(resolveGlTexture(state, textureWithImage(imageResource()))).toBeNull();
|
|
181
|
+
});
|
|
182
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ImageResource } from '@flighthq/types';
|
|
1
|
+
import type { ImageResource } 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 ImageResource;
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ImageResource } from '@flighthq/types/contract';
|
|
2
2
|
|
|
3
3
|
import { uploadGlTextureVideoFrame } from './glTextureVideoUpload';
|
|
4
4
|
|
|
@@ -11,43 +11,43 @@ function makeGl(): WebGL2RenderingContext {
|
|
|
11
11
|
} as unknown as WebGL2RenderingContext;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
// A
|
|
15
|
-
function
|
|
14
|
+
// A video ImageResource whose only relevant fields are version and the borrowed host element.
|
|
15
|
+
function makeVideoImage(version: number, readyState = 4, videoWidth = 320, videoHeight = 240): ImageResource {
|
|
16
16
|
return {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} as unknown as
|
|
17
|
+
source: { readyState, videoWidth, videoHeight } as unknown as HTMLVideoElement,
|
|
18
|
+
version,
|
|
19
|
+
} as unknown as ImageResource;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
describe('uploadGlTextureVideoFrame', () => {
|
|
23
23
|
it('uploads the element and returns the new frame id when the frame advanced', () => {
|
|
24
24
|
const gl = makeGl();
|
|
25
|
-
const
|
|
26
|
-
const uploaded = uploadGlTextureVideoFrame(gl,
|
|
25
|
+
const image = makeVideoImage(3);
|
|
26
|
+
const uploaded = uploadGlTextureVideoFrame(gl, image, -1);
|
|
27
27
|
expect(uploaded).toBe(3);
|
|
28
|
-
expect(gl.texImage2D).toHaveBeenCalledWith(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE,
|
|
28
|
+
expect(gl.texImage2D).toHaveBeenCalledWith(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image.source);
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
it('skips the upload and returns the same id when the frame has not advanced', () => {
|
|
32
32
|
const gl = makeGl();
|
|
33
|
-
const
|
|
34
|
-
const uploaded = uploadGlTextureVideoFrame(gl,
|
|
33
|
+
const image = makeVideoImage(5);
|
|
34
|
+
const uploaded = uploadGlTextureVideoFrame(gl, image, 5);
|
|
35
35
|
expect(uploaded).toBe(5);
|
|
36
36
|
expect(gl.texImage2D).not.toHaveBeenCalled();
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
it('skips and reports no upload when the element has no decoded frame yet', () => {
|
|
40
40
|
const gl = makeGl();
|
|
41
|
-
const
|
|
42
|
-
const uploaded = uploadGlTextureVideoFrame(gl,
|
|
41
|
+
const image = makeVideoImage(1, 1, 0, 0);
|
|
42
|
+
const uploaded = uploadGlTextureVideoFrame(gl, image, -1);
|
|
43
43
|
expect(uploaded).toBe(-1);
|
|
44
44
|
expect(gl.texImage2D).not.toHaveBeenCalled();
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
it('skips when the element is null', () => {
|
|
48
48
|
const gl = makeGl();
|
|
49
|
-
const
|
|
50
|
-
expect(uploadGlTextureVideoFrame(gl,
|
|
49
|
+
const image = { source: null, version: 2 } as unknown as ImageResource;
|
|
50
|
+
expect(uploadGlTextureVideoFrame(gl, image, -1)).toBe(-1);
|
|
51
51
|
expect(gl.texImage2D).not.toHaveBeenCalled();
|
|
52
52
|
});
|
|
53
53
|
});
|