@vpmedia/phaser 1.111.0 → 1.113.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 (296) hide show
  1. package/dist/index.js +1300 -1334
  2. package/dist/index.js.map +1 -1
  3. package/dist/phaser/core/animation.d.ts +14 -10
  4. package/dist/phaser/core/animation.d.ts.map +1 -1
  5. package/dist/phaser/core/animation_manager.d.ts +10 -8
  6. package/dist/phaser/core/animation_manager.d.ts.map +1 -1
  7. package/dist/phaser/core/animation_parser.d.ts +5 -4
  8. package/dist/phaser/core/animation_parser.d.ts.map +1 -1
  9. package/dist/phaser/core/array_set.d.ts.map +1 -1
  10. package/dist/phaser/core/cache.d.ts +4 -3
  11. package/dist/phaser/core/cache.d.ts.map +1 -1
  12. package/dist/phaser/core/const.d.ts.map +1 -1
  13. package/dist/phaser/core/device.d.ts.map +1 -1
  14. package/dist/phaser/core/device_util.d.ts.map +1 -1
  15. package/dist/phaser/core/dom.d.ts +3 -2
  16. package/dist/phaser/core/dom.d.ts.map +1 -1
  17. package/dist/phaser/core/event_manager.d.ts.map +1 -1
  18. package/dist/phaser/core/factory.d.ts +1 -1
  19. package/dist/phaser/core/factory.d.ts.map +1 -1
  20. package/dist/phaser/core/frame.d.ts.map +1 -1
  21. package/dist/phaser/core/frame_data.d.ts.map +1 -1
  22. package/dist/phaser/core/game.d.ts +1 -1
  23. package/dist/phaser/core/game.d.ts.map +1 -1
  24. package/dist/phaser/core/input.d.ts +8 -6
  25. package/dist/phaser/core/input.d.ts.map +1 -1
  26. package/dist/phaser/core/input_handler.d.ts +40 -30
  27. package/dist/phaser/core/input_handler.d.ts.map +1 -1
  28. package/dist/phaser/core/input_mouse.d.ts +3 -2
  29. package/dist/phaser/core/input_mouse.d.ts.map +1 -1
  30. package/dist/phaser/core/input_mspointer.d.ts +3 -2
  31. package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
  32. package/dist/phaser/core/input_pointer.d.ts +6 -4
  33. package/dist/phaser/core/input_pointer.d.ts.map +1 -1
  34. package/dist/phaser/core/input_touch.d.ts +3 -2
  35. package/dist/phaser/core/input_touch.d.ts.map +1 -1
  36. package/dist/phaser/core/loader.d.ts +4 -3
  37. package/dist/phaser/core/loader.d.ts.map +1 -1
  38. package/dist/phaser/core/loader_parser.d.ts +9 -8
  39. package/dist/phaser/core/loader_parser.d.ts.map +1 -1
  40. package/dist/phaser/core/raf.d.ts +3 -2
  41. package/dist/phaser/core/raf.d.ts.map +1 -1
  42. package/dist/phaser/core/registry.d.ts +7 -0
  43. package/dist/phaser/core/registry.d.ts.map +1 -0
  44. package/dist/phaser/core/scale_manager.d.ts +1 -1
  45. package/dist/phaser/core/scale_manager.d.ts.map +1 -1
  46. package/dist/phaser/core/scene.d.ts +0 -1
  47. package/dist/phaser/core/scene.d.ts.map +1 -1
  48. package/dist/phaser/core/scene_manager.d.ts +1 -1
  49. package/dist/phaser/core/scene_manager.d.ts.map +1 -1
  50. package/dist/phaser/core/signal.d.ts +0 -1
  51. package/dist/phaser/core/signal.d.ts.map +1 -1
  52. package/dist/phaser/core/signal_binding.d.ts +4 -3
  53. package/dist/phaser/core/signal_binding.d.ts.map +1 -1
  54. package/dist/phaser/core/sound.d.ts +6 -4
  55. package/dist/phaser/core/sound.d.ts.map +1 -1
  56. package/dist/phaser/core/sound_manager.d.ts +3 -2
  57. package/dist/phaser/core/sound_manager.d.ts.map +1 -1
  58. package/dist/phaser/core/sound_sprite.d.ts +5 -4
  59. package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
  60. package/dist/phaser/core/stage.d.ts +3 -2
  61. package/dist/phaser/core/stage.d.ts.map +1 -1
  62. package/dist/phaser/core/time.d.ts +1 -1
  63. package/dist/phaser/core/time.d.ts.map +1 -1
  64. package/dist/phaser/core/timer.d.ts +1 -1
  65. package/dist/phaser/core/timer.d.ts.map +1 -1
  66. package/dist/phaser/core/timer_event.d.ts.map +1 -1
  67. package/dist/phaser/core/tween.d.ts +10 -7
  68. package/dist/phaser/core/tween.d.ts.map +1 -1
  69. package/dist/phaser/core/tween_data.d.ts +3 -2
  70. package/dist/phaser/core/tween_data.d.ts.map +1 -1
  71. package/dist/phaser/core/tween_easing.d.ts.map +1 -1
  72. package/dist/phaser/core/tween_manager.d.ts +3 -2
  73. package/dist/phaser/core/tween_manager.d.ts.map +1 -1
  74. package/dist/phaser/core/world.d.ts +3 -2
  75. package/dist/phaser/core/world.d.ts.map +1 -1
  76. package/dist/phaser/display/bitmap_text.d.ts +3 -2
  77. package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
  78. package/dist/phaser/display/button.d.ts +3 -2
  79. package/dist/phaser/display/button.d.ts.map +1 -1
  80. package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
  81. package/dist/phaser/display/canvas/graphics.d.ts +7 -6
  82. package/dist/phaser/display/canvas/graphics.d.ts.map +1 -1
  83. package/dist/phaser/display/canvas/pool.d.ts +2 -2
  84. package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
  85. package/dist/phaser/display/canvas/renderer.d.ts +10 -8
  86. package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
  87. package/dist/phaser/display/canvas/tinter.d.ts +3 -2
  88. package/dist/phaser/display/canvas/tinter.d.ts.map +1 -1
  89. package/dist/phaser/display/canvas/util.d.ts +2 -2
  90. package/dist/phaser/display/canvas/util.d.ts.map +1 -1
  91. package/dist/phaser/display/display_object.d.ts +14 -12
  92. package/dist/phaser/display/display_object.d.ts.map +1 -1
  93. package/dist/phaser/display/graphics.d.ts +8 -5
  94. package/dist/phaser/display/graphics.d.ts.map +1 -1
  95. package/dist/phaser/display/graphics_data.d.ts.map +1 -1
  96. package/dist/phaser/display/graphics_data_util.d.ts.map +1 -1
  97. package/dist/phaser/display/group.d.ts +4 -3
  98. package/dist/phaser/display/group.d.ts.map +1 -1
  99. package/dist/phaser/display/image.d.ts +13 -10
  100. package/dist/phaser/display/image.d.ts.map +1 -1
  101. package/dist/phaser/display/sprite_batch.d.ts +3 -2
  102. package/dist/phaser/display/sprite_batch.d.ts.map +1 -1
  103. package/dist/phaser/display/sprite_util.d.ts +18 -15
  104. package/dist/phaser/display/sprite_util.d.ts.map +1 -1
  105. package/dist/phaser/display/text.d.ts +11 -9
  106. package/dist/phaser/display/text.d.ts.map +1 -1
  107. package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
  108. package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
  109. package/dist/phaser/display/webgl/blend_manager.d.ts +0 -1
  110. package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
  111. package/dist/phaser/display/webgl/earcut.d.ts +1 -1
  112. package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
  113. package/dist/phaser/display/webgl/earcut_node.d.ts.map +1 -1
  114. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +4 -3
  115. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
  116. package/dist/phaser/display/webgl/filter_manager.d.ts +2 -1
  117. package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
  118. package/dist/phaser/display/webgl/filter_texture.d.ts +2 -1
  119. package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
  120. package/dist/phaser/display/webgl/graphics.d.ts +7 -6
  121. package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
  122. package/dist/phaser/display/webgl/graphics_data.d.ts +2 -1
  123. package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
  124. package/dist/phaser/display/webgl/render_texture.d.ts +4 -2
  125. package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
  126. package/dist/phaser/display/webgl/renderer.d.ts +16 -11
  127. package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
  128. package/dist/phaser/display/webgl/shader/complex.d.ts +16 -6
  129. package/dist/phaser/display/webgl/shader/complex.d.ts.map +1 -1
  130. package/dist/phaser/display/webgl/shader/fast.d.ts +19 -7
  131. package/dist/phaser/display/webgl/shader/fast.d.ts.map +1 -1
  132. package/dist/phaser/display/webgl/shader/normal.d.ts +33 -12
  133. package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
  134. package/dist/phaser/display/webgl/shader/primitive.d.ts +15 -6
  135. package/dist/phaser/display/webgl/shader/primitive.d.ts.map +1 -1
  136. package/dist/phaser/display/webgl/shader/strip.d.ts +15 -6
  137. package/dist/phaser/display/webgl/shader/strip.d.ts.map +1 -1
  138. package/dist/phaser/display/webgl/shader_manager.d.ts +16 -11
  139. package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
  140. package/dist/phaser/display/webgl/sprite_batch.d.ts +29 -20
  141. package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
  142. package/dist/phaser/display/webgl/stencil_manager.d.ts +12 -10
  143. package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
  144. package/dist/phaser/display/webgl/texture.d.ts +3 -2
  145. package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
  146. package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
  147. package/dist/phaser/display/webgl/util.d.ts.map +1 -1
  148. package/dist/phaser/geom/circle.d.ts +4 -1
  149. package/dist/phaser/geom/circle.d.ts.map +1 -1
  150. package/dist/phaser/geom/ellipse.d.ts.map +1 -1
  151. package/dist/phaser/geom/line.d.ts +1 -1
  152. package/dist/phaser/geom/line.d.ts.map +1 -1
  153. package/dist/phaser/geom/matrix.d.ts.map +1 -1
  154. package/dist/phaser/geom/point.d.ts.map +1 -1
  155. package/dist/phaser/geom/polygon.d.ts.map +1 -1
  156. package/dist/phaser/geom/rectangle.d.ts.map +1 -1
  157. package/dist/phaser/geom/rounded_rectangle.d.ts.map +1 -1
  158. package/dist/phaser/geom/util/circle.d.ts.map +1 -1
  159. package/dist/phaser/geom/util/ellipse.d.ts +3 -2
  160. package/dist/phaser/geom/util/ellipse.d.ts.map +1 -1
  161. package/dist/phaser/geom/util/line.d.ts.map +1 -1
  162. package/dist/phaser/geom/util/matrix.d.ts +2 -2
  163. package/dist/phaser/geom/util/matrix.d.ts.map +1 -1
  164. package/dist/phaser/geom/util/point.d.ts.map +1 -1
  165. package/dist/phaser/geom/util/rectangle.d.ts +1 -1
  166. package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
  167. package/dist/phaser/util/math.d.ts.map +1 -1
  168. package/package.json +5 -4
  169. package/src/phaser/core/animation.ts +64 -60
  170. package/src/phaser/core/animation_manager.ts +54 -55
  171. package/src/phaser/core/animation_parser.ts +9 -9
  172. package/src/phaser/core/array_set.ts +16 -17
  173. package/src/phaser/core/cache.ts +92 -93
  174. package/src/phaser/core/const.ts +1 -1
  175. package/src/phaser/core/device.ts +24 -29
  176. package/src/phaser/core/device_util.ts +28 -32
  177. package/src/phaser/core/dom.ts +54 -65
  178. package/src/phaser/core/event_manager.ts +64 -94
  179. package/src/phaser/core/factory.ts +14 -14
  180. package/src/phaser/core/frame.ts +28 -28
  181. package/src/phaser/core/frame_data.test.ts +100 -0
  182. package/src/phaser/core/frame_data.ts +24 -24
  183. package/src/phaser/core/frame_util.ts +2 -2
  184. package/src/phaser/core/game.ts +50 -51
  185. package/src/phaser/core/input.ts +104 -110
  186. package/src/phaser/core/input_handler.test.ts +113 -0
  187. package/src/phaser/core/input_handler.ts +199 -218
  188. package/src/phaser/core/input_mouse.ts +71 -54
  189. package/src/phaser/core/input_mspointer.ts +52 -39
  190. package/src/phaser/core/input_pointer.ts +81 -80
  191. package/src/phaser/core/input_touch.ts +49 -36
  192. package/src/phaser/core/loader.ts +175 -154
  193. package/src/phaser/core/loader_parser.ts +39 -57
  194. package/src/phaser/core/raf.ts +8 -7
  195. package/src/phaser/core/registry.test.ts +31 -0
  196. package/src/phaser/core/registry.ts +9 -0
  197. package/src/phaser/core/scale_manager.ts +156 -152
  198. package/src/phaser/core/scene.ts +9 -13
  199. package/src/phaser/core/scene_manager.ts +47 -47
  200. package/src/phaser/core/signal.test.ts +4 -4
  201. package/src/phaser/core/signal.ts +41 -52
  202. package/src/phaser/core/signal_binding.ts +26 -25
  203. package/src/phaser/core/signal_dispatch.test.ts +180 -0
  204. package/src/phaser/core/sound.ts +75 -83
  205. package/src/phaser/core/sound_manager.ts +58 -56
  206. package/src/phaser/core/sound_sprite.ts +17 -16
  207. package/src/phaser/core/stage.ts +25 -24
  208. package/src/phaser/core/time.ts +52 -52
  209. package/src/phaser/core/timer.test.ts +187 -0
  210. package/src/phaser/core/timer.ts +82 -69
  211. package/src/phaser/core/timer_event.ts +10 -10
  212. package/src/phaser/core/tween.ts +90 -93
  213. package/src/phaser/core/tween_data.ts +45 -51
  214. package/src/phaser/core/tween_easing.test.ts +106 -0
  215. package/src/phaser/core/tween_easing.ts +151 -123
  216. package/src/phaser/core/tween_manager.ts +19 -18
  217. package/src/phaser/core/world.ts +4 -3
  218. package/src/phaser/display/bitmap_text.ts +56 -64
  219. package/src/phaser/display/button.ts +33 -32
  220. package/src/phaser/display/canvas/buffer.ts +8 -8
  221. package/src/phaser/display/canvas/graphics.ts +36 -37
  222. package/src/phaser/display/canvas/masker.ts +2 -2
  223. package/src/phaser/display/canvas/pool.test.ts +106 -0
  224. package/src/phaser/display/canvas/pool.ts +25 -27
  225. package/src/phaser/display/canvas/renderer.ts +32 -31
  226. package/src/phaser/display/canvas/tinter.ts +27 -27
  227. package/src/phaser/display/canvas/util.ts +7 -10
  228. package/src/phaser/display/display_object.ts +114 -118
  229. package/src/phaser/display/graphics.ts +121 -119
  230. package/src/phaser/display/graphics_data.ts +12 -12
  231. package/src/phaser/display/graphics_data_util.ts +2 -3
  232. package/src/phaser/display/group.ts +50 -57
  233. package/src/phaser/display/image.ts +55 -52
  234. package/src/phaser/display/sprite_batch.ts +3 -2
  235. package/src/phaser/display/sprite_util.ts +48 -54
  236. package/src/phaser/display/text.ts +199 -204
  237. package/src/phaser/display/webgl/abstract_filter.ts +9 -9
  238. package/src/phaser/display/webgl/base_texture.ts +21 -24
  239. package/src/phaser/display/webgl/blend_manager.ts +6 -10
  240. package/src/phaser/display/webgl/earcut.ts +73 -37
  241. package/src/phaser/display/webgl/earcut_node.ts +10 -10
  242. package/src/phaser/display/webgl/fast_sprite_batch.ts +34 -34
  243. package/src/phaser/display/webgl/filter_manager.ts +13 -12
  244. package/src/phaser/display/webgl/filter_texture.ts +14 -13
  245. package/src/phaser/display/webgl/graphics.ts +51 -57
  246. package/src/phaser/display/webgl/graphics_data.ts +15 -14
  247. package/src/phaser/display/webgl/mask_manager.ts +2 -2
  248. package/src/phaser/display/webgl/render_texture.ts +26 -25
  249. package/src/phaser/display/webgl/renderer.ts +57 -62
  250. package/src/phaser/display/webgl/shader/complex.ts +28 -12
  251. package/src/phaser/display/webgl/shader/fast.ts +30 -12
  252. package/src/phaser/display/webgl/shader/normal.ts +70 -57
  253. package/src/phaser/display/webgl/shader/primitive.ts +26 -11
  254. package/src/phaser/display/webgl/shader/shader.test.ts +148 -0
  255. package/src/phaser/display/webgl/shader/strip.ts +27 -12
  256. package/src/phaser/display/webgl/shader_manager.test.ts +124 -0
  257. package/src/phaser/display/webgl/shader_manager.ts +26 -34
  258. package/src/phaser/display/webgl/sprite_batch.ts +67 -61
  259. package/src/phaser/display/webgl/stencil_manager.ts +23 -34
  260. package/src/phaser/display/webgl/texture.ts +43 -50
  261. package/src/phaser/display/webgl/texture_util.ts +2 -3
  262. package/src/phaser/display/webgl/util.ts +26 -25
  263. package/src/phaser/geom/circle.test.ts +2 -3
  264. package/src/phaser/geom/circle.ts +36 -36
  265. package/src/phaser/geom/ellipse.test.ts +73 -71
  266. package/src/phaser/geom/ellipse.ts +14 -14
  267. package/src/phaser/geom/line.test.ts +5 -5
  268. package/src/phaser/geom/line.ts +35 -35
  269. package/src/phaser/geom/matrix.test.ts +1 -1
  270. package/src/phaser/geom/matrix.ts +27 -27
  271. package/src/phaser/geom/point.test.ts +1 -2
  272. package/src/phaser/geom/point.ts +35 -35
  273. package/src/phaser/geom/polygon.test.ts +82 -0
  274. package/src/phaser/geom/polygon.ts +16 -16
  275. package/src/phaser/geom/rectangle.test.ts +14 -14
  276. package/src/phaser/geom/rectangle.ts +83 -75
  277. package/src/phaser/geom/rounded_rectangle.test.ts +1 -7
  278. package/src/phaser/geom/rounded_rectangle.ts +9 -9
  279. package/src/phaser/geom/util/circle.test.ts +25 -23
  280. package/src/phaser/geom/util/circle.ts +9 -18
  281. package/src/phaser/geom/util/ellipse.test.ts +7 -5
  282. package/src/phaser/geom/util/ellipse.ts +3 -2
  283. package/src/phaser/geom/util/line.test.ts +10 -8
  284. package/src/phaser/geom/util/line.ts +6 -16
  285. package/src/phaser/geom/util/matrix.test.ts +20 -18
  286. package/src/phaser/geom/util/matrix.ts +8 -15
  287. package/src/phaser/geom/util/point.test.ts +8 -6
  288. package/src/phaser/geom/util/point.ts +24 -28
  289. package/src/phaser/geom/util/polygon.test.ts +12 -10
  290. package/src/phaser/geom/util/polygon.ts +2 -2
  291. package/src/phaser/geom/util/rectangle.test.ts +10 -8
  292. package/src/phaser/geom/util/rectangle.ts +18 -37
  293. package/src/phaser/geom/util/rounded_rectangle.test.ts +11 -9
  294. package/src/phaser/geom/util/rounded_rectangle.ts +1 -1
  295. package/src/phaser/util/math.test.ts +11 -11
  296. package/src/phaser/util/math.ts +29 -46
@@ -1,3 +1,6 @@
1
+ import type { Game } from '../../core/game.js';
2
+ import type { Stage } from '../../core/stage.js';
3
+ import type { BaseTexture } from './base_texture.js';
1
4
  import {
2
5
  BLEND_ADD,
3
6
  BLEND_COLOR,
@@ -29,32 +32,34 @@ import * as WebGLMaskManager from './mask_manager.js';
29
32
  import { WebGLShaderManager } from './shader_manager.js';
30
33
  import { WebGLSpriteBatch } from './sprite_batch.js';
31
34
  import { WebGLStencilManager } from './stencil_manager.js';
35
+ import type { IdentifiedWebGLRenderingContext } from './util.js';
32
36
  import { getWebGLContextErrorCode, getWebGLContextErrorName } from './util.js';
33
37
 
34
38
  export class WebGLRenderer {
35
- [key: string]: any;
36
- type!: any;
37
- resolution!: any;
38
- autoResize!: any;
39
- contextLost!: any;
40
- clearBeforeRender!: any;
41
- width!: any;
42
- height!: any;
43
- view!: any;
44
- _contextOptions!: any;
45
- projection!: any;
46
- offset!: any;
47
- shaderManager!: any;
48
- spriteBatch!: any;
49
- filterManager!: any;
50
- stencilManager!: any;
51
- blendModeManager!: any;
52
- renderSession!: any;
39
+ public gl!: IdentifiedWebGLRenderingContext;
40
+ public glContextId!: number;
41
+ public type!: any;
42
+ public resolution!: any;
43
+ public autoResize!: any;
44
+ public contextLost!: any;
45
+ public clearBeforeRender!: any;
46
+ public width!: any;
47
+ public height!: any;
48
+ public view!: any;
49
+ public _contextOptions!: any;
50
+ public projection!: any;
51
+ public offset!: any;
52
+ public shaderManager!: any;
53
+ public spriteBatch!: any;
54
+ public filterManager!: any;
55
+ public stencilManager!: any;
56
+ public blendModeManager!: any;
57
+ public renderSession!: any;
53
58
  /**
54
59
  * Creates a new WebGLRenderer instance.
55
- * @param {import('../../core/game.js').Game} game - The game instance.
60
+ * @param {Game} game - The game instance.
56
61
  */
57
- constructor(game: import('../../core/game.js').Game) {
62
+ public constructor(game: Game) {
58
63
  /** @type {number} */
59
64
  this.type = RENDER_WEBGL;
60
65
  this.resolution = game.config.resolution;
@@ -98,8 +103,8 @@ export class WebGLRenderer {
98
103
  /**
99
104
  * Destroys this renderer and cleans up resources.
100
105
  */
101
- destroy() {
102
- window.PhaserRegistry.GL_CONTEXTS[this.glContextId] = null;
106
+ public destroy() {
107
+ globalThis.PhaserRegistry.GL_CONTEXTS[this.glContextId] = null;
103
108
  this.projection = null;
104
109
  this.offset = null;
105
110
  this.shaderManager.destroy();
@@ -116,43 +121,35 @@ export class WebGLRenderer {
116
121
  loseContextExt.loseContext();
117
122
  }
118
123
  }
119
- this.gl = null;
120
124
  this.renderSession = null;
121
125
  remove(this);
122
- window.PhaserRegistry.INSTANCES[this.glContextId] = null;
123
- window.PhaserRegistry.GL_CONTEXT_ID -= 1;
126
+ globalThis.PhaserRegistry.INSTANCES[this.glContextId] = null;
127
+ globalThis.PhaserRegistry.GL_CONTEXT_ID -= 1;
124
128
  }
125
129
 
126
130
  /**
127
131
  * Initializes the WebGL registry.
128
132
  */
129
- initRegistry() {
130
- if (!window.PhaserRegistry.GL_CONTEXT_ID) {
131
- window.PhaserRegistry.GL_CONTEXT_ID = 0;
132
- }
133
- if (!window.PhaserRegistry.GL_CONTEXTS) {
134
- window.PhaserRegistry.GL_CONTEXTS = [];
135
- }
136
- if (!window.PhaserRegistry.INSTANCES) {
137
- window.PhaserRegistry.INSTANCES = [];
138
- }
133
+ public initRegistry() {
134
+ globalThis.PhaserRegistry.GL_CONTEXT_ID ??= 0;
135
+ globalThis.PhaserRegistry.GL_CONTEXTS ??= [];
136
+ globalThis.PhaserRegistry.INSTANCES ??= [];
139
137
  }
140
138
 
141
139
  /**
142
140
  * Initializes the WebGL context for rendering.
143
- * @param {import('../../core/game.js').Game} game - The game instance.
141
+ * @param {Game} game - The game instance.
144
142
  * @throws {Error}
145
143
  */
146
- initContext(game: import('../../core/game.js').Game) {
144
+ public initContext(game: Game) {
147
145
  game.logger.info('initContext');
148
146
  // TODO: view.addEventListener('webglcontextcreationerror', this.onWebGLContextCreationError, false);
149
147
  /** @type {WebGLRenderingContext & { id: number }} */
150
- // @ts-ignore
151
- const gl = this.view.getContext('webgl', this._contextOptions);
152
- this.gl = gl;
148
+ const gl = this.view.getContext('webgl', this._contextOptions) as IdentifiedWebGLRenderingContext | null;
153
149
  if (!gl) {
154
150
  throw new Error(ENGINE_ERROR_CREATING_WEBGL_CONTEXT);
155
151
  }
152
+ this.gl = gl;
156
153
  const errorCode = getWebGLContextErrorCode(gl);
157
154
  if (errorCode) {
158
155
  const errorName = getWebGLContextErrorName(errorCode);
@@ -163,11 +160,11 @@ export class WebGLRenderer {
163
160
  }
164
161
  // set current context
165
162
  this.initRegistry();
166
- this.glContextId = window.PhaserRegistry.GL_CONTEXT_ID;
167
- gl.id = window.PhaserRegistry.GL_CONTEXT_ID;
168
- window.PhaserRegistry.GL_CONTEXTS[this.glContextId] = gl;
169
- window.PhaserRegistry.INSTANCES[this.glContextId] = this;
170
- window.PhaserRegistry.GL_CONTEXT_ID += 1;
163
+ this.glContextId = globalThis.PhaserRegistry.GL_CONTEXT_ID;
164
+ gl.id = globalThis.PhaserRegistry.GL_CONTEXT_ID;
165
+ globalThis.PhaserRegistry.GL_CONTEXTS[this.glContextId] = gl;
166
+ globalThis.PhaserRegistry.INSTANCES[this.glContextId] = this;
167
+ globalThis.PhaserRegistry.GL_CONTEXT_ID += 1;
171
168
  // set default settings
172
169
  gl.disable(gl.DEPTH_TEST);
173
170
  gl.disable(gl.CULL_FACE);
@@ -185,13 +182,13 @@ export class WebGLRenderer {
185
182
 
186
183
  /**
187
184
  * Renders the stage to WebGL.
188
- * @param {import('../../core/stage.js').Stage} stage - The root stage to render.
185
+ * @param {Stage} stage - The root stage to render.
189
186
  */
190
- render(stage: import('../../core/stage.js').Stage) {
187
+ public render(stage: Stage) {
191
188
  if (this.contextLost) {
192
189
  return;
193
190
  }
194
- const gl = this.gl;
191
+ const { gl } = this;
195
192
  // -- Does this need to be set every frame? -- //
196
193
  // gl.viewport(0, 0, this.width, this.height);
197
194
  // make sure we are bound to the main frame buffer
@@ -207,12 +204,12 @@ export class WebGLRenderer {
207
204
 
208
205
  /**
209
206
  * Renders a display object to WebGL.
210
- * @param {import('../../display/display_object.js').DisplayObject} displayObject - The display object to render.
207
+ * @param {DisplayObject} displayObject - The display object to render.
211
208
  * @param {Point} projection - The projection matrix.
212
209
  * @param {object} buffer - The render buffer.
213
- * @param {import('../../geom/matrix.js').Matrix} matrix - The transformation matrix.
210
+ * @param {Matrix} matrix - The transformation matrix.
214
211
  */
215
- renderDisplayObject(displayObject: any, projection: Point, buffer?: any, matrix?: any) {
212
+ public renderDisplayObject(displayObject: any, projection: Point, buffer?: any, matrix?: any) {
216
213
  this.renderSession.blendModeManager.setBlendMode(BLEND_NORMAL);
217
214
  // reset the render session data..
218
215
  this.renderSession.drawCount = 0;
@@ -237,7 +234,7 @@ export class WebGLRenderer {
237
234
  * @param {number} width - The new width of the canvas.
238
235
  * @param {number} height - The new height of the canvas.
239
236
  */
240
- resize(width: number, height: number) {
237
+ public resize(width: number, height: number) {
241
238
  this.width = width * this.resolution;
242
239
  this.height = height * this.resolution;
243
240
  this.view.width = this.width;
@@ -253,17 +250,15 @@ export class WebGLRenderer {
253
250
 
254
251
  /**
255
252
  * Updates a texture in the WebGL context.
256
- * @param {import('./base_texture.js').BaseTexture} texture - The base texture to update.
253
+ * @param {BaseTexture} texture - The base texture to update.
257
254
  * @returns {boolean} Whether the update was successful.
258
255
  */
259
- updateTexture(texture: import('./base_texture.js').BaseTexture) {
256
+ public updateTexture(texture: BaseTexture) {
260
257
  if (!texture.hasLoaded) {
261
258
  return false;
262
259
  }
263
- const gl = this.gl;
264
- if (!texture._glTextures[gl.id]) {
265
- texture._glTextures[gl.id] = gl.createTexture();
266
- }
260
+ const { gl } = this;
261
+ texture._glTextures[gl.id] ??= gl.createTexture();
267
262
  gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]);
268
263
  gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultipliedAlpha);
269
264
  gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source);
@@ -297,11 +292,11 @@ export class WebGLRenderer {
297
292
  /**
298
293
  * Maps blend modes to WebGL rendering operations.
299
294
  */
300
- mapBlendModes() {
301
- if (window.PhaserRegistry.blendModesWebGL) {
295
+ public mapBlendModes() {
296
+ if (globalThis.PhaserRegistry.blendModesWebGL) {
302
297
  return;
303
298
  }
304
- const gl = this.gl;
299
+ const { gl } = this;
305
300
  const b = [];
306
301
  b[BLEND_NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
307
302
  b[BLEND_ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA];
@@ -320,6 +315,6 @@ export class WebGLRenderer {
320
315
  b[BLEND_SATURATION] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
321
316
  b[BLEND_COLOR] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
322
317
  b[BLEND_LUMINOSITY] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
323
- window.PhaserRegistry.blendModesWebGL = b;
318
+ globalThis.PhaserRegistry.blendModesWebGL = b;
324
319
  }
325
320
  }
@@ -4,17 +4,27 @@ import { compileProgram } from '../util.js';
4
4
  // the next one is used for rendering triangle strips
5
5
 
6
6
  export class ComplexPrimitiveShader {
7
- [key: string]: any;
8
- gl!: any;
9
- _UID!: any;
10
- program!: any;
11
- fragmentSrc!: any;
12
- vertexSrc!: any;
7
+ public gl: WebGLRenderingContext | null;
8
+ public _UID: string;
9
+ public program: WebGLProgram | null;
10
+ public fragmentSrc: string[];
11
+ public vertexSrc: string[];
12
+ public projectionVector!: WebGLUniformLocation | null;
13
+ public offsetVector!: WebGLUniformLocation | null;
14
+ public tintColor!: WebGLUniformLocation | null;
15
+ public color!: WebGLUniformLocation | null;
16
+ public flipY!: WebGLUniformLocation | null;
17
+ public translationMatrix!: WebGLUniformLocation | null;
18
+ public alpha!: WebGLUniformLocation | null;
19
+ public aVertexPosition!: number;
20
+ public colorAttribute: number | undefined;
21
+ public uniforms: unknown = null;
22
+ public attributes: (number | undefined)[] | null = null;
13
23
  /**
14
24
  * Creates a new ComplexShader instance.
15
25
  * @param {WebGLRenderingContext} gl - The WebGL rendering context.
16
26
  */
17
- constructor(gl: WebGLRenderingContext) {
27
+ public constructor(gl: WebGLRenderingContext) {
18
28
  this.gl = gl;
19
29
  this._UID = uuidv4();
20
30
  /** @type {WebGLProgram} */
@@ -52,9 +62,15 @@ export class ComplexPrimitiveShader {
52
62
  /**
53
63
  * Destroys this shader and cleans up resources.
54
64
  */
55
- init() {
56
- const gl = this.gl;
65
+ public init(): void {
66
+ const { gl } = this;
67
+ if (!gl) {
68
+ return;
69
+ }
57
70
  const program = compileProgram(gl, this.vertexSrc, this.fragmentSrc);
71
+ if (!program) {
72
+ return;
73
+ }
58
74
  gl.useProgram(program);
59
75
  // get and store the uniforms for the shader
60
76
  this.projectionVector = gl.getUniformLocation(program, 'projectionVector');
@@ -74,10 +90,10 @@ export class ComplexPrimitiveShader {
74
90
  /**
75
91
  * Binds this shader to the WebGL context.
76
92
  */
77
- destroy() {
78
- this.gl.deleteProgram(this.program);
93
+ public destroy(): void {
94
+ this.gl?.deleteProgram(this.program);
79
95
  this.uniforms = null;
80
96
  this.gl = null;
81
- this.attribute = null;
97
+ this.attributes = null;
82
98
  }
83
99
  }
@@ -4,18 +4,30 @@ import { compileProgram } from '../util.js';
4
4
  // this shader is used for the fast sprite rendering
5
5
 
6
6
  export class FastShader {
7
- [key: string]: any;
8
- gl!: any;
9
- _UID!: any;
10
- program!: any;
11
- textureCount!: any;
12
- fragmentSrc!: any;
13
- vertexSrc!: any;
7
+ public gl: WebGLRenderingContext | null;
8
+ public _UID: string;
9
+ public program: WebGLProgram | null;
10
+ public textureCount: number;
11
+ public fragmentSrc: string[];
12
+ public vertexSrc: string[];
13
+ public uSampler!: WebGLUniformLocation | null;
14
+ public projectionVector!: WebGLUniformLocation | null;
15
+ public offsetVector!: WebGLUniformLocation | null;
16
+ public dimensions!: WebGLUniformLocation | null;
17
+ public uMatrix!: WebGLUniformLocation | null;
18
+ public uniforms: unknown = null;
19
+ public aVertexPosition!: number;
20
+ public aPositionCoord!: number;
21
+ public aScale!: number;
22
+ public aRotation!: number;
23
+ public aTextureCoord!: number;
24
+ public colorAttribute!: number;
25
+ public attributes: number[] | null = null;
14
26
  /**
15
27
  * Creates a new FastShader instance.
16
28
  * @param {WebGLRenderingContext} gl - The WebGL rendering context.
17
29
  */
18
- constructor(gl: WebGLRenderingContext) {
30
+ public constructor(gl: WebGLRenderingContext) {
19
31
  this.gl = gl;
20
32
  this._UID = uuidv4();
21
33
  /** @type {WebGLProgram} */
@@ -65,9 +77,15 @@ export class FastShader {
65
77
  /**
66
78
  * Creates a new FastShader instance.
67
79
  */
68
- init() {
69
- const gl = this.gl;
80
+ public init(): void {
81
+ const { gl } = this;
82
+ if (!gl) {
83
+ return;
84
+ }
70
85
  const program = compileProgram(gl, this.vertexSrc, this.fragmentSrc);
86
+ if (!program) {
87
+ return;
88
+ }
71
89
  gl.useProgram(program);
72
90
  // get and store the uniforms for the shader
73
91
  this.uSampler = gl.getUniformLocation(program, 'uSampler');
@@ -105,8 +123,8 @@ export class FastShader {
105
123
  /**
106
124
  * Destroys this shader and cleans up resources.
107
125
  */
108
- destroy() {
109
- this.gl.deleteProgram(this.program);
126
+ public destroy(): void {
127
+ this.gl?.deleteProgram(this.program);
110
128
  this.uniforms = null;
111
129
  this.gl = null;
112
130
  this.attributes = null;
@@ -21,25 +21,45 @@ const defaultVertexSrc = [
21
21
  '}',
22
22
  ];
23
23
 
24
+ const glMember = (gl: WebGLRenderingContext, name: string): any => (gl as unknown as Record<string, unknown>)[name];
25
+
24
26
  // this shader is used for the default sprite rendering
25
27
 
28
+ export type ShaderUniform = {
29
+ type: string;
30
+ value: any;
31
+ uniformLocation?: WebGLUniformLocation | null;
32
+ glFunc?: (...args: any[]) => void;
33
+ glMatrix?: boolean;
34
+ glValueLength?: number;
35
+ transpose?: boolean;
36
+ textureData?: Record<string, any>;
37
+ _init?: boolean;
38
+ };
39
+
26
40
  export class NormalShader {
27
- [key: string]: any;
28
- gl!: any;
29
- _UID!: any;
30
- program!: any;
31
- fragmentSrc!: any;
32
- vertexSrc!: any;
33
- textureCount!: any;
34
- firstRun!: any;
35
- dirty!: any;
36
- uniforms!: any;
37
- attributes!: any;
41
+ public gl: WebGLRenderingContext & { id: number };
42
+ public _UID: string;
43
+ public program: WebGLProgram | null;
44
+ public fragmentSrc: string[];
45
+ public vertexSrc: string[] | null;
46
+ public textureCount: number;
47
+ public firstRun: boolean;
48
+ public dirty: boolean;
49
+ public uniforms: Record<string, ShaderUniform>;
50
+ public attributes: number[];
51
+ public uSampler!: WebGLUniformLocation | null;
52
+ public projectionVector!: WebGLUniformLocation | null;
53
+ public offsetVector!: WebGLUniformLocation | null;
54
+ public dimensions!: WebGLUniformLocation | null;
55
+ public aVertexPosition!: number;
56
+ public aTextureCoord!: number;
57
+ public colorAttribute!: number;
38
58
  /**
39
59
  * Creates a new NormalShader instance.
40
60
  * @param {WebGLRenderingContext & { id: number }} gl - The WebGL rendering context.
41
61
  */
42
- constructor(gl: WebGLRenderingContext) {
62
+ public constructor(gl: WebGLRenderingContext & { id: number }) {
43
63
  this.gl = gl;
44
64
  this._UID = uuidv4();
45
65
  /** @type {WebGLProgram} */
@@ -66,9 +86,12 @@ export class NormalShader {
66
86
  /**
67
87
  * Destroys this shader and cleans up resources.
68
88
  */
69
- init() {
70
- const gl = this.gl;
71
- const program = compileProgram(gl, this.vertexSrc || defaultVertexSrc, this.fragmentSrc);
89
+ public init(): void {
90
+ const { gl } = this;
91
+ const program = compileProgram(gl, this.vertexSrc ?? defaultVertexSrc, this.fragmentSrc);
92
+ if (!program) {
93
+ return;
94
+ }
72
95
  gl.useProgram(program);
73
96
  // get and store the uniforms for the shader
74
97
  this.uSampler = gl.getUniformLocation(program, 'uSampler');
@@ -90,10 +113,9 @@ export class NormalShader {
90
113
  this.attributes = [this.aVertexPosition, this.aTextureCoord, this.colorAttribute];
91
114
  // End worst hack eva //
92
115
  // add those custom shaders!
93
- const keys = Object.keys(this.uniforms);
94
- for (let i = 0; i < keys.length; i += 1) {
116
+ for (const [key, uniform] of Object.entries(this.uniforms)) {
95
117
  // get the uniform locations..
96
- this.uniforms[keys[i]].uniformLocation = gl.getUniformLocation(program, keys[i]);
118
+ uniform.uniformLocation = gl.getUniformLocation(program, key);
97
119
  }
98
120
  this.initUniforms();
99
121
  this.program = program;
@@ -102,15 +124,11 @@ export class NormalShader {
102
124
  /**
103
125
  * Binds this shader to the WebGL context.
104
126
  */
105
- initUniforms() {
127
+ public initUniforms() {
106
128
  this.textureCount = 1;
107
- const gl = this.gl;
108
- let uniform;
109
- const keys = Object.keys(this.uniforms);
110
- for (let i = 0; i < keys.length; i += 1) {
111
- const key = keys[i];
112
- uniform = this.uniforms[key];
113
- const type = uniform.type;
129
+ const { gl } = this;
130
+ for (const uniform of Object.values(this.uniforms)) {
131
+ const { type } = uniform;
114
132
  if (type === 'sampler2D') {
115
133
  uniform._init = false;
116
134
  if (uniform.value !== null) {
@@ -129,7 +147,7 @@ export class NormalShader {
129
147
  }
130
148
  } else {
131
149
  // GL function reference
132
- uniform.glFunc = gl[`uniform${type}`];
150
+ uniform.glFunc = glMember(gl, `uniform${type}`);
133
151
  if (type === '2f' || type === '2i') {
134
152
  uniform.glValueLength = 2;
135
153
  } else if (type === '3f' || type === '3i') {
@@ -147,12 +165,12 @@ export class NormalShader {
147
165
  * Sets a uniform value for this shader.
148
166
  * @param {object} uniform - The uniform to set.
149
167
  */
150
- initSampler2D(uniform: any) {
168
+ public initSampler2D(uniform: any) {
151
169
  if (!uniform.value || !uniform.value.baseTexture || !uniform.value.baseTexture.hasLoaded) {
152
170
  return;
153
171
  }
154
- const gl = this.gl;
155
- gl.activeTexture(gl[`TEXTURE${this.textureCount}`]);
172
+ const { gl } = this;
173
+ gl.activeTexture(glMember(gl, `TEXTURE${this.textureCount}`));
156
174
  gl.bindTexture(gl.TEXTURE_2D, uniform.value.baseTexture._glTextures[gl.id]);
157
175
  // Extended texture data
158
176
  if (uniform.textureData) {
@@ -165,20 +183,20 @@ export class NormalShader {
165
183
  // KeyTexture = whatever + luminance + width 256, height 2, border 0
166
184
  // magFilter can be: gl.LINEAR, gl.LINEAR_MIPMAP_LINEAR or gl.NEAREST
167
185
  // wrapS/T can be: gl.CLAMP_TO_EDGE or gl.REPEAT
168
- const magFilter = data.magFilter ? data.magFilter : gl.LINEAR;
169
- const minFilter = data.minFilter ? data.minFilter : gl.LINEAR;
170
- let wrapS = data.wrapS ? data.wrapS : gl.CLAMP_TO_EDGE;
171
- let wrapT = data.wrapT ? data.wrapT : gl.CLAMP_TO_EDGE;
186
+ const magFilter = data.magFilter ?? gl.LINEAR;
187
+ const minFilter = data.minFilter ?? gl.LINEAR;
188
+ let wrapS = data.wrapS ?? gl.CLAMP_TO_EDGE;
189
+ let wrapT = data.wrapT ?? gl.CLAMP_TO_EDGE;
172
190
  const format = data.luminance ? gl.LUMINANCE : gl.RGBA;
173
191
  if (data.repeat) {
174
192
  wrapS = gl.REPEAT;
175
193
  wrapT = gl.REPEAT;
176
194
  }
177
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, !!data.flipY);
195
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, Boolean(data.flipY));
178
196
  if (data.width) {
179
- const width = data.width ? data.width : 512;
180
- const height = data.height ? data.height : 2;
181
- const border = data.border ? data.border : 0;
197
+ const width = data.width ?? 512;
198
+ const height = data.height ?? 2;
199
+ const border = data.border ?? 0;
182
200
 
183
201
  // void texImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, ArrayBufferView? pixels);
184
202
  gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, border, format, gl.UNSIGNED_BYTE, null);
@@ -199,27 +217,23 @@ export class NormalShader {
199
217
  /**
200
218
  * Sets the shader to use for rendering.
201
219
  */
202
- syncUniforms() {
220
+ public syncUniforms() {
203
221
  this.textureCount = 1;
204
- let uniform;
205
- const gl = this.gl;
222
+ const { gl } = this;
206
223
  // This would probably be faster in an array and it would guarantee key order
207
- const keys = Object.keys(this.uniforms);
208
- for (let i = 0; i < keys.length; i += 1) {
209
- const key = keys[i];
210
- uniform = this.uniforms[key];
224
+ for (const uniform of Object.values(this.uniforms)) {
211
225
  if (uniform.glValueLength === 1) {
212
226
  if (uniform.glMatrix === true) {
213
- uniform.glFunc.call(gl, uniform.uniformLocation, uniform.transpose, uniform.value);
227
+ uniform.glFunc?.call(gl, uniform.uniformLocation, uniform.transpose, uniform.value);
214
228
  } else {
215
- uniform.glFunc.call(gl, uniform.uniformLocation, uniform.value);
229
+ uniform.glFunc?.call(gl, uniform.uniformLocation, uniform.value);
216
230
  }
217
231
  } else if (uniform.glValueLength === 2) {
218
- uniform.glFunc.call(gl, uniform.uniformLocation, uniform.value.x, uniform.value.y);
232
+ uniform.glFunc?.call(gl, uniform.uniformLocation, uniform.value.x, uniform.value.y);
219
233
  } else if (uniform.glValueLength === 3) {
220
- uniform.glFunc.call(gl, uniform.uniformLocation, uniform.value.x, uniform.value.y, uniform.value.z);
234
+ uniform.glFunc?.call(gl, uniform.uniformLocation, uniform.value.x, uniform.value.y, uniform.value.z);
221
235
  } else if (uniform.glValueLength === 4) {
222
- uniform.glFunc.call(
236
+ uniform.glFunc?.call(
223
237
  gl,
224
238
  uniform.uniformLocation,
225
239
  uniform.value.x,
@@ -229,15 +243,15 @@ export class NormalShader {
229
243
  );
230
244
  } else if (uniform.type === 'sampler2D') {
231
245
  if (uniform._init) {
232
- gl.activeTexture(gl[`TEXTURE${this.textureCount}`]);
246
+ gl.activeTexture(glMember(gl, `TEXTURE${this.textureCount}`));
233
247
  if (uniform.value.baseTexture._dirty[gl.id]) {
234
- window.PhaserRegistry.INSTANCES[gl.id].updateTexture(uniform.value.baseTexture);
248
+ globalThis.PhaserRegistry.INSTANCES[gl.id]?.updateTexture(uniform.value.baseTexture);
235
249
  } else {
236
250
  // bind the current texture
237
251
  gl.bindTexture(gl.TEXTURE_2D, uniform.value.baseTexture._glTextures[gl.id]);
238
252
  }
239
253
  // gl.bindTexture(gl.TEXTURE_2D, uniform.value.baseTexture._glTextures[gl.id] || PIXI.createWebGLTexture( uniform.value.baseTexture, gl));
240
- gl.uniform1i(uniform.uniformLocation, this.textureCount);
254
+ gl.uniform1i(uniform.uniformLocation ?? null, this.textureCount);
241
255
  this.textureCount += 1;
242
256
  } else {
243
257
  this.initSampler2D(uniform);
@@ -249,10 +263,9 @@ export class NormalShader {
249
263
  /**
250
264
  * Destroys this shader and cleans up resources.
251
265
  */
252
- destroy() {
266
+ public destroy(): void {
253
267
  this.gl.deleteProgram(this.program);
254
- this.uniforms = null;
255
- this.gl = null;
256
- this.attributes = null;
268
+ this.uniforms = {};
269
+ this.attributes = [];
257
270
  }
258
271
  }
@@ -4,17 +4,26 @@ import { compileProgram } from '../util.js';
4
4
  // the next one is used for rendering primitives
5
5
 
6
6
  export class PrimitiveShader {
7
- [key: string]: any;
8
- gl!: any;
9
- _UID!: any;
10
- program!: any;
11
- fragmentSrc!: any;
12
- vertexSrc!: any;
7
+ public gl: WebGLRenderingContext | null;
8
+ public _UID: string;
9
+ public program: WebGLProgram | null;
10
+ public fragmentSrc: string[];
11
+ public vertexSrc: string[];
12
+ public projectionVector!: WebGLUniformLocation | null;
13
+ public offsetVector!: WebGLUniformLocation | null;
14
+ public tintColor!: WebGLUniformLocation | null;
15
+ public flipY!: WebGLUniformLocation | null;
16
+ public translationMatrix!: WebGLUniformLocation | null;
17
+ public alpha!: WebGLUniformLocation | null;
18
+ public aVertexPosition!: number;
19
+ public colorAttribute!: number;
20
+ public uniforms: unknown = null;
21
+ public attributes: number[] | null = null;
13
22
  /**
14
23
  * Creates a new PrimitiveShader instance.
15
24
  * @param {WebGLRenderingContext} gl - The WebGL rendering context.
16
25
  */
17
- constructor(gl: WebGLRenderingContext) {
26
+ public constructor(gl: WebGLRenderingContext) {
18
27
  this.gl = gl;
19
28
  this._UID = uuidv4();
20
29
  /** @type {WebGLProgram} */
@@ -51,9 +60,15 @@ export class PrimitiveShader {
51
60
  /**
52
61
  * Destroys this shader and cleans up resources.
53
62
  */
54
- init() {
55
- const gl = this.gl;
63
+ public init(): void {
64
+ const { gl } = this;
65
+ if (!gl) {
66
+ return;
67
+ }
56
68
  const program = compileProgram(gl, this.vertexSrc, this.fragmentSrc);
69
+ if (!program) {
70
+ return;
71
+ }
57
72
  gl.useProgram(program);
58
73
  // get and store the uniforms for the shader
59
74
  this.projectionVector = gl.getUniformLocation(program, 'projectionVector');
@@ -72,8 +87,8 @@ export class PrimitiveShader {
72
87
  /**
73
88
  * Binds this shader to the WebGL context.
74
89
  */
75
- destroy() {
76
- this.gl.deleteProgram(this.program);
90
+ public destroy(): void {
91
+ this.gl?.deleteProgram(this.program);
77
92
  this.uniforms = null;
78
93
  this.gl = null;
79
94
  this.attributes = null;