@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.
Files changed (206) hide show
  1. package/dist/index.js +339 -323
  2. package/dist/index.js.map +1 -1
  3. package/dist/phaser/core/animation.d.ts +3 -3
  4. package/dist/phaser/core/animation.d.ts.map +1 -1
  5. package/dist/phaser/core/animation_manager.d.ts.map +1 -1
  6. package/dist/phaser/core/animation_parser.d.ts +27 -2
  7. package/dist/phaser/core/animation_parser.d.ts.map +1 -1
  8. package/dist/phaser/core/array_set.d.ts +11 -11
  9. package/dist/phaser/core/array_set.d.ts.map +1 -1
  10. package/dist/phaser/core/cache.d.ts.map +1 -1
  11. package/dist/phaser/core/callback.d.ts.map +1 -1
  12. package/dist/phaser/core/dom.d.ts +125 -19
  13. package/dist/phaser/core/dom.d.ts.map +1 -1
  14. package/dist/phaser/core/factory.d.ts +3 -2
  15. package/dist/phaser/core/factory.d.ts.map +1 -1
  16. package/dist/phaser/core/input.d.ts +3 -2
  17. package/dist/phaser/core/input.d.ts.map +1 -1
  18. package/dist/phaser/core/input_handler.d.ts.map +1 -1
  19. package/dist/phaser/core/input_mouse.d.ts +5 -1
  20. package/dist/phaser/core/input_mouse.d.ts.map +1 -1
  21. package/dist/phaser/core/input_pointer.d.ts +3 -3
  22. package/dist/phaser/core/input_pointer.d.ts.map +1 -1
  23. package/dist/phaser/core/input_touch.d.ts +8 -8
  24. package/dist/phaser/core/input_touch.d.ts.map +1 -1
  25. package/dist/phaser/core/loader.d.ts +11 -2
  26. package/dist/phaser/core/loader.d.ts.map +1 -1
  27. package/dist/phaser/core/loader_parser.d.ts +14 -1
  28. package/dist/phaser/core/loader_parser.d.ts.map +1 -1
  29. package/dist/phaser/core/raf.d.ts +1 -1
  30. package/dist/phaser/core/raf.d.ts.map +1 -1
  31. package/dist/phaser/core/scale_manager.d.ts.map +1 -1
  32. package/dist/phaser/core/scene_manager.d.ts.map +1 -1
  33. package/dist/phaser/core/signal.d.ts.map +1 -1
  34. package/dist/phaser/core/sound.d.ts.map +1 -1
  35. package/dist/phaser/core/sound_manager.d.ts +1 -1
  36. package/dist/phaser/core/sound_manager.d.ts.map +1 -1
  37. package/dist/phaser/core/stage.d.ts +16 -6
  38. package/dist/phaser/core/stage.d.ts.map +1 -1
  39. package/dist/phaser/core/time.d.ts.map +1 -1
  40. package/dist/phaser/core/timer.d.ts +1 -1
  41. package/dist/phaser/core/timer.d.ts.map +1 -1
  42. package/dist/phaser/core/tween.d.ts +13 -5
  43. package/dist/phaser/core/tween.d.ts.map +1 -1
  44. package/dist/phaser/core/tween_data.d.ts +9 -7
  45. package/dist/phaser/core/tween_data.d.ts.map +1 -1
  46. package/dist/phaser/core/tween_manager.d.ts.map +1 -1
  47. package/dist/phaser/display/button.d.ts +6 -5
  48. package/dist/phaser/display/button.d.ts.map +1 -1
  49. package/dist/phaser/display/canvas/buffer.d.ts +1 -1
  50. package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
  51. package/dist/phaser/display/canvas/masker.d.ts +1 -1
  52. package/dist/phaser/display/canvas/masker.d.ts.map +1 -1
  53. package/dist/phaser/display/canvas/pool.d.ts +2 -2
  54. package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
  55. package/dist/phaser/display/canvas/renderer.d.ts +9 -8
  56. package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
  57. package/dist/phaser/display/display_object.d.ts +3 -1
  58. package/dist/phaser/display/display_object.d.ts.map +1 -1
  59. package/dist/phaser/display/graphics.d.ts +1 -1
  60. package/dist/phaser/display/graphics.d.ts.map +1 -1
  61. package/dist/phaser/display/group.d.ts +1 -1
  62. package/dist/phaser/display/group.d.ts.map +1 -1
  63. package/dist/phaser/display/image.d.ts +6 -5
  64. package/dist/phaser/display/image.d.ts.map +1 -1
  65. package/dist/phaser/display/sprite_util.d.ts +3 -2
  66. package/dist/phaser/display/sprite_util.d.ts.map +1 -1
  67. package/dist/phaser/display/text.d.ts +2 -16
  68. package/dist/phaser/display/text.d.ts.map +1 -1
  69. package/dist/phaser/display/webgl/abstract_filter.d.ts +14 -8
  70. package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
  71. package/dist/phaser/display/webgl/blend_manager.d.ts +2 -3
  72. package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
  73. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +11 -5
  74. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
  75. package/dist/phaser/display/webgl/filter_manager.d.ts +6 -4
  76. package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
  77. package/dist/phaser/display/webgl/filter_texture.d.ts +4 -4
  78. package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
  79. package/dist/phaser/display/webgl/graphics.d.ts +2 -2
  80. package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
  81. package/dist/phaser/display/webgl/mask_manager.d.ts +3 -2
  82. package/dist/phaser/display/webgl/mask_manager.d.ts.map +1 -1
  83. package/dist/phaser/display/webgl/render_texture.d.ts +11 -8
  84. package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
  85. package/dist/phaser/display/webgl/renderer.d.ts +8 -4
  86. package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
  87. package/dist/phaser/display/webgl/shader/normal.d.ts +28 -3
  88. package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
  89. package/dist/phaser/display/webgl/sprite_batch.d.ts +6 -5
  90. package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
  91. package/dist/phaser/display/webgl/stencil_manager.d.ts +3 -3
  92. package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
  93. package/dist/phaser/display/webgl/texture_util.d.ts +2 -2
  94. package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
  95. package/dist/phaser/display/webgl/util.d.ts +1 -1
  96. package/dist/phaser/display/webgl/util.d.ts.map +1 -1
  97. package/dist/phaser/geom/circle.d.ts.map +1 -1
  98. package/dist/phaser/geom/line.d.ts +10 -1
  99. package/dist/phaser/geom/line.d.ts.map +1 -1
  100. package/dist/phaser/geom/rectangle.d.ts.map +1 -1
  101. package/dist/phaser/geom/util/circle.d.ts +2 -1
  102. package/dist/phaser/geom/util/circle.d.ts.map +1 -1
  103. package/dist/phaser/geom/util/point.d.ts +1 -1
  104. package/dist/phaser/geom/util/point.d.ts.map +1 -1
  105. package/dist/phaser/geom/util/rectangle.d.ts +1 -1
  106. package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
  107. package/dist/phaser/util/math.d.ts.map +1 -1
  108. package/package.json +1 -1
  109. package/src/phaser/core/animation.ts +4 -4
  110. package/src/phaser/core/animation_manager.ts +10 -10
  111. package/src/phaser/core/animation_parser.ts +30 -24
  112. package/src/phaser/core/array_set.ts +27 -27
  113. package/src/phaser/core/cache.test.ts +33 -33
  114. package/src/phaser/core/cache.ts +3 -3
  115. package/src/phaser/core/callback.ts +1 -0
  116. package/src/phaser/core/callback_context.test.ts +8 -8
  117. package/src/phaser/core/dom.ts +15 -5
  118. package/src/phaser/core/factory.ts +9 -2
  119. package/src/phaser/core/frame_data.test.ts +23 -23
  120. package/src/phaser/core/input.ts +9 -8
  121. package/src/phaser/core/input_handler.test.ts +18 -18
  122. package/src/phaser/core/input_handler.ts +1 -1
  123. package/src/phaser/core/input_mouse.ts +9 -8
  124. package/src/phaser/core/input_pointer.test.ts +26 -26
  125. package/src/phaser/core/input_pointer.ts +3 -3
  126. package/src/phaser/core/input_touch.ts +8 -8
  127. package/src/phaser/core/loader.test.ts +26 -26
  128. package/src/phaser/core/loader.ts +25 -25
  129. package/src/phaser/core/loader_parser.test.ts +16 -16
  130. package/src/phaser/core/loader_parser.ts +16 -6
  131. package/src/phaser/core/raf.ts +1 -1
  132. package/src/phaser/core/registry.test.ts +6 -6
  133. package/src/phaser/core/scale_manager.ts +2 -2
  134. package/src/phaser/core/scene_manager.test.ts +30 -30
  135. package/src/phaser/core/scene_manager.ts +1 -1
  136. package/src/phaser/core/signal.test.ts +8 -8
  137. package/src/phaser/core/signal.ts +1 -1
  138. package/src/phaser/core/signal_dispatch.test.ts +30 -30
  139. package/src/phaser/core/sound.ts +20 -8
  140. package/src/phaser/core/sound_manager.ts +6 -6
  141. package/src/phaser/core/stage.ts +19 -9
  142. package/src/phaser/core/time.ts +1 -1
  143. package/src/phaser/core/timer.test.ts +47 -47
  144. package/src/phaser/core/timer.ts +1 -1
  145. package/src/phaser/core/tween.ts +28 -25
  146. package/src/phaser/core/tween_data.test.ts +119 -0
  147. package/src/phaser/core/tween_data.ts +54 -39
  148. package/src/phaser/core/tween_easing.test.ts +5 -5
  149. package/src/phaser/core/tween_manager.ts +2 -2
  150. package/src/phaser/display/bitmap_text.test.ts +30 -30
  151. package/src/phaser/display/button.ts +8 -6
  152. package/src/phaser/display/canvas/buffer.ts +2 -2
  153. package/src/phaser/display/canvas/masker.ts +1 -1
  154. package/src/phaser/display/canvas/pool.test.ts +20 -20
  155. package/src/phaser/display/canvas/pool.ts +3 -3
  156. package/src/phaser/display/canvas/renderer.ts +12 -11
  157. package/src/phaser/display/canvas/util.test.ts +25 -25
  158. package/src/phaser/display/display_object.ts +3 -1
  159. package/src/phaser/display/graphics.test.ts +70 -20
  160. package/src/phaser/display/graphics.ts +38 -32
  161. package/src/phaser/display/group.ts +4 -4
  162. package/src/phaser/display/image.ts +28 -25
  163. package/src/phaser/display/sprite_util.ts +3 -2
  164. package/src/phaser/display/text.test.ts +28 -25
  165. package/src/phaser/display/text.ts +21 -18
  166. package/src/phaser/display/webgl/abstract_filter.ts +20 -10
  167. package/src/phaser/display/webgl/blend_manager.ts +4 -5
  168. package/src/phaser/display/webgl/earcut.test.ts +20 -20
  169. package/src/phaser/display/webgl/fast_sprite_batch.ts +21 -16
  170. package/src/phaser/display/webgl/filter_manager.ts +7 -4
  171. package/src/phaser/display/webgl/filter_texture.ts +5 -5
  172. package/src/phaser/display/webgl/graphics.ts +2 -2
  173. package/src/phaser/display/webgl/mask_manager.ts +9 -14
  174. package/src/phaser/display/webgl/render_texture.ts +15 -14
  175. package/src/phaser/display/webgl/renderer.ts +7 -6
  176. package/src/phaser/display/webgl/shader/normal.ts +41 -31
  177. package/src/phaser/display/webgl/shader/shader.test.ts +24 -24
  178. package/src/phaser/display/webgl/shader_manager.test.ts +18 -18
  179. package/src/phaser/display/webgl/sprite_batch.ts +8 -8
  180. package/src/phaser/display/webgl/stencil_manager.ts +4 -4
  181. package/src/phaser/display/webgl/texture_util.ts +2 -2
  182. package/src/phaser/display/webgl/util.ts +1 -1
  183. package/src/phaser/geom/circle.test.ts +38 -38
  184. package/src/phaser/geom/circle.ts +7 -7
  185. package/src/phaser/geom/ellipse.test.ts +12 -12
  186. package/src/phaser/geom/line.test.ts +15 -15
  187. package/src/phaser/geom/line.ts +5 -2
  188. package/src/phaser/geom/matrix.test.ts +31 -31
  189. package/src/phaser/geom/point.test.ts +31 -31
  190. package/src/phaser/geom/polygon.test.ts +27 -27
  191. package/src/phaser/geom/rectangle.test.ts +87 -87
  192. package/src/phaser/geom/rectangle.ts +11 -11
  193. package/src/phaser/geom/rounded_rectangle.test.ts +9 -9
  194. package/src/phaser/geom/util/circle.test.ts +5 -5
  195. package/src/phaser/geom/util/circle.ts +2 -1
  196. package/src/phaser/geom/util/ellipse.test.ts +2 -2
  197. package/src/phaser/geom/util/line.test.ts +2 -2
  198. package/src/phaser/geom/util/matrix.test.ts +4 -4
  199. package/src/phaser/geom/util/point.test.ts +2 -2
  200. package/src/phaser/geom/util/point.ts +1 -1
  201. package/src/phaser/geom/util/polygon.test.ts +2 -2
  202. package/src/phaser/geom/util/rectangle.test.ts +2 -2
  203. package/src/phaser/geom/util/rectangle.ts +1 -1
  204. package/src/phaser/geom/util/rounded_rectangle.test.ts +2 -2
  205. package/src/phaser/util/math.test.ts +41 -41
  206. 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!: any;
24
+ public currentBlendMode!: number;
20
25
  public renderSession!: RenderSession;
21
- public shader!: any;
22
- public matrix!: any;
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: any, renderSession: RenderSession): void {
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: any): void {
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.texture._uvs) {
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 (let i = 0, j = children.length; i < j; i += 1) {
111
- this.renderSprite(children[i]);
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.projectionVector, projection.x, projection.y);
276
+ gl.uniform2f(this.shader!.projectionVector, projection.x, projection.y);
272
277
  // set the matrix
273
- gl.uniformMatrix3fv(this.shader.uMatrix, false, this.matrix);
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.aVertexPosition, 2, gl.FLOAT, false, stride, 0);
277
- gl.vertexAttribPointer(this.shader.aPositionCoord, 2, gl.FLOAT, false, stride, 2 * 4);
278
- gl.vertexAttribPointer(this.shader.aScale, 2, gl.FLOAT, false, stride, 4 * 4);
279
- gl.vertexAttribPointer(this.shader.aRotation, 1, gl.FLOAT, false, stride, 6 * 4);
280
- gl.vertexAttribPointer(this.shader.aTextureCoord, 2, gl.FLOAT, false, stride, 7 * 4);
281
- gl.vertexAttribPointer(this.shader.colorAttribute, 1, gl.FLOAT, false, stride, 9 * 4);
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!: any[];
4
- public filterStack!: any;
5
- public offsetX!: any;
6
- public offsetY!: any;
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!: any;
7
- public frameBuffer!: any;
8
- public texture!: any;
9
- public renderBuffer!: any;
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: any, renderSession: RenderSession): void => {
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
- if (
15
- maskData._webGL[gl.id] === undefined ||
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, maskData._webGL[gl.id].data[0], renderSession);
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: any, renderSession: RenderSession): void => {
27
+ export const popMask = (maskData: Graphics | null, renderSession: RenderSession): void => {
30
28
  const { gl } = renderSession;
31
- if (
32
- maskData._webGL[gl.id] === undefined ||
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, maskData._webGL[gl.id].data[0], renderSession);
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: any;
17
- declare public crop: any;
18
- public renderer!: any;
19
- public textureBuffer!: any;
20
- public render!: any;
21
- public projection!: any;
22
- declare public valid: any;
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 (this.renderer.type === RENDER_WEBGL) {
56
- const { gl } = this.renderer;
54
+ if (renderer.type === RENDER_WEBGL) {
55
+ const { gl } = renderer as WebGLRenderer;
57
56
  this.baseTexture._dirty[gl.id] = false;
58
- this.textureBuffer = new FilterTexture(gl, this.width, this.height, this.baseTexture.scaleMode);
59
- this.baseTexture._glTextures[gl.id] = this.textureBuffer.texture;
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
- this.textureBuffer = new CanvasBuffer(this.width * this.resolution, this.height * this.resolution);
65
- this.baseTexture.source = this.textureBuffer.canvas;
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!: any;
56
- public stencilManager!: any;
57
- public blendModeManager!: any;
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: any, projection: Point, buffer?: any, matrix?: any): void {
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(this.renderSession, buffer);
221
+ this.filterManager.begin();
221
222
  // render the scene!
222
- displayObject.renderWebGL(this.renderSession, matrix);
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): any => (gl as unknown as Record<string, unknown>)[name];
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: any;
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?: Record<string, any>;
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: any): void {
178
- if (!uniform.value || !uniform.value.baseTexture || !uniform.value.baseTexture.hasLoaded) {
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, uniform.value.baseTexture._glTextures[gl.id]);
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, uniform.value.baseTexture.source);
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, uniform.value.x, uniform.value.y);
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
- if (uniform.value.baseTexture._dirty[gl.id]) {
265
- globalThis.PhaserRegistry.INSTANCES[gl.id]?.updateTexture(uniform.value.baseTexture);
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, uniform.value.baseTexture._glTextures[gl.id]);
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(uniform);
284
+ this.initSampler2D(sampler);
275
285
  }
276
286
  }
277
287
  }