@flighthq/application-gl 0.5.1-next.650.5d3df0b → 0.5.1-next.658.9cb44d7
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/README.md +2 -2
- package/package.json +5 -5
- package/src/glApplicationRenderView.test.ts +60 -63
package/README.md
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/application-gl`. The
|
|
|
13
13
|
This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
|
|
14
14
|
|
|
15
15
|
- [Flight project](https://github.com/flighthq/flight)
|
|
16
|
-
- [Source for @flighthq/application-gl@0.5.1-next.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/application-gl@0.5.1-next.658.9cb44d7](https://github.com/flighthq/flight/tree/9cb44d76b981adad2503d5e62207be99adb35c55/packages/application-gl)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/9cb44d76b981adad2503d5e62207be99adb35c55/LICENSE.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/application-gl",
|
|
3
|
-
"version": "0.5.1-next.
|
|
3
|
+
"version": "0.5.1-next.658.9cb44d7",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/application": "0.5.1-next.
|
|
42
|
-
"@flighthq/node": "0.5.1-next.
|
|
43
|
-
"@flighthq/render-gl": "0.5.1-next.
|
|
44
|
-
"@flighthq/types": "0.5.1-next.
|
|
41
|
+
"@flighthq/application": "0.5.1-next.658.9cb44d7",
|
|
42
|
+
"@flighthq/node": "0.5.1-next.658.9cb44d7",
|
|
43
|
+
"@flighthq/render-gl": "0.5.1-next.658.9cb44d7",
|
|
44
|
+
"@flighthq/types": "0.5.1-next.658.9cb44d7"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@flighthq/signals": "*",
|
|
@@ -3,60 +3,53 @@ import {
|
|
|
3
3
|
createApplicationWindow,
|
|
4
4
|
synchronizeApplicationRenderView,
|
|
5
5
|
} from '@flighthq/application/contract';
|
|
6
|
+
import * as nodeContract from '@flighthq/node/contract';
|
|
7
|
+
import * as renderGlContract from '@flighthq/render-gl/contract';
|
|
6
8
|
import { emitSignal } from '@flighthq/signals/contract';
|
|
7
9
|
import type { GlPipeline, GlRenderState, GlRenderTarget } from '@flighthq/types/contract';
|
|
8
10
|
|
|
9
11
|
import { createGlApplicationRenderView, destroyGlApplicationRenderView } from './glApplicationRenderView';
|
|
10
12
|
|
|
11
|
-
const mocks = vi.hoisted(() => ({
|
|
12
|
-
createGlContextFromCanvasElement: vi.fn(),
|
|
13
|
-
createGlContextState: vi.fn(),
|
|
14
|
-
createGlRenderState: vi.fn(),
|
|
15
|
-
createGlRenderTarget: vi.fn(),
|
|
16
|
-
createViewport: vi.fn(),
|
|
17
|
-
destroyGlRenderState: vi.fn(),
|
|
18
|
-
destroyGlRenderTarget: vi.fn(),
|
|
19
|
-
invalidateGlRenderStateCache: vi.fn(),
|
|
20
|
-
resizeGlRenderTarget: vi.fn(),
|
|
21
|
-
}));
|
|
22
|
-
|
|
23
|
-
vi.mock('@flighthq/node/contract', () => ({
|
|
24
|
-
createViewport: mocks.createViewport,
|
|
25
|
-
}));
|
|
26
|
-
|
|
27
|
-
vi.mock('@flighthq/render-gl/contract', () => ({
|
|
28
|
-
createGlContextFromCanvasElement: mocks.createGlContextFromCanvasElement,
|
|
29
|
-
createGlContextState: mocks.createGlContextState,
|
|
30
|
-
createGlRenderState: mocks.createGlRenderState,
|
|
31
|
-
createGlRenderTarget: mocks.createGlRenderTarget,
|
|
32
|
-
destroyGlRenderState: mocks.destroyGlRenderState,
|
|
33
|
-
destroyGlRenderTarget: mocks.destroyGlRenderTarget,
|
|
34
|
-
invalidateGlRenderStateCache: mocks.invalidateGlRenderStateCache,
|
|
35
|
-
resizeGlRenderTarget: mocks.resizeGlRenderTarget,
|
|
36
|
-
}));
|
|
37
|
-
|
|
38
13
|
beforeEach(() => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
14
|
+
vi.spyOn(nodeContract, 'createViewport').mockImplementation((options) => ({ ...options, x: 0, y: 0 }) as never);
|
|
15
|
+
|
|
16
|
+
vi.spyOn(renderGlContract, 'createGlContextFromCanvasElement').mockImplementation(
|
|
17
|
+
() => ({ drawingBufferHeight: 0, drawingBufferWidth: 0 }) as never,
|
|
18
|
+
);
|
|
19
|
+
vi.spyOn(renderGlContract, 'createGlContextState').mockImplementation(((gl: never) => ({ gl })) as never);
|
|
20
|
+
vi.spyOn(renderGlContract, 'createGlRenderState').mockImplementation(((
|
|
21
|
+
contextState: never,
|
|
22
|
+
_pipeline: never,
|
|
23
|
+
options: { pixelRatio: number },
|
|
24
|
+
) => ({
|
|
42
25
|
contextState,
|
|
43
|
-
gl: contextState.gl,
|
|
26
|
+
gl: (contextState as { gl: unknown }).gl,
|
|
44
27
|
pixelRatio: options.pixelRatio,
|
|
45
28
|
renderTransform2D: { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 },
|
|
46
|
-
}));
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
29
|
+
})) as never);
|
|
30
|
+
vi.spyOn(renderGlContract, 'createGlRenderTarget').mockImplementation(((
|
|
31
|
+
_state: GlRenderState,
|
|
32
|
+
descriptor: { height: number; width: number },
|
|
33
|
+
) => ({
|
|
34
|
+
height: Math.max(1, descriptor.height),
|
|
35
|
+
width: Math.max(1, descriptor.width),
|
|
36
|
+
})) as never);
|
|
37
|
+
vi.spyOn(renderGlContract, 'destroyGlRenderState').mockImplementation((() => {}) as never);
|
|
38
|
+
vi.spyOn(renderGlContract, 'destroyGlRenderTarget').mockImplementation((() => {}) as never);
|
|
39
|
+
vi.spyOn(renderGlContract, 'invalidateGlRenderStateCache').mockImplementation((() => {}) as never);
|
|
40
|
+
vi.spyOn(renderGlContract, 'resizeGlRenderTarget').mockImplementation(((
|
|
41
|
+
_state: GlRenderState,
|
|
42
|
+
target: GlRenderTarget,
|
|
43
|
+
width: number,
|
|
44
|
+
height: number,
|
|
45
|
+
) => {
|
|
46
|
+
target.width = Math.max(1, width);
|
|
47
|
+
target.height = Math.max(1, height);
|
|
48
|
+
}) as never);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
afterEach(() => {
|
|
52
|
+
vi.restoreAllMocks();
|
|
60
53
|
});
|
|
61
54
|
|
|
62
55
|
const pipeline = {} as GlPipeline;
|
|
@@ -78,15 +71,19 @@ describe('createGlApplicationRenderView', () => {
|
|
|
78
71
|
|
|
79
72
|
expect(canvas.width).toBe(640);
|
|
80
73
|
expect(canvas.height).toBe(360);
|
|
81
|
-
expect(
|
|
82
|
-
expect(
|
|
83
|
-
|
|
74
|
+
expect(renderGlContract.createGlContextFromCanvasElement).toHaveBeenCalledWith(canvas, { antialias: false });
|
|
75
|
+
expect(renderGlContract.createGlContextState).toHaveBeenCalledWith(
|
|
76
|
+
vi.mocked(renderGlContract.createGlContextFromCanvasElement).mock.results[0].value,
|
|
84
77
|
);
|
|
85
|
-
expect(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
78
|
+
expect(renderGlContract.createGlRenderState).toHaveBeenCalledWith(
|
|
79
|
+
vi.mocked(renderGlContract.createGlContextState).mock.results[0].value,
|
|
80
|
+
pipeline,
|
|
81
|
+
{
|
|
82
|
+
pixelRatio: 2,
|
|
83
|
+
roundPixels: true,
|
|
84
|
+
},
|
|
85
|
+
);
|
|
86
|
+
expect(renderGlContract.createGlRenderTarget).toHaveBeenCalledWith(view.renderState, {
|
|
90
87
|
colorSpace: 'linear',
|
|
91
88
|
depth: 'depth-stencil',
|
|
92
89
|
height: 360,
|
|
@@ -101,18 +98,18 @@ describe('createGlApplicationRenderView', () => {
|
|
|
101
98
|
window.height = 10;
|
|
102
99
|
const canvas = document.createElement('canvas');
|
|
103
100
|
const view = createGlApplicationRenderView(window, canvas, { pipeline });
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
vi.mocked(renderGlContract.invalidateGlRenderStateCache).mockClear();
|
|
102
|
+
vi.mocked(renderGlContract.resizeGlRenderTarget).mockClear();
|
|
106
103
|
|
|
107
104
|
synchronizeApplicationRenderView(view);
|
|
108
|
-
expect(
|
|
109
|
-
expect(
|
|
105
|
+
expect(renderGlContract.invalidateGlRenderStateCache).not.toHaveBeenCalled();
|
|
106
|
+
expect(renderGlContract.resizeGlRenderTarget).not.toHaveBeenCalled();
|
|
110
107
|
|
|
111
108
|
window.width = 30;
|
|
112
109
|
synchronizeApplicationRenderView(view);
|
|
113
110
|
expect(canvas.width).toBe(30);
|
|
114
|
-
expect(
|
|
115
|
-
expect(
|
|
111
|
+
expect(renderGlContract.invalidateGlRenderStateCache).toHaveBeenCalledWith(view.renderState);
|
|
112
|
+
expect(renderGlContract.resizeGlRenderTarget).toHaveBeenCalledWith(view.renderState, view.renderTarget, 30, 10);
|
|
116
113
|
});
|
|
117
114
|
});
|
|
118
115
|
|
|
@@ -123,14 +120,14 @@ describe('destroyGlApplicationRenderView', () => {
|
|
|
123
120
|
window.height = 10;
|
|
124
121
|
const view = createGlApplicationRenderView(window, document.createElement('canvas'), { pipeline });
|
|
125
122
|
attachApplicationRenderView(view);
|
|
126
|
-
|
|
123
|
+
vi.mocked(renderGlContract.resizeGlRenderTarget).mockClear();
|
|
127
124
|
|
|
128
125
|
destroyGlApplicationRenderView(view);
|
|
129
126
|
window.width = 30;
|
|
130
127
|
emitSignal(window.onResize);
|
|
131
128
|
|
|
132
|
-
expect(
|
|
133
|
-
expect(
|
|
134
|
-
expect(
|
|
129
|
+
expect(renderGlContract.resizeGlRenderTarget).not.toHaveBeenCalled();
|
|
130
|
+
expect(renderGlContract.destroyGlRenderTarget).toHaveBeenCalledWith(view.renderState, view.renderTarget);
|
|
131
|
+
expect(renderGlContract.destroyGlRenderState).toHaveBeenCalledWith(view.renderState);
|
|
135
132
|
});
|
|
136
133
|
});
|