@vpmedia/phaser 1.123.0 → 1.124.0
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/index.js +339 -323
- package/dist/index.js.map +1 -1
- package/dist/phaser/core/animation.d.ts +3 -3
- package/dist/phaser/core/animation.d.ts.map +1 -1
- package/dist/phaser/core/animation_manager.d.ts.map +1 -1
- package/dist/phaser/core/animation_parser.d.ts +27 -2
- package/dist/phaser/core/animation_parser.d.ts.map +1 -1
- package/dist/phaser/core/array_set.d.ts +11 -11
- package/dist/phaser/core/array_set.d.ts.map +1 -1
- package/dist/phaser/core/cache.d.ts.map +1 -1
- package/dist/phaser/core/callback.d.ts.map +1 -1
- package/dist/phaser/core/dom.d.ts +125 -19
- package/dist/phaser/core/dom.d.ts.map +1 -1
- package/dist/phaser/core/factory.d.ts +3 -2
- package/dist/phaser/core/factory.d.ts.map +1 -1
- package/dist/phaser/core/input.d.ts +3 -2
- package/dist/phaser/core/input.d.ts.map +1 -1
- package/dist/phaser/core/input_handler.d.ts.map +1 -1
- package/dist/phaser/core/input_mouse.d.ts +5 -1
- package/dist/phaser/core/input_mouse.d.ts.map +1 -1
- package/dist/phaser/core/input_pointer.d.ts +3 -3
- package/dist/phaser/core/input_pointer.d.ts.map +1 -1
- package/dist/phaser/core/input_touch.d.ts +8 -8
- package/dist/phaser/core/input_touch.d.ts.map +1 -1
- package/dist/phaser/core/loader.d.ts +11 -2
- package/dist/phaser/core/loader.d.ts.map +1 -1
- package/dist/phaser/core/loader_parser.d.ts +14 -1
- package/dist/phaser/core/loader_parser.d.ts.map +1 -1
- package/dist/phaser/core/raf.d.ts +1 -1
- package/dist/phaser/core/raf.d.ts.map +1 -1
- package/dist/phaser/core/scale_manager.d.ts.map +1 -1
- package/dist/phaser/core/scene_manager.d.ts.map +1 -1
- package/dist/phaser/core/signal.d.ts.map +1 -1
- package/dist/phaser/core/sound.d.ts.map +1 -1
- package/dist/phaser/core/sound_manager.d.ts +1 -1
- package/dist/phaser/core/sound_manager.d.ts.map +1 -1
- package/dist/phaser/core/stage.d.ts +16 -6
- package/dist/phaser/core/stage.d.ts.map +1 -1
- package/dist/phaser/core/time.d.ts.map +1 -1
- package/dist/phaser/core/timer.d.ts +1 -1
- package/dist/phaser/core/timer.d.ts.map +1 -1
- package/dist/phaser/core/tween.d.ts +13 -5
- package/dist/phaser/core/tween.d.ts.map +1 -1
- package/dist/phaser/core/tween_data.d.ts +9 -7
- package/dist/phaser/core/tween_data.d.ts.map +1 -1
- package/dist/phaser/core/tween_manager.d.ts.map +1 -1
- package/dist/phaser/display/button.d.ts +6 -5
- package/dist/phaser/display/button.d.ts.map +1 -1
- package/dist/phaser/display/canvas/buffer.d.ts +1 -1
- package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/masker.d.ts +1 -1
- package/dist/phaser/display/canvas/masker.d.ts.map +1 -1
- package/dist/phaser/display/canvas/pool.d.ts +2 -2
- package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
- package/dist/phaser/display/canvas/renderer.d.ts +9 -8
- package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/dist/phaser/display/display_object.d.ts +3 -1
- package/dist/phaser/display/display_object.d.ts.map +1 -1
- package/dist/phaser/display/graphics.d.ts +1 -1
- package/dist/phaser/display/graphics.d.ts.map +1 -1
- package/dist/phaser/display/group.d.ts +1 -1
- package/dist/phaser/display/group.d.ts.map +1 -1
- package/dist/phaser/display/image.d.ts +6 -5
- package/dist/phaser/display/image.d.ts.map +1 -1
- package/dist/phaser/display/sprite_util.d.ts +3 -2
- package/dist/phaser/display/sprite_util.d.ts.map +1 -1
- package/dist/phaser/display/text.d.ts +2 -16
- package/dist/phaser/display/text.d.ts.map +1 -1
- package/dist/phaser/display/webgl/abstract_filter.d.ts +14 -8
- package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
- package/dist/phaser/display/webgl/blend_manager.d.ts +2 -3
- package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +11 -5
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts +6 -4
- package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_texture.d.ts +4 -4
- package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics.d.ts +2 -2
- package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/dist/phaser/display/webgl/mask_manager.d.ts +3 -2
- package/dist/phaser/display/webgl/mask_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/render_texture.d.ts +11 -8
- package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/renderer.d.ts +8 -4
- package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/normal.d.ts +28 -3
- package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/dist/phaser/display/webgl/sprite_batch.d.ts +6 -5
- package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/stencil_manager.d.ts +3 -3
- package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture_util.d.ts +2 -2
- package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
- package/dist/phaser/display/webgl/util.d.ts +1 -1
- package/dist/phaser/display/webgl/util.d.ts.map +1 -1
- package/dist/phaser/geom/circle.d.ts.map +1 -1
- package/dist/phaser/geom/line.d.ts +10 -1
- package/dist/phaser/geom/line.d.ts.map +1 -1
- package/dist/phaser/geom/rectangle.d.ts.map +1 -1
- package/dist/phaser/geom/util/circle.d.ts +2 -1
- package/dist/phaser/geom/util/circle.d.ts.map +1 -1
- package/dist/phaser/geom/util/point.d.ts +1 -1
- package/dist/phaser/geom/util/point.d.ts.map +1 -1
- package/dist/phaser/geom/util/rectangle.d.ts +1 -1
- package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
- package/dist/phaser/util/math.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/phaser/core/animation.ts +4 -4
- package/src/phaser/core/animation_manager.ts +10 -10
- package/src/phaser/core/animation_parser.ts +30 -24
- package/src/phaser/core/array_set.ts +27 -27
- package/src/phaser/core/cache.test.ts +33 -33
- package/src/phaser/core/cache.ts +3 -3
- package/src/phaser/core/callback.ts +1 -0
- package/src/phaser/core/callback_context.test.ts +8 -8
- package/src/phaser/core/dom.ts +15 -5
- package/src/phaser/core/factory.ts +9 -2
- package/src/phaser/core/frame_data.test.ts +23 -23
- package/src/phaser/core/input.ts +9 -8
- package/src/phaser/core/input_handler.test.ts +18 -18
- package/src/phaser/core/input_handler.ts +1 -1
- package/src/phaser/core/input_mouse.ts +9 -8
- package/src/phaser/core/input_pointer.test.ts +26 -26
- package/src/phaser/core/input_pointer.ts +3 -3
- package/src/phaser/core/input_touch.ts +8 -8
- package/src/phaser/core/loader.test.ts +26 -26
- package/src/phaser/core/loader.ts +25 -25
- package/src/phaser/core/loader_parser.test.ts +16 -16
- package/src/phaser/core/loader_parser.ts +16 -6
- package/src/phaser/core/raf.ts +1 -1
- package/src/phaser/core/registry.test.ts +6 -6
- package/src/phaser/core/scale_manager.ts +2 -2
- package/src/phaser/core/scene_manager.test.ts +30 -30
- package/src/phaser/core/scene_manager.ts +1 -1
- package/src/phaser/core/signal.test.ts +8 -8
- package/src/phaser/core/signal.ts +1 -1
- package/src/phaser/core/signal_dispatch.test.ts +30 -30
- package/src/phaser/core/sound.ts +20 -8
- package/src/phaser/core/sound_manager.ts +6 -6
- package/src/phaser/core/stage.ts +19 -9
- package/src/phaser/core/time.ts +1 -1
- package/src/phaser/core/timer.test.ts +47 -47
- package/src/phaser/core/timer.ts +1 -1
- package/src/phaser/core/tween.ts +28 -25
- package/src/phaser/core/tween_data.test.ts +119 -0
- package/src/phaser/core/tween_data.ts +54 -39
- package/src/phaser/core/tween_easing.test.ts +5 -5
- package/src/phaser/core/tween_manager.ts +2 -2
- package/src/phaser/display/bitmap_text.test.ts +30 -30
- package/src/phaser/display/button.ts +8 -6
- package/src/phaser/display/canvas/buffer.ts +2 -2
- package/src/phaser/display/canvas/masker.ts +1 -1
- package/src/phaser/display/canvas/pool.test.ts +20 -20
- package/src/phaser/display/canvas/pool.ts +3 -3
- package/src/phaser/display/canvas/renderer.ts +12 -11
- package/src/phaser/display/canvas/util.test.ts +25 -25
- package/src/phaser/display/display_object.ts +3 -1
- package/src/phaser/display/graphics.test.ts +70 -20
- package/src/phaser/display/graphics.ts +38 -32
- package/src/phaser/display/group.ts +4 -4
- package/src/phaser/display/image.ts +28 -25
- package/src/phaser/display/sprite_util.ts +3 -2
- package/src/phaser/display/text.test.ts +28 -25
- package/src/phaser/display/text.ts +21 -18
- package/src/phaser/display/webgl/abstract_filter.ts +20 -10
- package/src/phaser/display/webgl/blend_manager.ts +4 -5
- package/src/phaser/display/webgl/earcut.test.ts +20 -20
- package/src/phaser/display/webgl/fast_sprite_batch.ts +21 -16
- package/src/phaser/display/webgl/filter_manager.ts +7 -4
- package/src/phaser/display/webgl/filter_texture.ts +5 -5
- package/src/phaser/display/webgl/graphics.ts +2 -2
- package/src/phaser/display/webgl/mask_manager.ts +9 -14
- package/src/phaser/display/webgl/render_texture.ts +15 -14
- package/src/phaser/display/webgl/renderer.ts +7 -6
- package/src/phaser/display/webgl/shader/normal.ts +41 -31
- package/src/phaser/display/webgl/shader/shader.test.ts +24 -24
- package/src/phaser/display/webgl/shader_manager.test.ts +18 -18
- package/src/phaser/display/webgl/sprite_batch.ts +8 -8
- package/src/phaser/display/webgl/stencil_manager.ts +4 -4
- package/src/phaser/display/webgl/texture_util.ts +2 -2
- package/src/phaser/display/webgl/util.ts +1 -1
- package/src/phaser/geom/circle.test.ts +38 -38
- package/src/phaser/geom/circle.ts +7 -7
- package/src/phaser/geom/ellipse.test.ts +12 -12
- package/src/phaser/geom/line.test.ts +15 -15
- package/src/phaser/geom/line.ts +5 -2
- package/src/phaser/geom/matrix.test.ts +31 -31
- package/src/phaser/geom/point.test.ts +31 -31
- package/src/phaser/geom/polygon.test.ts +27 -27
- package/src/phaser/geom/rectangle.test.ts +87 -87
- package/src/phaser/geom/rectangle.ts +11 -11
- package/src/phaser/geom/rounded_rectangle.test.ts +9 -9
- package/src/phaser/geom/util/circle.test.ts +5 -5
- package/src/phaser/geom/util/circle.ts +2 -1
- package/src/phaser/geom/util/ellipse.test.ts +2 -2
- package/src/phaser/geom/util/line.test.ts +2 -2
- package/src/phaser/geom/util/matrix.test.ts +4 -4
- package/src/phaser/geom/util/point.test.ts +2 -2
- package/src/phaser/geom/util/point.ts +1 -1
- package/src/phaser/geom/util/polygon.test.ts +2 -2
- package/src/phaser/geom/util/rectangle.test.ts +2 -2
- package/src/phaser/geom/util/rectangle.ts +1 -1
- package/src/phaser/geom/util/rounded_rectangle.test.ts +2 -2
- package/src/phaser/util/math.test.ts +41 -41
- package/src/phaser/util/math.ts +5 -2
|
@@ -31,32 +31,32 @@ const SQUARE_WITH_HOLE = [
|
|
|
31
31
|
10, 10, 20, 10, 20, 20, 10, 20,
|
|
32
32
|
];
|
|
33
33
|
|
|
34
|
-
describe('earcut triangulate', () => {
|
|
35
|
-
describe('simple polygons', () => {
|
|
36
|
-
it('cuts a square into two triangles', () => {
|
|
34
|
+
describe('earcut triangulate', (): void => {
|
|
35
|
+
describe('simple polygons', (): void => {
|
|
36
|
+
it('cuts a square into two triangles', (): void => {
|
|
37
37
|
const triangles = triangulate(SQUARE, null, 2);
|
|
38
38
|
expect(triangles).toHaveLength(6);
|
|
39
39
|
expect(coveredArea(SQUARE, triangles)).toBeCloseTo(100, 6);
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
it('leaves a triangle as one triangle', () => {
|
|
42
|
+
it('leaves a triangle as one triangle', (): void => {
|
|
43
43
|
const triangles = triangulate(TRIANGLE, null, 2);
|
|
44
44
|
expect(triangles).toHaveLength(3);
|
|
45
45
|
expect(coveredArea(TRIANGLE, triangles)).toBeCloseTo(50, 6);
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
it('covers an L shape exactly', () => {
|
|
48
|
+
it('covers an L shape exactly', (): void => {
|
|
49
49
|
const triangles = triangulate(L_SHAPE, null, 2);
|
|
50
50
|
expect(triangles).toHaveLength(12);
|
|
51
51
|
expect(coveredArea(L_SHAPE, triangles)).toBeCloseTo(300, 6);
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
it('covers a concave polygon exactly', () => {
|
|
54
|
+
it('covers a concave polygon exactly', (): void => {
|
|
55
55
|
const triangles = triangulate(CONCAVE, null, 2);
|
|
56
56
|
expect(coveredArea(CONCAVE, triangles)).toBeCloseTo(300, 6);
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
-
it('emits indices in range and in whole triangles', () => {
|
|
59
|
+
it('emits indices in range and in whole triangles', (): void => {
|
|
60
60
|
const triangles = triangulate(L_SHAPE, null, 2);
|
|
61
61
|
expect(triangles.length % 3).toBe(0);
|
|
62
62
|
for (const index of triangles) {
|
|
@@ -66,21 +66,21 @@ describe('earcut triangulate', () => {
|
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
describe('polygons with holes', () => {
|
|
70
|
-
it('covers the outer ring minus the hole', () => {
|
|
69
|
+
describe('polygons with holes', (): void => {
|
|
70
|
+
it('covers the outer ring minus the hole', (): void => {
|
|
71
71
|
const triangles = triangulate(SQUARE_WITH_HOLE, [4], 2);
|
|
72
72
|
expect(coveredArea(SQUARE_WITH_HOLE, triangles)).toBeCloseTo(900 - 100, 6);
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
it('emits whole triangles', () => {
|
|
75
|
+
it('emits whole triangles', (): void => {
|
|
76
76
|
const triangles = triangulate(SQUARE_WITH_HOLE, [4], 2);
|
|
77
77
|
expect(triangles.length % 3).toBe(0);
|
|
78
78
|
expect(triangles.length).toBeGreaterThan(0);
|
|
79
79
|
});
|
|
80
80
|
});
|
|
81
81
|
|
|
82
|
-
describe('winding order', () => {
|
|
83
|
-
it('gives the same coverage whichever way the ring is wound', () => {
|
|
82
|
+
describe('winding order', (): void => {
|
|
83
|
+
it('gives the same coverage whichever way the ring is wound', (): void => {
|
|
84
84
|
const clockwise = [0, 0, 0, 10, 10, 10, 10, 0];
|
|
85
85
|
const counter = [0, 0, 10, 0, 10, 10, 0, 10];
|
|
86
86
|
expect(coveredArea(clockwise, triangulate(clockwise, null, 2))).toBeCloseTo(
|
|
@@ -90,32 +90,32 @@ describe('earcut triangulate', () => {
|
|
|
90
90
|
});
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
-
describe('degenerate input', () => {
|
|
94
|
-
it('returns nothing for an empty ring', () => {
|
|
93
|
+
describe('degenerate input', (): void => {
|
|
94
|
+
it('returns nothing for an empty ring', (): void => {
|
|
95
95
|
expect(triangulate([], null, 2)).toStrictEqual([]);
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
-
it('returns nothing for a single point', () => {
|
|
98
|
+
it('returns nothing for a single point', (): void => {
|
|
99
99
|
expect(triangulate([1, 1], null, 2)).toStrictEqual([]);
|
|
100
100
|
});
|
|
101
101
|
|
|
102
|
-
it('returns nothing for a two point ring', () => {
|
|
102
|
+
it('returns nothing for a two point ring', (): void => {
|
|
103
103
|
expect(triangulate([0, 0, 10, 10], null, 2)).toStrictEqual([]);
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
-
it('returns nothing for a zero area ring', () => {
|
|
106
|
+
it('returns nothing for a zero area ring', (): void => {
|
|
107
107
|
expect(triangulate([0, 0, 10, 10, 20, 20], null, 2)).toStrictEqual([]);
|
|
108
108
|
});
|
|
109
109
|
|
|
110
|
-
it('drops duplicated consecutive points', () => {
|
|
110
|
+
it('drops duplicated consecutive points', (): void => {
|
|
111
111
|
const withDuplicate = [0, 0, 0, 0, 10, 0, 10, 10, 0, 10];
|
|
112
112
|
expect(coveredArea(withDuplicate, triangulate(withDuplicate, null, 2))).toBeCloseTo(100, 6);
|
|
113
113
|
});
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
-
describe('large rings', () => {
|
|
116
|
+
describe('large rings', (): void => {
|
|
117
117
|
// Past 80 vertices earcut switches to the z-order curve hash, a separate code path.
|
|
118
|
-
it('covers a many sided polygon exactly, exercising the hashed path', () => {
|
|
118
|
+
it('covers a many sided polygon exactly, exercising the hashed path', (): void => {
|
|
119
119
|
const sides = 200;
|
|
120
120
|
const radius = 100;
|
|
121
121
|
const ring: number[] = [];
|
|
@@ -2,6 +2,11 @@ import type { BaseTexture } from './base_texture.js';
|
|
|
2
2
|
import type { IdentifiedWebGLRenderingContext } from './util.js';
|
|
3
3
|
import type { Image } from '../../display/image.js';
|
|
4
4
|
import type { RenderSession } from '../render_session.js';
|
|
5
|
+
import type { DisplayObject } from '../display_object.js';
|
|
6
|
+
|
|
7
|
+
/** What the fast batch draws: a container whose children are plain images sharing one texture. */
|
|
8
|
+
export type FastBatchRoot = DisplayObject & { children: Image[] };
|
|
9
|
+
import type { FastShader } from './shader/fast.js';
|
|
5
10
|
|
|
6
11
|
export class FastSpriteBatch {
|
|
7
12
|
public gl!: IdentifiedWebGLRenderingContext;
|
|
@@ -16,10 +21,10 @@ export class FastSpriteBatch {
|
|
|
16
21
|
public drawing!: boolean;
|
|
17
22
|
public currentBatchSize!: number;
|
|
18
23
|
public currentBaseTexture!: BaseTexture | null;
|
|
19
|
-
public currentBlendMode!:
|
|
24
|
+
public currentBlendMode!: number;
|
|
20
25
|
public renderSession!: RenderSession;
|
|
21
|
-
public shader!:
|
|
22
|
-
public matrix!:
|
|
26
|
+
public shader!: FastShader | null;
|
|
27
|
+
public matrix!: Float32Array | number[] | null;
|
|
23
28
|
/**
|
|
24
29
|
* Creates a new FastSpriteBatch instance.
|
|
25
30
|
* @param {WebGLRenderingContext & { id: number }} gl - The WebGL rendering context.
|
|
@@ -75,7 +80,7 @@ export class FastSpriteBatch {
|
|
|
75
80
|
* @param {object} spriteBatch - The sprite batch to render.
|
|
76
81
|
* @param {object} renderSession - The render session to use.
|
|
77
82
|
*/
|
|
78
|
-
public begin(spriteBatch:
|
|
83
|
+
public begin(spriteBatch: FastBatchRoot, renderSession: RenderSession): void {
|
|
79
84
|
this.renderSession = renderSession;
|
|
80
85
|
this.shader = this.renderSession.shaderManager.fastShader;
|
|
81
86
|
this.matrix = spriteBatch.worldTransform.toArray(true);
|
|
@@ -93,12 +98,12 @@ export class FastSpriteBatch {
|
|
|
93
98
|
* Flushes the sprite batch to WebGL.
|
|
94
99
|
* @param {object} spriteBatch - The sprite batch to flush.
|
|
95
100
|
*/
|
|
96
|
-
public render(spriteBatch:
|
|
101
|
+
public render(spriteBatch: FastBatchRoot): void {
|
|
97
102
|
const { children } = spriteBatch;
|
|
98
103
|
const [sprite] = children;
|
|
99
104
|
// if the uvs have not updated then no point rendering just yet!
|
|
100
105
|
// check texture.
|
|
101
|
-
if (!sprite
|
|
106
|
+
if (!sprite?.texture._uvs) {
|
|
102
107
|
return;
|
|
103
108
|
}
|
|
104
109
|
this.currentBaseTexture = sprite.texture.baseTexture;
|
|
@@ -107,8 +112,8 @@ export class FastSpriteBatch {
|
|
|
107
112
|
this.flush();
|
|
108
113
|
this.renderSession.blendModeManager.setBlendMode(sprite.blendMode);
|
|
109
114
|
}
|
|
110
|
-
for (
|
|
111
|
-
this.renderSprite(
|
|
115
|
+
for (const child of children) {
|
|
116
|
+
this.renderSprite(child);
|
|
112
117
|
}
|
|
113
118
|
this.flush();
|
|
114
119
|
}
|
|
@@ -268,16 +273,16 @@ export class FastSpriteBatch {
|
|
|
268
273
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
|
|
269
274
|
// set the projection
|
|
270
275
|
const { projection } = this.renderSession;
|
|
271
|
-
gl.uniform2f(this.shader
|
|
276
|
+
gl.uniform2f(this.shader!.projectionVector, projection.x, projection.y);
|
|
272
277
|
// set the matrix
|
|
273
|
-
gl.uniformMatrix3fv(this.shader
|
|
278
|
+
gl.uniformMatrix3fv(this.shader!.uMatrix, false, this.matrix!);
|
|
274
279
|
// set the pointers
|
|
275
280
|
const stride = this.vertSize * 4;
|
|
276
|
-
gl.vertexAttribPointer(this.shader
|
|
277
|
-
gl.vertexAttribPointer(this.shader
|
|
278
|
-
gl.vertexAttribPointer(this.shader
|
|
279
|
-
gl.vertexAttribPointer(this.shader
|
|
280
|
-
gl.vertexAttribPointer(this.shader
|
|
281
|
-
gl.vertexAttribPointer(this.shader
|
|
281
|
+
gl.vertexAttribPointer(this.shader!.aVertexPosition, 2, gl.FLOAT, false, stride, 0);
|
|
282
|
+
gl.vertexAttribPointer(this.shader!.aPositionCoord, 2, gl.FLOAT, false, stride, 2 * 4);
|
|
283
|
+
gl.vertexAttribPointer(this.shader!.aScale, 2, gl.FLOAT, false, stride, 4 * 4);
|
|
284
|
+
gl.vertexAttribPointer(this.shader!.aRotation, 1, gl.FLOAT, false, stride, 6 * 4);
|
|
285
|
+
gl.vertexAttribPointer(this.shader!.aTextureCoord, 2, gl.FLOAT, false, stride, 7 * 4);
|
|
286
|
+
gl.vertexAttribPointer(this.shader!.colorAttribute, 1, gl.FLOAT, false, stride, 9 * 4);
|
|
282
287
|
}
|
|
283
288
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import type { AbstractFilter } from './abstract_filter.js';
|
|
2
|
+
import type { FilterTexture } from './filter_texture.js';
|
|
3
|
+
|
|
1
4
|
export class WebGLFilterManager {
|
|
2
5
|
public gl!: WebGLRenderingContext;
|
|
3
|
-
public texturePool!:
|
|
4
|
-
public filterStack!:
|
|
5
|
-
public offsetX!:
|
|
6
|
-
public offsetY!:
|
|
6
|
+
public texturePool!: FilterTexture[];
|
|
7
|
+
public filterStack!: AbstractFilter[];
|
|
8
|
+
public offsetX!: number;
|
|
9
|
+
public offsetY!: number;
|
|
7
10
|
/**
|
|
8
11
|
* Creates a new FilterManager instance.
|
|
9
12
|
*/
|
|
@@ -3,10 +3,10 @@ import { SCALE_LINEAR } from '../../core/const.js';
|
|
|
3
3
|
export class FilterTexture {
|
|
4
4
|
public width!: number;
|
|
5
5
|
public height!: number;
|
|
6
|
-
public gl!:
|
|
7
|
-
public frameBuffer!:
|
|
8
|
-
public texture!:
|
|
9
|
-
public renderBuffer!:
|
|
6
|
+
public gl!: WebGLRenderingContext;
|
|
7
|
+
public frameBuffer!: WebGLFramebuffer | null;
|
|
8
|
+
public texture!: WebGLTexture | null;
|
|
9
|
+
public renderBuffer!: WebGLRenderbuffer | null;
|
|
10
10
|
/**
|
|
11
11
|
* Creates a new FilterTexture instance.
|
|
12
12
|
* @param {WebGLRenderingContext} gl - The WebGL rendering context.
|
|
@@ -72,6 +72,6 @@ export class FilterTexture {
|
|
|
72
72
|
this.frameBuffer = null;
|
|
73
73
|
this.texture = null;
|
|
74
74
|
this.renderBuffer = null;
|
|
75
|
-
this.gl = null
|
|
75
|
+
this.gl = null!;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -26,7 +26,7 @@ export const getStencilBufferLimit = (): number => {
|
|
|
26
26
|
* Updates the graphics data for WebGL rendering.
|
|
27
27
|
* @returns {object[]} The graphics data array.
|
|
28
28
|
*/
|
|
29
|
-
export const getGraphicsDataPool = () => {
|
|
29
|
+
export const getGraphicsDataPool = (): GraphicsData[] => {
|
|
30
30
|
globalThis.PhaserRegistry.graphicsDataPool ??= [];
|
|
31
31
|
return globalThis.PhaserRegistry.graphicsDataPool;
|
|
32
32
|
};
|
|
@@ -37,7 +37,7 @@ export const getGraphicsDataPool = () => {
|
|
|
37
37
|
* @param {number} type - The type of graphics data to create.
|
|
38
38
|
* @returns {object} The newly created graphics data object.
|
|
39
39
|
*/
|
|
40
|
-
export const switchMode = (webGL: GraphicsWebGLBucket, type: number) => {
|
|
40
|
+
export const switchMode = (webGL: GraphicsWebGLBucket, type: number): GraphicsData => {
|
|
41
41
|
let webGLData;
|
|
42
42
|
if (webGL.data.length === 0) {
|
|
43
43
|
webGLData = getGraphicsDataPool().pop() ?? new GraphicsData(webGL.gl);
|
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import { updateGraphics } from './graphics.js';
|
|
2
2
|
import type { RenderSession } from '../render_session.js';
|
|
3
|
+
import type { Graphics } from '../graphics.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Sets up the mask manager for WebGL rendering.
|
|
6
7
|
* @param {object} maskData - The mask data to apply.
|
|
7
8
|
* @param {object} renderSession - The rendering session.
|
|
8
9
|
*/
|
|
9
|
-
export const pushMask = (maskData:
|
|
10
|
+
export const pushMask = (maskData: Graphics, renderSession: RenderSession): void => {
|
|
10
11
|
const { gl } = renderSession;
|
|
11
12
|
if (maskData.dirty) {
|
|
12
13
|
updateGraphics(maskData, gl);
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
maskData._webGL[gl.id].data === undefined ||
|
|
17
|
-
maskData._webGL[gl.id].data.length === 0
|
|
18
|
-
) {
|
|
15
|
+
const [first] = maskData._webGL[gl.id]?.data ?? [];
|
|
16
|
+
if (!first) {
|
|
19
17
|
return;
|
|
20
18
|
}
|
|
21
|
-
renderSession.stencilManager.pushStencil(maskData,
|
|
19
|
+
renderSession.stencilManager.pushStencil(maskData, first, renderSession);
|
|
22
20
|
};
|
|
23
21
|
|
|
24
22
|
/**
|
|
@@ -26,14 +24,11 @@ export const pushMask = (maskData: any, renderSession: RenderSession): void => {
|
|
|
26
24
|
* @param {object} maskData - The mask data to apply.
|
|
27
25
|
* @param {object} renderSession - The rendering session.
|
|
28
26
|
*/
|
|
29
|
-
export const popMask = (maskData:
|
|
27
|
+
export const popMask = (maskData: Graphics | null, renderSession: RenderSession): void => {
|
|
30
28
|
const { gl } = renderSession;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
maskData._webGL[gl.id].data === undefined ||
|
|
34
|
-
maskData._webGL[gl.id].data.length === 0
|
|
35
|
-
) {
|
|
29
|
+
const [first] = maskData?._webGL[gl.id]?.data ?? [];
|
|
30
|
+
if (!first) {
|
|
36
31
|
return;
|
|
37
32
|
}
|
|
38
|
-
renderSession.stencilManager.popStencil(maskData
|
|
33
|
+
renderSession.stencilManager.popStencil(maskData!, first, renderSession);
|
|
39
34
|
};
|
|
@@ -9,17 +9,16 @@ import type { WebGLRenderer } from './renderer.js';
|
|
|
9
9
|
import type { CanvasRenderer } from '../canvas/renderer.js';
|
|
10
10
|
|
|
11
11
|
export class RenderTexture extends Texture {
|
|
12
|
-
[key: string]: any;
|
|
13
12
|
declare public width: number;
|
|
14
13
|
declare public height: number;
|
|
15
14
|
public resolution!: number;
|
|
16
|
-
declare public frame:
|
|
17
|
-
declare public crop:
|
|
18
|
-
public renderer!:
|
|
19
|
-
public textureBuffer!:
|
|
20
|
-
public render!:
|
|
21
|
-
public projection
|
|
22
|
-
declare public valid:
|
|
15
|
+
declare public frame: Rectangle;
|
|
16
|
+
declare public crop: Rectangle;
|
|
17
|
+
public renderer!: WebGLRenderer | CanvasRenderer;
|
|
18
|
+
public textureBuffer!: FilterTexture | CanvasBuffer;
|
|
19
|
+
public render!: () => void;
|
|
20
|
+
public projection: Point | null = null;
|
|
21
|
+
declare public valid: boolean;
|
|
23
22
|
/**
|
|
24
23
|
* Creates a new RenderTexture instance.
|
|
25
24
|
* @param {number} width - The width of the render texture.
|
|
@@ -52,17 +51,19 @@ export class RenderTexture extends Texture {
|
|
|
52
51
|
this.frame = new Rectangle(0, 0, this.width * this.resolution, this.height * this.resolution);
|
|
53
52
|
this.crop = new Rectangle(0, 0, this.width * this.resolution, this.height * this.resolution);
|
|
54
53
|
this.renderer = renderer;
|
|
55
|
-
if (
|
|
56
|
-
const { gl } =
|
|
54
|
+
if (renderer.type === RENDER_WEBGL) {
|
|
55
|
+
const { gl } = renderer as WebGLRenderer;
|
|
57
56
|
this.baseTexture._dirty[gl.id] = false;
|
|
58
|
-
|
|
59
|
-
this.
|
|
57
|
+
const buffer = new FilterTexture(gl, this.width, this.height, this.baseTexture.scaleMode);
|
|
58
|
+
this.textureBuffer = buffer;
|
|
59
|
+
this.baseTexture._glTextures[gl.id] = buffer.texture;
|
|
60
60
|
this.render = this.renderWebGL;
|
|
61
61
|
this.projection = new Point(this.width * 0.5, -this.height * 0.5);
|
|
62
62
|
} else {
|
|
63
63
|
this.render = this.renderCanvas;
|
|
64
|
-
|
|
65
|
-
this.
|
|
64
|
+
const buffer = new CanvasBuffer(this.width * this.resolution, this.height * this.resolution);
|
|
65
|
+
this.textureBuffer = buffer;
|
|
66
|
+
this.baseTexture.source = buffer.canvas;
|
|
66
67
|
}
|
|
67
68
|
this.valid = true;
|
|
68
69
|
this._updateUvs();
|
|
@@ -35,6 +35,7 @@ import { WebGLStencilManager } from './stencil_manager.js';
|
|
|
35
35
|
import type { IdentifiedWebGLRenderingContext } from './util.js';
|
|
36
36
|
import { getWebGLContextErrorCode, getWebGLContextErrorName } from './util.js';
|
|
37
37
|
import type { RenderSession } from '../render_session.js';
|
|
38
|
+
import type { DisplayObject } from '../display_object.js';
|
|
38
39
|
|
|
39
40
|
export class WebGLRenderer {
|
|
40
41
|
public gl!: IdentifiedWebGLRenderingContext;
|
|
@@ -52,9 +53,9 @@ export class WebGLRenderer {
|
|
|
52
53
|
public offset!: Point;
|
|
53
54
|
public shaderManager!: WebGLShaderManager;
|
|
54
55
|
public spriteBatch!: WebGLSpriteBatch;
|
|
55
|
-
public filterManager!:
|
|
56
|
-
public stencilManager!:
|
|
57
|
-
public blendModeManager!:
|
|
56
|
+
public filterManager!: WebGLFilterManager;
|
|
57
|
+
public stencilManager!: WebGLStencilManager;
|
|
58
|
+
public blendModeManager!: WebGLBlendModeManager;
|
|
58
59
|
public renderSession!: RenderSession;
|
|
59
60
|
/**
|
|
60
61
|
* Creates a new WebGLRenderer instance.
|
|
@@ -204,7 +205,7 @@ export class WebGLRenderer {
|
|
|
204
205
|
* @param {object} buffer - The render buffer.
|
|
205
206
|
* @param {Matrix} matrix - The transformation matrix.
|
|
206
207
|
*/
|
|
207
|
-
public renderDisplayObject(displayObject:
|
|
208
|
+
public renderDisplayObject(displayObject: DisplayObject, projection: Point, buffer?: WebGLFramebuffer | null): void {
|
|
208
209
|
this.renderSession.blendModeManager.setBlendMode(BLEND_NORMAL);
|
|
209
210
|
// reset the render session data..
|
|
210
211
|
this.renderSession.drawCount = 0;
|
|
@@ -217,9 +218,9 @@ export class WebGLRenderer {
|
|
|
217
218
|
// start the sprite batch
|
|
218
219
|
this.spriteBatch.begin(this.renderSession);
|
|
219
220
|
// start the filter manager
|
|
220
|
-
this.filterManager.begin(
|
|
221
|
+
this.filterManager.begin();
|
|
221
222
|
// render the scene!
|
|
222
|
-
displayObject.renderWebGL(this.renderSession
|
|
223
|
+
displayObject.renderWebGL(this.renderSession);
|
|
223
224
|
// finish the sprite batch
|
|
224
225
|
this.spriteBatch.end();
|
|
225
226
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { v4 as uuidv4 } from 'uuid';
|
|
2
2
|
import { compileProgram } from '../util.js';
|
|
3
|
+
import type { Texture } from '../texture.js';
|
|
3
4
|
|
|
4
5
|
const defaultVertexSrc = [
|
|
5
6
|
'attribute vec2 aVertexPosition;',
|
|
@@ -21,7 +22,7 @@ const defaultVertexSrc = [
|
|
|
21
22
|
'}',
|
|
22
23
|
];
|
|
23
24
|
|
|
24
|
-
const glMember = (gl: WebGLRenderingContext, name: string):
|
|
25
|
+
const glMember = (gl: WebGLRenderingContext, name: string): GLenum => (gl as unknown as Record<string, GLenum>)[name]!;
|
|
25
26
|
|
|
26
27
|
/** Applies one of the gl uniform setters, whose signatures vary by uniform kind. */
|
|
27
28
|
const callUniformSetter = (setter: unknown, gl: WebGLRenderingContext, ...args: unknown[]): void => {
|
|
@@ -32,9 +33,29 @@ const callUniformSetter = (setter: unknown, gl: WebGLRenderingContext, ...args:
|
|
|
32
33
|
|
|
33
34
|
// this shader is used for the default sprite rendering
|
|
34
35
|
|
|
36
|
+
/** The extra texture parameters a sampler uniform may carry, as the consumer supplied them. */
|
|
37
|
+
export type ShaderTextureData = {
|
|
38
|
+
magFilter?: GLenum;
|
|
39
|
+
minFilter?: GLenum;
|
|
40
|
+
wrapS?: GLenum;
|
|
41
|
+
wrapT?: GLenum;
|
|
42
|
+
luminance?: boolean;
|
|
43
|
+
repeat?: boolean;
|
|
44
|
+
flipY?: boolean;
|
|
45
|
+
width?: number;
|
|
46
|
+
height?: number;
|
|
47
|
+
border?: number;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** A sampler uniform, whose value is the texture to bind. */
|
|
51
|
+
export type SamplerUniform = ShaderUniform & { value: Texture | null };
|
|
52
|
+
|
|
53
|
+
/** A vector uniform value, read component-wise by the setter matching its arity. */
|
|
54
|
+
export type UniformVector = { x: number; y: number; z?: number; w?: number };
|
|
55
|
+
|
|
35
56
|
export type ShaderUniform = {
|
|
36
57
|
type: string;
|
|
37
|
-
value:
|
|
58
|
+
value: unknown;
|
|
38
59
|
uniformLocation?: WebGLUniformLocation | null;
|
|
39
60
|
/** One of the gl uniform setters. Their arities differ by uniform kind, so the stored value is
|
|
40
61
|
* opaque and applied through callUniformSetter. */
|
|
@@ -42,7 +63,7 @@ export type ShaderUniform = {
|
|
|
42
63
|
glMatrix?: boolean;
|
|
43
64
|
glValueLength?: number;
|
|
44
65
|
transpose?: boolean;
|
|
45
|
-
textureData?:
|
|
66
|
+
textureData?: ShaderTextureData;
|
|
46
67
|
_init?: boolean;
|
|
47
68
|
};
|
|
48
69
|
|
|
@@ -141,7 +162,7 @@ export class NormalShader {
|
|
|
141
162
|
if (type === 'sampler2D') {
|
|
142
163
|
uniform._init = false;
|
|
143
164
|
if (uniform.value !== null) {
|
|
144
|
-
this.initSampler2D(uniform);
|
|
165
|
+
this.initSampler2D(uniform as SamplerUniform);
|
|
145
166
|
}
|
|
146
167
|
} else if (type === 'mat2' || type === 'mat3' || type === 'mat4') {
|
|
147
168
|
// These require special handling
|
|
@@ -174,13 +195,14 @@ export class NormalShader {
|
|
|
174
195
|
* Sets a uniform value for this shader.
|
|
175
196
|
* @param {object} uniform - The uniform to set.
|
|
176
197
|
*/
|
|
177
|
-
public initSampler2D(uniform:
|
|
178
|
-
|
|
198
|
+
public initSampler2D(uniform: SamplerUniform): void {
|
|
199
|
+
const texture = uniform.value;
|
|
200
|
+
if (!texture?.baseTexture.hasLoaded) {
|
|
179
201
|
return;
|
|
180
202
|
}
|
|
181
203
|
const { gl } = this;
|
|
182
204
|
gl.activeTexture(glMember(gl, `TEXTURE${this.textureCount}`));
|
|
183
|
-
gl.bindTexture(gl.TEXTURE_2D,
|
|
205
|
+
gl.bindTexture(gl.TEXTURE_2D, texture.baseTexture._glTextures[gl.id] ?? null);
|
|
184
206
|
// Extended texture data
|
|
185
207
|
if (uniform.textureData) {
|
|
186
208
|
const data = uniform.textureData;
|
|
@@ -211,14 +233,14 @@ export class NormalShader {
|
|
|
211
233
|
gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, border, format, gl.UNSIGNED_BYTE, null);
|
|
212
234
|
} else {
|
|
213
235
|
// void texImage2D(GLenum target, GLint level, GLenum internalformat, GLenum format, GLenum type, ImageData? pixels);
|
|
214
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, format, gl.RGBA, gl.UNSIGNED_BYTE,
|
|
236
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, format, gl.RGBA, gl.UNSIGNED_BYTE, texture.baseTexture.source!);
|
|
215
237
|
}
|
|
216
238
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);
|
|
217
239
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);
|
|
218
240
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapS);
|
|
219
241
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrapT);
|
|
220
242
|
}
|
|
221
|
-
gl.uniform1i(uniform.uniformLocation, this.textureCount);
|
|
243
|
+
gl.uniform1i(uniform.uniformLocation ?? null, this.textureCount);
|
|
222
244
|
uniform._init = true;
|
|
223
245
|
this.textureCount += 1;
|
|
224
246
|
}
|
|
@@ -231,6 +253,8 @@ export class NormalShader {
|
|
|
231
253
|
const { gl } = this;
|
|
232
254
|
// This would probably be faster in an array and it would guarantee key order
|
|
233
255
|
for (const uniform of Object.values(this.uniforms)) {
|
|
256
|
+
const vector = uniform.value as UniformVector;
|
|
257
|
+
const sampler = uniform as SamplerUniform;
|
|
234
258
|
if (uniform.glValueLength === 1) {
|
|
235
259
|
if (uniform.glMatrix === true) {
|
|
236
260
|
callUniformSetter(uniform.glFunc, gl, uniform.uniformLocation, uniform.transpose, uniform.value);
|
|
@@ -238,40 +262,26 @@ export class NormalShader {
|
|
|
238
262
|
callUniformSetter(uniform.glFunc, gl, uniform.uniformLocation, uniform.value);
|
|
239
263
|
}
|
|
240
264
|
} else if (uniform.glValueLength === 2) {
|
|
241
|
-
callUniformSetter(uniform.glFunc, gl, uniform.uniformLocation,
|
|
265
|
+
callUniformSetter(uniform.glFunc, gl, uniform.uniformLocation, vector.x, vector.y);
|
|
242
266
|
} else if (uniform.glValueLength === 3) {
|
|
243
|
-
callUniformSetter(
|
|
244
|
-
uniform.glFunc,
|
|
245
|
-
gl,
|
|
246
|
-
uniform.uniformLocation,
|
|
247
|
-
uniform.value.x,
|
|
248
|
-
uniform.value.y,
|
|
249
|
-
uniform.value.z
|
|
250
|
-
);
|
|
267
|
+
callUniformSetter(uniform.glFunc, gl, uniform.uniformLocation, vector.x, vector.y, vector.z);
|
|
251
268
|
} else if (uniform.glValueLength === 4) {
|
|
252
|
-
callUniformSetter(
|
|
253
|
-
uniform.glFunc,
|
|
254
|
-
gl,
|
|
255
|
-
uniform.uniformLocation,
|
|
256
|
-
uniform.value.x,
|
|
257
|
-
uniform.value.y,
|
|
258
|
-
uniform.value.z,
|
|
259
|
-
uniform.value.w
|
|
260
|
-
);
|
|
269
|
+
callUniformSetter(uniform.glFunc, gl, uniform.uniformLocation, vector.x, vector.y, vector.z, vector.w);
|
|
261
270
|
} else if (uniform.type === 'sampler2D') {
|
|
262
271
|
if (uniform._init) {
|
|
263
272
|
gl.activeTexture(glMember(gl, `TEXTURE${this.textureCount}`));
|
|
264
|
-
|
|
265
|
-
|
|
273
|
+
const { baseTexture } = sampler.value!;
|
|
274
|
+
if (baseTexture._dirty[gl.id]) {
|
|
275
|
+
globalThis.PhaserRegistry.INSTANCES[gl.id]?.updateTexture(baseTexture);
|
|
266
276
|
} else {
|
|
267
277
|
// bind the current texture
|
|
268
|
-
gl.bindTexture(gl.TEXTURE_2D,
|
|
278
|
+
gl.bindTexture(gl.TEXTURE_2D, baseTexture._glTextures[gl.id] ?? null);
|
|
269
279
|
}
|
|
270
280
|
// gl.bindTexture(gl.TEXTURE_2D, uniform.value.baseTexture._glTextures[gl.id] || PIXI.createWebGLTexture( uniform.value.baseTexture, gl));
|
|
271
281
|
gl.uniform1i(uniform.uniformLocation ?? null, this.textureCount);
|
|
272
282
|
this.textureCount += 1;
|
|
273
283
|
} else {
|
|
274
|
-
this.initSampler2D(
|
|
284
|
+
this.initSampler2D(sampler);
|
|
275
285
|
}
|
|
276
286
|
}
|
|
277
287
|
}
|