@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/glDraw.test.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import type { ImageResource, SamplerLike,
|
|
2
|
-
import {
|
|
1
|
+
import type { Bitmap, CompressedImage, ImageResource, SamplerLike, Texture } from '@flighthq/types/contract';
|
|
2
|
+
import {
|
|
3
|
+
AdvancedBlendMode,
|
|
4
|
+
BitmapTextureBackingKind,
|
|
5
|
+
BlendMode,
|
|
6
|
+
CompressedImageTextureBackingKind,
|
|
7
|
+
ImageTextureBackingKind,
|
|
8
|
+
} from '@flighthq/types/contract';
|
|
3
9
|
|
|
4
10
|
import { registerGlCompressedTextureDecoder, registerGlCompressedTextureUpload } from './glCompressedTexture';
|
|
5
11
|
import {
|
|
6
12
|
applyGlBlendMode,
|
|
13
|
+
applyGlSamplerState,
|
|
14
|
+
bindGlBitmapTexture,
|
|
15
|
+
bindGlCompressedImageTexture,
|
|
7
16
|
bindGlImageResourceTexture,
|
|
8
17
|
bindGlTexture,
|
|
9
18
|
bindGlVideoTexture,
|
|
@@ -21,12 +30,9 @@ import { getGlRenderStateRuntime } from './glRenderState';
|
|
|
21
30
|
import { registerGlBitmapShader } from './glShaderRegistry';
|
|
22
31
|
import { createGlState } from './glTestHelper';
|
|
23
32
|
|
|
24
|
-
// A
|
|
25
|
-
|
|
26
|
-
function compressedBc3ImageResource(): ImageResource {
|
|
33
|
+
// A single 4×4 bc3 level for exercising the opt-in compressed upload seam.
|
|
34
|
+
function compressedBc3Image(): CompressedImage {
|
|
27
35
|
return {
|
|
28
|
-
source: null,
|
|
29
|
-
data: null,
|
|
30
36
|
compressed: {
|
|
31
37
|
container: {
|
|
32
38
|
format: 'bc3',
|
|
@@ -44,8 +50,21 @@ function compressedBc3ImageResource(): ImageResource {
|
|
|
44
50
|
width: 4,
|
|
45
51
|
height: 4,
|
|
46
52
|
version: 1,
|
|
53
|
+
kind: CompressedImageTextureBackingKind,
|
|
54
|
+
} as unknown as CompressedImage;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function bitmap(size: number, version: number): Bitmap {
|
|
58
|
+
return {
|
|
47
59
|
alphaType: 'straight',
|
|
48
|
-
|
|
60
|
+
colorSpace: 'srgb',
|
|
61
|
+
data: new Uint8ClampedArray(size * size * 4),
|
|
62
|
+
format: 'rgba8unorm',
|
|
63
|
+
height: size,
|
|
64
|
+
kind: BitmapTextureBackingKind,
|
|
65
|
+
version,
|
|
66
|
+
width: size,
|
|
67
|
+
} as unknown as Bitmap;
|
|
49
68
|
}
|
|
50
69
|
|
|
51
70
|
// A plain SamplerLike with the AAA sampling defaults (clamp/linear/trilinear/mips, anisotropy off),
|
|
@@ -161,82 +180,44 @@ describe('applyGlBlendMode', () => {
|
|
|
161
180
|
});
|
|
162
181
|
});
|
|
163
182
|
|
|
164
|
-
describe('
|
|
165
|
-
|
|
166
|
-
return {
|
|
167
|
-
source: null,
|
|
168
|
-
data: new Uint8ClampedArray(size * size * 4),
|
|
169
|
-
width: size,
|
|
170
|
-
height: size,
|
|
171
|
-
version,
|
|
172
|
-
alphaType: 'straight',
|
|
173
|
-
} as unknown as ImageResource;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
it('uploads a data-only ImageResource (a generated Surface) via the raw-pixel path', () => {
|
|
183
|
+
describe('applyGlSamplerState', () => {
|
|
184
|
+
it('applies sampler state to an existing texture without uploading it', () => {
|
|
177
185
|
const { state, gl } = createGlState();
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
186
|
+
const runtime = getGlRenderStateRuntime(state);
|
|
187
|
+
const texture = gl.createTexture()!;
|
|
188
|
+
const uploads = vi.mocked(gl.texImage2D).mock.calls.length;
|
|
189
|
+
|
|
190
|
+
applyGlSamplerState(state, runtime, texture, makeSampler({ mipmaps: false, wrapU: 'repeat' }));
|
|
191
|
+
|
|
192
|
+
expect(gl.texParameteri).toHaveBeenCalledWith(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
|
|
193
|
+
expect(gl.texImage2D).toHaveBeenCalledTimes(uploads);
|
|
181
194
|
});
|
|
195
|
+
});
|
|
182
196
|
|
|
183
|
-
|
|
197
|
+
describe('bindGlBitmapTexture', () => {
|
|
198
|
+
it('uploads CPU-readable pixels via the raw-pixel path', () => {
|
|
184
199
|
const { state, gl } = createGlState();
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
data: null,
|
|
188
|
-
width: 1,
|
|
189
|
-
height: 1,
|
|
190
|
-
version: 1,
|
|
191
|
-
alphaType: 'straight',
|
|
192
|
-
} as unknown as ImageResource;
|
|
193
|
-
bindGlImageResourceTexture(state, image);
|
|
200
|
+
bindGlBitmapTexture(state, bitmap(4, 1));
|
|
201
|
+
expect(gl.createTexture).toHaveBeenCalled();
|
|
194
202
|
expect(gl.texImage2D).toHaveBeenCalled();
|
|
195
203
|
});
|
|
196
204
|
|
|
197
205
|
it('caches by resource identity and re-uploads only when the version changes', () => {
|
|
198
206
|
const { state, gl } = createGlState();
|
|
199
|
-
const image =
|
|
200
|
-
const t1 =
|
|
207
|
+
const image = bitmap(1, 1);
|
|
208
|
+
const t1 = bindGlBitmapTexture(state, image);
|
|
201
209
|
const uploads = (gl.texImage2D as ReturnType<typeof vi.fn>).mock.calls.length;
|
|
202
|
-
const t2 =
|
|
210
|
+
const t2 = bindGlBitmapTexture(state, image);
|
|
203
211
|
expect(t2).toBe(t1);
|
|
204
212
|
expect((gl.texImage2D as ReturnType<typeof vi.fn>).mock.calls.length).toBe(uploads);
|
|
205
213
|
image.version = 2;
|
|
206
|
-
|
|
214
|
+
bindGlBitmapTexture(state, image);
|
|
207
215
|
expect((gl.texImage2D as ReturnType<typeof vi.fn>).mock.calls.length).toBe(uploads + 1);
|
|
208
216
|
});
|
|
209
217
|
|
|
210
|
-
it('
|
|
211
|
-
// The device mock exposes no block extension, so the compressed container falls back to the
|
|
212
|
-
// registered RGBA decoder and uploads via texImage2D — proving the real bind/draw path reaches the
|
|
213
|
-
// installed compressed uploader, not just the raw data/element branches.
|
|
214
|
-
const { state, gl } = createGlState();
|
|
215
|
-
const rgba = new Uint8ClampedArray(4 * 4 * 4);
|
|
216
|
-
const decode = vi.fn(() => rgba);
|
|
217
|
-
registerGlCompressedTextureUpload(state);
|
|
218
|
-
registerGlCompressedTextureDecoder(state, decode);
|
|
219
|
-
const image = compressedBc3ImageResource();
|
|
220
|
-
bindGlImageResourceTexture(state, image);
|
|
221
|
-
expect(decode).toHaveBeenCalledWith('bc3', 4, 4, expect.any(Uint8Array));
|
|
222
|
-
expect(gl.texImage2D).toHaveBeenCalled();
|
|
223
|
-
expect(getGlRenderStateRuntime(state).currentTextureStraightAlpha).toBe(true);
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it('skips a compressed-only ImageResource when no compressed uploader is registered', () => {
|
|
227
|
-
// The compressed path is an opt-in seam: without registerGlCompressedTextureUpload, a compressed
|
|
228
|
-
// resource uploads nothing (the enum table tree-shakes out of a bitmap-only bundle) rather than
|
|
229
|
-
// reaching texImage2D.
|
|
230
|
-
const { state, gl } = createGlState();
|
|
231
|
-
bindGlImageResourceTexture(state, compressedBc3ImageResource());
|
|
232
|
-
expect(gl.texImage2D).not.toHaveBeenCalled();
|
|
233
|
-
expect(gl.compressedTexImage2D).not.toHaveBeenCalled();
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
it('a per-bitmap smoothingOverride=false forces NEAREST even when allowSmoothing is true', () => {
|
|
237
|
-
// A non-smoothed bitmap must sample NEAREST regardless of the global allowSmoothing default.
|
|
218
|
+
it('a smoothingOverride=false forces NEAREST even when allowSmoothing is true', () => {
|
|
238
219
|
const { state, gl } = createGlState({ allowSmoothing: true });
|
|
239
|
-
|
|
220
|
+
bindGlBitmapTexture(state, bitmap(4, 1), null, false);
|
|
240
221
|
const g = gl as unknown as {
|
|
241
222
|
TEXTURE_2D: number;
|
|
242
223
|
TEXTURE_MIN_FILTER: number;
|
|
@@ -247,9 +228,9 @@ describe('bindGlImageResourceTexture', () => {
|
|
|
247
228
|
expect(gl.texParameteri).toHaveBeenCalledWith(g.TEXTURE_2D, g.TEXTURE_MAG_FILTER, g.NEAREST);
|
|
248
229
|
});
|
|
249
230
|
|
|
250
|
-
it('a
|
|
231
|
+
it('a smoothingOverride=true forces LINEAR even when allowSmoothing is false', () => {
|
|
251
232
|
const { state, gl } = createGlState({ allowSmoothing: false });
|
|
252
|
-
|
|
233
|
+
bindGlBitmapTexture(state, bitmap(4, 1), null, true);
|
|
253
234
|
const g = gl as unknown as {
|
|
254
235
|
TEXTURE_2D: number;
|
|
255
236
|
TEXTURE_MIN_FILTER: number;
|
|
@@ -261,6 +242,63 @@ describe('bindGlImageResourceTexture', () => {
|
|
|
261
242
|
});
|
|
262
243
|
});
|
|
263
244
|
|
|
245
|
+
describe('bindGlCompressedImageTexture', () => {
|
|
246
|
+
it('routes through the registered compressed upload seam (decode fallback)', () => {
|
|
247
|
+
// The device mock exposes no block extension, so the compressed container falls back to the
|
|
248
|
+
// registered RGBA decoder and uploads via texImage2D — proving the real bind/draw path reaches the
|
|
249
|
+
// installed compressed uploader.
|
|
250
|
+
const { state, gl } = createGlState();
|
|
251
|
+
const rgba = new Uint8ClampedArray(4 * 4 * 4);
|
|
252
|
+
const decode = vi.fn(() => rgba);
|
|
253
|
+
registerGlCompressedTextureUpload(state);
|
|
254
|
+
registerGlCompressedTextureDecoder(state, decode);
|
|
255
|
+
const image = compressedBc3Image();
|
|
256
|
+
bindGlCompressedImageTexture(state, image);
|
|
257
|
+
expect(decode).toHaveBeenCalledWith('bc3', 4, 4, expect.any(Uint8Array));
|
|
258
|
+
expect(gl.texImage2D).toHaveBeenCalled();
|
|
259
|
+
expect(getGlRenderStateRuntime(state).currentTextureStraightAlpha).toBe(true);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('preserves straight-alpha sampling on a cache hit', () => {
|
|
263
|
+
const { state } = createGlState();
|
|
264
|
+
registerGlCompressedTextureUpload(state);
|
|
265
|
+
registerGlCompressedTextureDecoder(
|
|
266
|
+
state,
|
|
267
|
+
vi.fn(() => new Uint8ClampedArray(4 * 4 * 4)),
|
|
268
|
+
);
|
|
269
|
+
const image = compressedBc3Image();
|
|
270
|
+
bindGlCompressedImageTexture(state, image);
|
|
271
|
+
getGlRenderStateRuntime(state).currentTextureStraightAlpha = false;
|
|
272
|
+
bindGlCompressedImageTexture(state, image);
|
|
273
|
+
expect(getGlRenderStateRuntime(state).currentTextureStraightAlpha).toBe(true);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it('skips the image when no compressed uploader is registered', () => {
|
|
277
|
+
// The compressed path is an opt-in seam: without registerGlCompressedTextureUpload, a compressed
|
|
278
|
+
// image uploads nothing (the enum table tree-shakes out of a bitmap-only bundle) rather than
|
|
279
|
+
// reaching texImage2D.
|
|
280
|
+
const { state, gl } = createGlState();
|
|
281
|
+
bindGlCompressedImageTexture(state, compressedBc3Image());
|
|
282
|
+
expect(gl.texImage2D).not.toHaveBeenCalled();
|
|
283
|
+
expect(gl.compressedTexImage2D).not.toHaveBeenCalled();
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
describe('bindGlImageResourceTexture', () => {
|
|
288
|
+
it('uploads a host-backed image via the element path', () => {
|
|
289
|
+
const { state, gl } = createGlState();
|
|
290
|
+
const image = {
|
|
291
|
+
source: document.createElement('img'),
|
|
292
|
+
width: 1,
|
|
293
|
+
height: 1,
|
|
294
|
+
kind: ImageTextureBackingKind,
|
|
295
|
+
version: 1,
|
|
296
|
+
} as unknown as ImageResource;
|
|
297
|
+
bindGlImageResourceTexture(state, image);
|
|
298
|
+
expect(gl.texImage2D).toHaveBeenCalled();
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
|
|
264
302
|
describe('bindGlTexture', () => {
|
|
265
303
|
it('creates a new texture for an uncached image source', () => {
|
|
266
304
|
const { state, gl } = createGlState();
|
|
@@ -475,32 +513,45 @@ describe('bindGlTexture', () => {
|
|
|
475
513
|
});
|
|
476
514
|
|
|
477
515
|
describe('bindGlVideoTexture', () => {
|
|
478
|
-
function videoTexture(
|
|
516
|
+
function videoTexture(version: number, readyState = 4, videoWidth = 320, videoHeight = 240): Texture {
|
|
479
517
|
return {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
518
|
+
sampler: makeSampler(),
|
|
519
|
+
storage: {
|
|
520
|
+
dimension: '2d',
|
|
521
|
+
image: {
|
|
522
|
+
source: { readyState, videoWidth, videoHeight } as unknown as HTMLVideoElement,
|
|
523
|
+
version,
|
|
524
|
+
},
|
|
525
|
+
},
|
|
526
|
+
version,
|
|
527
|
+
} as unknown as Texture;
|
|
484
528
|
}
|
|
485
529
|
|
|
486
|
-
it('creates a texture, uploads the current frame, and caches by
|
|
530
|
+
it('creates a texture, uploads the current frame, and caches by backing identity', () => {
|
|
487
531
|
const { state, gl } = createGlState();
|
|
488
532
|
const vt = videoTexture(3);
|
|
489
533
|
const t1 = bindGlVideoTexture(state, vt);
|
|
490
534
|
expect(gl.createTexture).toHaveBeenCalled();
|
|
491
|
-
expect(gl.texImage2D).toHaveBeenCalledWith(
|
|
535
|
+
expect(gl.texImage2D).toHaveBeenCalledWith(
|
|
536
|
+
gl.TEXTURE_2D,
|
|
537
|
+
0,
|
|
538
|
+
gl.RGBA,
|
|
539
|
+
gl.RGBA,
|
|
540
|
+
gl.UNSIGNED_BYTE,
|
|
541
|
+
(vt.storage.image as ImageResource).source,
|
|
542
|
+
);
|
|
492
543
|
const t2 = bindGlVideoTexture(state, vt);
|
|
493
544
|
expect(t2).toBe(t1);
|
|
494
545
|
});
|
|
495
546
|
|
|
496
|
-
it('re-uploads only when the
|
|
547
|
+
it('re-uploads only when the backing version advances (the dirty-gate)', () => {
|
|
497
548
|
const { state, gl } = createGlState();
|
|
498
549
|
const vt = videoTexture(1);
|
|
499
550
|
bindGlVideoTexture(state, vt);
|
|
500
551
|
const uploads = (gl.texImage2D as ReturnType<typeof vi.fn>).mock.calls.length;
|
|
501
552
|
bindGlVideoTexture(state, vt);
|
|
502
553
|
expect((gl.texImage2D as ReturnType<typeof vi.fn>).mock.calls.length).toBe(uploads);
|
|
503
|
-
vt.
|
|
554
|
+
vt.storage.image!.version = 2;
|
|
504
555
|
bindGlVideoTexture(state, vt);
|
|
505
556
|
expect((gl.texImage2D as ReturnType<typeof vi.fn>).mock.calls.length).toBe(uploads + 1);
|
|
506
557
|
});
|
|
@@ -511,7 +562,7 @@ describe('bindGlVideoTexture', () => {
|
|
|
511
562
|
expect(gl.texImage2D).not.toHaveBeenCalled();
|
|
512
563
|
});
|
|
513
564
|
|
|
514
|
-
it('applies the
|
|
565
|
+
it('applies the Texture sampler when no explicit sampler is passed', () => {
|
|
515
566
|
const { state, gl } = createGlState();
|
|
516
567
|
const vt = videoTexture(1);
|
|
517
568
|
(vt as { sampler: SamplerLike }).sampler = makeSampler({ wrapU: 'repeat' });
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getTextureBackingKind } from '@flighthq/texture/contract';
|
|
2
|
+
import { ExternalTextureBackingKind } from '@flighthq/types/contract';
|
|
3
|
+
|
|
4
|
+
import { createExternalGlTexture, disposeExternalGlTexture } from './glExternalTexture';
|
|
5
|
+
import { createGlState } from './glTestHelper';
|
|
6
|
+
import { resolveGlTexture } from './glTextureResolver';
|
|
7
|
+
|
|
8
|
+
describe('createExternalGlTexture', () => {
|
|
9
|
+
it('resolves a borrowed handle and forgets it without deleting the allocation', () => {
|
|
10
|
+
const { state } = createGlState();
|
|
11
|
+
const handle = state.gl.createTexture()!;
|
|
12
|
+
const deleteTexture = vi.spyOn(state.gl, 'deleteTexture');
|
|
13
|
+
const texture = createExternalGlTexture(state, handle, { height: 16, width: 32 });
|
|
14
|
+
|
|
15
|
+
expect(getTextureBackingKind(texture)).toBe(ExternalTextureBackingKind);
|
|
16
|
+
expect(resolveGlTexture(state, texture)).toBe(handle);
|
|
17
|
+
expect(disposeExternalGlTexture(state, texture)).toBe(true);
|
|
18
|
+
expect(resolveGlTexture(state, texture)).toBeNull();
|
|
19
|
+
expect(deleteTexture).not.toHaveBeenCalled();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('disposeExternalGlTexture', () => {
|
|
24
|
+
it('returns false after the borrowed handle has already been forgotten', () => {
|
|
25
|
+
const { state } = createGlState();
|
|
26
|
+
const texture = createExternalGlTexture(state, state.gl.createTexture()!, { height: 1, width: 1 });
|
|
27
|
+
expect(disposeExternalGlTexture(state, texture)).toBe(true);
|
|
28
|
+
expect(disposeExternalGlTexture(state, texture)).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { GlRenderTarget } from '@flighthq/types';
|
|
2
|
-
import { BlendMode } from '@flighthq/types';
|
|
1
|
+
import type { GlRenderTarget } from '@flighthq/types/contract';
|
|
2
|
+
import { BlendMode } from '@flighthq/types/contract';
|
|
3
3
|
|
|
4
4
|
import { clearGlRenderTarget, compileGlFullscreenProgram, drawGlFullscreenPass } from './glFullscreenPass';
|
|
5
5
|
import { getGlRenderStateRuntime } from './glRenderState';
|
|
@@ -55,7 +55,7 @@ describe('clearGlRenderTarget', () => {
|
|
|
55
55
|
clearGlRenderTarget(state, target);
|
|
56
56
|
|
|
57
57
|
expect(viewportSpy).toHaveBeenCalledWith(0, 0, 48, 24);
|
|
58
|
-
expect(getGlRenderStateRuntime(state).renderTargetViewport).toEqual({ width: 48,
|
|
58
|
+
expect(getGlRenderStateRuntime(state).renderTargetViewport).toEqual({ height: 24, width: 48, x: 0, y: 0 });
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
it('clears to fully transparent', () => {
|
|
@@ -132,7 +132,7 @@ describe('drawGlFullscreenPass', () => {
|
|
|
132
132
|
|
|
133
133
|
expect(bindSpy).toHaveBeenCalledWith(gl.FRAMEBUFFER, dest.framebuffer);
|
|
134
134
|
expect(viewportSpy).toHaveBeenCalledWith(0, 0, 40, 20);
|
|
135
|
-
expect(getGlRenderStateRuntime(state).renderTargetViewport).toEqual({ width: 40,
|
|
135
|
+
expect(getGlRenderStateRuntime(state).renderTargetViewport).toEqual({ height: 20, width: 40, x: 0, y: 0 });
|
|
136
136
|
});
|
|
137
137
|
|
|
138
138
|
it('targets the canvas and clears renderTargetViewport when dest is null', () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { GlMaterialRenderer, Material } from '@flighthq/types';
|
|
2
|
-
import {
|
|
1
|
+
import type { GlMaterialRenderer, Material } from '@flighthq/types/contract';
|
|
2
|
+
import { StandardMaterialKind } from '@flighthq/types/contract';
|
|
3
3
|
|
|
4
4
|
import { getGlMaterialRenderer, registerGlMaterialRenderer, resolveGlMaterialRenderer } from './glMaterialRegistry';
|
|
5
5
|
import { createGlState } from './glTestHelper';
|
|
@@ -39,9 +39,9 @@ describe('resolveGlMaterialRenderer', () => {
|
|
|
39
39
|
expect(resolveGlMaterialRenderer(state, makeMaterial(TestKind))).toBe(testRenderer);
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
it('falls back to the renderer registered for
|
|
42
|
+
it('falls back to the renderer registered for StandardMaterialKind', () => {
|
|
43
43
|
const { state } = createGlState();
|
|
44
|
-
registerGlMaterialRenderer(state,
|
|
44
|
+
registerGlMaterialRenderer(state, StandardMaterialKind, testRenderer);
|
|
45
45
|
expect(resolveGlMaterialRenderer(state, makeMaterial('Other'))).toBe(testRenderer);
|
|
46
46
|
expect(resolveGlMaterialRenderer(state, null)).toBe(testRenderer);
|
|
47
47
|
});
|
package/src/glReadback.test.ts
CHANGED
package/src/glRenderPass.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createMatrix } from '@flighthq/geometry';
|
|
2
|
-
import type { GlRenderTarget } from '@flighthq/types';
|
|
1
|
+
import { createMatrix } from '@flighthq/geometry/contract';
|
|
2
|
+
import type { GlRenderTarget, Viewport } from '@flighthq/types/contract';
|
|
3
3
|
|
|
4
4
|
import { beginGlRenderPass, endGlRenderPass, setGlRenderTransform2D } from './glRenderPass';
|
|
5
5
|
import { getGlRenderStateRuntime } from './glRenderState';
|
|
@@ -92,7 +92,59 @@ describe('beginGlRenderPass', () => {
|
|
|
92
92
|
|
|
93
93
|
const runtime = getGlRenderStateRuntime(state);
|
|
94
94
|
expect(runtime.currentRenderTarget).toBe(target);
|
|
95
|
-
expect(runtime.renderTargetViewport).toEqual({ width: 64,
|
|
95
|
+
expect(runtime.renderTargetViewport).toEqual({ height: 48, width: 64, x: 0, y: 0 });
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('constrains viewport and clears to a top-left-origin sub-region', () => {
|
|
99
|
+
const { state, gl } = createGlState();
|
|
100
|
+
const target = makeTarget({ width: 100, height: 80 });
|
|
101
|
+
const viewport = makeViewport(10, 20, 30, 40);
|
|
102
|
+
|
|
103
|
+
beginGlRenderPass(state, target, undefined, viewport);
|
|
104
|
+
|
|
105
|
+
expect(gl.viewport).toHaveBeenLastCalledWith(10, 20, 30, 40);
|
|
106
|
+
expect(gl.enable).toHaveBeenCalledWith(gl.SCISSOR_TEST);
|
|
107
|
+
expect(gl.scissor).toHaveBeenLastCalledWith(10, 20, 30, 40);
|
|
108
|
+
expect(vi.mocked(gl.scissor).mock.invocationCallOrder[0]).toBeLessThan(
|
|
109
|
+
vi.mocked(gl.clearBufferfv).mock.invocationCallOrder[0],
|
|
110
|
+
);
|
|
111
|
+
expect(getGlRenderStateRuntime(state).renderTargetViewport).toEqual({
|
|
112
|
+
height: 40,
|
|
113
|
+
width: 30,
|
|
114
|
+
x: 10,
|
|
115
|
+
y: 20,
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('intersects both viewport edges before clamping a negative origin', () => {
|
|
120
|
+
const { state, gl } = createGlState();
|
|
121
|
+
|
|
122
|
+
beginGlRenderPass(state, makeTarget({ width: 100, height: 80 }), undefined, makeViewport(-10, -5, 25, 20));
|
|
123
|
+
|
|
124
|
+
// Visible top-left intersection is 15×15, not the original 25×20 shifted inward.
|
|
125
|
+
expect(gl.viewport).toHaveBeenLastCalledWith(0, 65, 15, 15);
|
|
126
|
+
expect(gl.scissor).toHaveBeenLastCalledWith(0, 65, 15, 15);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('keeps a fractional-origin zero-area viewport empty', () => {
|
|
130
|
+
const { state, gl } = createGlState();
|
|
131
|
+
|
|
132
|
+
beginGlRenderPass(state, makeTarget({ width: 100, height: 80 }), undefined, makeViewport(10.5, 20.5, 0, 0));
|
|
133
|
+
|
|
134
|
+
expect(gl.viewport).toHaveBeenLastCalledWith(10, 60, 0, 0);
|
|
135
|
+
expect(gl.scissor).toHaveBeenLastCalledWith(10, 60, 0, 0);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('keeps a nested full-region pass inside the enclosing scissor', () => {
|
|
139
|
+
const { state, gl } = createGlState();
|
|
140
|
+
const target = makeTarget({ width: 100, height: 80 });
|
|
141
|
+
|
|
142
|
+
beginGlRenderPass(state, target, undefined, makeViewport(10, 20, 30, 40));
|
|
143
|
+
beginGlRenderPass(state, target);
|
|
144
|
+
|
|
145
|
+
expect(gl.viewport).toHaveBeenLastCalledWith(0, 0, 100, 80);
|
|
146
|
+
expect(gl.scissor).toHaveBeenLastCalledWith(10, 20, 30, 40);
|
|
147
|
+
expect(getGlRenderStateRuntime(state).currentScissorRect).toEqual({ height: 40, width: 30, x: 10, y: 20 });
|
|
96
148
|
});
|
|
97
149
|
|
|
98
150
|
it('nests: the inner pass is current until it ends, then the outer is restored', () => {
|
|
@@ -107,7 +159,7 @@ describe('beginGlRenderPass', () => {
|
|
|
107
159
|
|
|
108
160
|
endGlRenderPass(state);
|
|
109
161
|
expect(runtime.currentRenderTarget).toBe(outer);
|
|
110
|
-
expect(runtime.renderTargetViewport).toEqual({ width: 64,
|
|
162
|
+
expect(runtime.renderTargetViewport).toEqual({ height: 48, width: 64, x: 0, y: 0 });
|
|
111
163
|
});
|
|
112
164
|
});
|
|
113
165
|
|
|
@@ -134,12 +186,99 @@ describe('endGlRenderPass', () => {
|
|
|
134
186
|
expect(getGlRenderStateRuntime(state).renderTargetViewport).toBeNull();
|
|
135
187
|
});
|
|
136
188
|
|
|
137
|
-
it('
|
|
189
|
+
it('restores the exact enclosing viewport and scissor after a nested pass', () => {
|
|
190
|
+
const { state, gl } = createGlState();
|
|
191
|
+
const target = makeTarget({ width: 100, height: 80 });
|
|
192
|
+
|
|
193
|
+
beginGlRenderPass(state, target, undefined, makeViewport(10, 20, 30, 40));
|
|
194
|
+
beginGlRenderPass(state, target, undefined, makeViewport(15, 25, 10, 10));
|
|
195
|
+
endGlRenderPass(state);
|
|
196
|
+
|
|
197
|
+
expect(gl.viewport).toHaveBeenLastCalledWith(10, 20, 30, 40);
|
|
198
|
+
expect(gl.scissor).toHaveBeenLastCalledWith(10, 20, 30, 40);
|
|
199
|
+
expect(getGlRenderStateRuntime(state).currentScissorRect).toEqual({ height: 40, width: 30, x: 10, y: 20 });
|
|
200
|
+
expect(getGlRenderStateRuntime(state).scissorStack).toEqual([{ height: 40, width: 30, x: 10, y: 20 }]);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('isolates and restores the enclosing logical 2D clip stack', () => {
|
|
138
204
|
const { state } = createGlState();
|
|
139
|
-
|
|
205
|
+
const runtime = getGlRenderStateRuntime(state);
|
|
206
|
+
const outerClip = { height: 20, width: 20, x: 15, y: 25 };
|
|
207
|
+
|
|
208
|
+
beginGlRenderPass(state, makeTarget({ width: 100, height: 80 }), undefined, makeViewport(10, 20, 30, 40));
|
|
209
|
+
runtime.currentScissorRect = outerClip;
|
|
210
|
+
runtime.scissorStack!.push(outerClip);
|
|
211
|
+
runtime.clipForms.push('rect');
|
|
212
|
+
|
|
213
|
+
beginGlRenderPass(state, makeTarget({ width: 100, height: 80 }));
|
|
214
|
+
expect(runtime.clipForms).toEqual([]);
|
|
215
|
+
expect(runtime.currentMaskDepth).toBe(0);
|
|
216
|
+
|
|
217
|
+
// An inner renderGlScene2D.finalize now has no enclosing entry to drain.
|
|
218
|
+
endGlRenderPass(state);
|
|
219
|
+
expect(runtime.currentScissorRect).toBe(outerClip);
|
|
220
|
+
expect(runtime.scissorStack).toEqual([{ height: 40, width: 30, x: 10, y: 20 }, outerClip]);
|
|
221
|
+
expect(runtime.clipForms).toEqual(['rect']);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('restores depth writes after a nested depth-clearing pass', () => {
|
|
225
|
+
const { state, gl } = createGlState();
|
|
226
|
+
let depthMask = true;
|
|
227
|
+
vi.mocked(gl.depthMask).mockImplementation((value) => {
|
|
228
|
+
depthMask = value;
|
|
229
|
+
});
|
|
230
|
+
vi.mocked(gl.getParameter).mockImplementation((parameter) => (parameter === gl.DEPTH_WRITEMASK ? depthMask : null));
|
|
231
|
+
|
|
232
|
+
beginGlRenderPass(state, makeTarget(), { preserveDepth: true });
|
|
233
|
+
gl.depthMask(false);
|
|
234
|
+
beginGlRenderPass(state, makeTarget());
|
|
235
|
+
expect(depthMask).toBe(true);
|
|
236
|
+
endGlRenderPass(state);
|
|
237
|
+
|
|
238
|
+
expect(depthMask).toBe(false);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('isolates and restores an enclosing contour stencil gate', () => {
|
|
242
|
+
const { state, gl } = createGlState();
|
|
243
|
+
const runtime = getGlRenderStateRuntime(state);
|
|
244
|
+
runtime.clipForms = ['contour'];
|
|
245
|
+
runtime.currentMaskDepth = 1;
|
|
246
|
+
|
|
247
|
+
beginGlRenderPass(state, makeTarget());
|
|
248
|
+
expect(runtime.clipForms).toEqual([]);
|
|
249
|
+
expect(runtime.currentMaskDepth).toBe(0);
|
|
250
|
+
expect(gl.disable).toHaveBeenCalledWith(gl.STENCIL_TEST);
|
|
251
|
+
|
|
252
|
+
endGlRenderPass(state);
|
|
253
|
+
expect(runtime.clipForms).toEqual(['contour']);
|
|
254
|
+
expect(runtime.currentMaskDepth).toBe(1);
|
|
255
|
+
expect(gl.enable).toHaveBeenCalledWith(gl.STENCIL_TEST);
|
|
256
|
+
expect(gl.stencilMask).toHaveBeenCalled();
|
|
257
|
+
expect(gl.stencilFunc).toHaveBeenCalled();
|
|
258
|
+
expect(gl.stencilOp).toHaveBeenCalled();
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('disables scissor when the outer partial pass returns to the canvas', () => {
|
|
262
|
+
const { state, gl } = createGlState();
|
|
263
|
+
|
|
264
|
+
beginGlRenderPass(state, makeTarget(), undefined, makeViewport(1, 2, 10, 8));
|
|
265
|
+
endGlRenderPass(state);
|
|
266
|
+
|
|
267
|
+
expect(gl.disable).toHaveBeenCalledWith(gl.SCISSOR_TEST);
|
|
268
|
+
expect(getGlRenderStateRuntime(state).currentScissorRect).toBeNull();
|
|
269
|
+
expect(getGlRenderStateRuntime(state).scissorStack).toEqual([]);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it('throws when there is no matching begin', () => {
|
|
273
|
+
const { state } = createGlState();
|
|
274
|
+
expect(() => endGlRenderPass(state)).toThrow('without a matching beginGlRenderPass');
|
|
140
275
|
});
|
|
141
276
|
});
|
|
142
277
|
|
|
278
|
+
function makeViewport(x: number, y: number, width: number, height: number): Viewport {
|
|
279
|
+
return { devicePixelRatio: 1, height, width, x, y } as Viewport;
|
|
280
|
+
}
|
|
281
|
+
|
|
143
282
|
describe('setGlRenderTransform2D', () => {
|
|
144
283
|
it('installs a copy of the transform as the 2D root device transform', () => {
|
|
145
284
|
const { state } = createGlState();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BlendMode } from '@flighthq/types';
|
|
1
|
+
import { BlendMode } from '@flighthq/types/contract';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
createGlRenderState,
|
|
@@ -171,7 +171,7 @@ describe('invalidateGlRenderStateCache', () => {
|
|
|
171
171
|
runtime.currentBlendMode = BlendMode.Add;
|
|
172
172
|
runtime.currentMaskDepth = 3;
|
|
173
173
|
runtime.currentScissorRect = { x: 0, y: 0, width: 1, height: 1 };
|
|
174
|
-
runtime.renderTargetViewport = {
|
|
174
|
+
runtime.renderTargetViewport = { height: 4, width: 4, x: 0, y: 0 };
|
|
175
175
|
|
|
176
176
|
invalidateGlRenderStateCache(state);
|
|
177
177
|
|