@vpmedia/phaser 1.112.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.
- package/dist/index.js +1261 -1314
- package/dist/index.js.map +1 -1
- package/dist/phaser/core/animation.d.ts +14 -10
- package/dist/phaser/core/animation.d.ts.map +1 -1
- package/dist/phaser/core/animation_manager.d.ts +10 -8
- package/dist/phaser/core/animation_manager.d.ts.map +1 -1
- package/dist/phaser/core/animation_parser.d.ts +5 -4
- package/dist/phaser/core/animation_parser.d.ts.map +1 -1
- package/dist/phaser/core/array_set.d.ts.map +1 -1
- package/dist/phaser/core/cache.d.ts +4 -3
- package/dist/phaser/core/cache.d.ts.map +1 -1
- package/dist/phaser/core/const.d.ts.map +1 -1
- package/dist/phaser/core/device.d.ts.map +1 -1
- package/dist/phaser/core/device_util.d.ts.map +1 -1
- package/dist/phaser/core/dom.d.ts +3 -2
- package/dist/phaser/core/dom.d.ts.map +1 -1
- package/dist/phaser/core/event_manager.d.ts.map +1 -1
- package/dist/phaser/core/factory.d.ts +1 -1
- package/dist/phaser/core/factory.d.ts.map +1 -1
- package/dist/phaser/core/frame.d.ts.map +1 -1
- package/dist/phaser/core/frame_data.d.ts.map +1 -1
- package/dist/phaser/core/game.d.ts.map +1 -1
- package/dist/phaser/core/input.d.ts +8 -6
- package/dist/phaser/core/input.d.ts.map +1 -1
- package/dist/phaser/core/input_handler.d.ts +40 -30
- package/dist/phaser/core/input_handler.d.ts.map +1 -1
- package/dist/phaser/core/input_mouse.d.ts +3 -2
- package/dist/phaser/core/input_mouse.d.ts.map +1 -1
- package/dist/phaser/core/input_mspointer.d.ts +3 -2
- package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
- package/dist/phaser/core/input_pointer.d.ts +6 -4
- package/dist/phaser/core/input_pointer.d.ts.map +1 -1
- package/dist/phaser/core/input_touch.d.ts +3 -2
- package/dist/phaser/core/input_touch.d.ts.map +1 -1
- package/dist/phaser/core/loader.d.ts +4 -3
- package/dist/phaser/core/loader.d.ts.map +1 -1
- package/dist/phaser/core/loader_parser.d.ts +9 -8
- package/dist/phaser/core/loader_parser.d.ts.map +1 -1
- package/dist/phaser/core/raf.d.ts +3 -2
- package/dist/phaser/core/raf.d.ts.map +1 -1
- package/dist/phaser/core/registry.d.ts +7 -0
- package/dist/phaser/core/registry.d.ts.map +1 -0
- package/dist/phaser/core/scale_manager.d.ts +1 -1
- package/dist/phaser/core/scale_manager.d.ts.map +1 -1
- package/dist/phaser/core/scene.d.ts +0 -1
- package/dist/phaser/core/scene.d.ts.map +1 -1
- package/dist/phaser/core/scene_manager.d.ts +1 -1
- package/dist/phaser/core/scene_manager.d.ts.map +1 -1
- package/dist/phaser/core/signal.d.ts +0 -1
- package/dist/phaser/core/signal.d.ts.map +1 -1
- package/dist/phaser/core/signal_binding.d.ts +4 -3
- package/dist/phaser/core/signal_binding.d.ts.map +1 -1
- package/dist/phaser/core/sound.d.ts +6 -4
- package/dist/phaser/core/sound.d.ts.map +1 -1
- package/dist/phaser/core/sound_manager.d.ts +3 -2
- package/dist/phaser/core/sound_manager.d.ts.map +1 -1
- package/dist/phaser/core/sound_sprite.d.ts +5 -4
- package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
- package/dist/phaser/core/stage.d.ts +3 -2
- package/dist/phaser/core/stage.d.ts.map +1 -1
- package/dist/phaser/core/time.d.ts +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/timer_event.d.ts.map +1 -1
- package/dist/phaser/core/tween.d.ts +10 -7
- package/dist/phaser/core/tween.d.ts.map +1 -1
- package/dist/phaser/core/tween_data.d.ts +3 -2
- package/dist/phaser/core/tween_data.d.ts.map +1 -1
- package/dist/phaser/core/tween_easing.d.ts.map +1 -1
- package/dist/phaser/core/tween_manager.d.ts +3 -2
- package/dist/phaser/core/tween_manager.d.ts.map +1 -1
- package/dist/phaser/core/world.d.ts +3 -2
- package/dist/phaser/core/world.d.ts.map +1 -1
- package/dist/phaser/display/bitmap_text.d.ts +3 -2
- package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
- package/dist/phaser/display/button.d.ts +3 -2
- package/dist/phaser/display/button.d.ts.map +1 -1
- package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/graphics.d.ts +7 -6
- package/dist/phaser/display/canvas/graphics.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 +10 -8
- package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/tinter.d.ts +3 -2
- package/dist/phaser/display/canvas/tinter.d.ts.map +1 -1
- package/dist/phaser/display/canvas/util.d.ts +2 -2
- package/dist/phaser/display/canvas/util.d.ts.map +1 -1
- package/dist/phaser/display/display_object.d.ts +14 -12
- package/dist/phaser/display/display_object.d.ts.map +1 -1
- package/dist/phaser/display/graphics.d.ts +8 -5
- package/dist/phaser/display/graphics.d.ts.map +1 -1
- package/dist/phaser/display/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/graphics_data_util.d.ts.map +1 -1
- package/dist/phaser/display/group.d.ts +4 -3
- package/dist/phaser/display/group.d.ts.map +1 -1
- package/dist/phaser/display/image.d.ts +13 -10
- package/dist/phaser/display/image.d.ts.map +1 -1
- package/dist/phaser/display/sprite_batch.d.ts +3 -2
- package/dist/phaser/display/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/sprite_util.d.ts +18 -15
- package/dist/phaser/display/sprite_util.d.ts.map +1 -1
- package/dist/phaser/display/text.d.ts +11 -9
- package/dist/phaser/display/text.d.ts.map +1 -1
- package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
- package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/blend_manager.d.ts +0 -1
- package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut_node.d.ts.map +1 -1
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +4 -3
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts +2 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_texture.d.ts +2 -1
- package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics.d.ts +7 -6
- package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics_data.d.ts +2 -1
- package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/webgl/render_texture.d.ts +4 -2
- package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/renderer.d.ts +16 -11
- package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/complex.d.ts +16 -6
- package/dist/phaser/display/webgl/shader/complex.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/fast.d.ts +19 -7
- package/dist/phaser/display/webgl/shader/fast.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/normal.d.ts +33 -12
- package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/primitive.d.ts +15 -6
- package/dist/phaser/display/webgl/shader/primitive.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/strip.d.ts +15 -6
- package/dist/phaser/display/webgl/shader/strip.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader_manager.d.ts +16 -11
- package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/sprite_batch.d.ts +29 -20
- package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/stencil_manager.d.ts +12 -10
- package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture.d.ts +3 -2
- package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
- package/dist/phaser/display/webgl/util.d.ts.map +1 -1
- package/dist/phaser/geom/circle.d.ts +4 -1
- package/dist/phaser/geom/circle.d.ts.map +1 -1
- package/dist/phaser/geom/ellipse.d.ts.map +1 -1
- package/dist/phaser/geom/line.d.ts +1 -1
- package/dist/phaser/geom/line.d.ts.map +1 -1
- package/dist/phaser/geom/matrix.d.ts.map +1 -1
- package/dist/phaser/geom/point.d.ts.map +1 -1
- package/dist/phaser/geom/polygon.d.ts.map +1 -1
- package/dist/phaser/geom/rectangle.d.ts.map +1 -1
- package/dist/phaser/geom/rounded_rectangle.d.ts.map +1 -1
- package/dist/phaser/geom/util/circle.d.ts.map +1 -1
- package/dist/phaser/geom/util/ellipse.d.ts +3 -2
- package/dist/phaser/geom/util/ellipse.d.ts.map +1 -1
- package/dist/phaser/geom/util/line.d.ts.map +1 -1
- package/dist/phaser/geom/util/matrix.d.ts +2 -2
- package/dist/phaser/geom/util/matrix.d.ts.map +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 +5 -5
- package/src/phaser/core/animation.ts +64 -60
- package/src/phaser/core/animation_manager.ts +50 -53
- package/src/phaser/core/animation_parser.ts +9 -9
- package/src/phaser/core/array_set.ts +16 -17
- package/src/phaser/core/cache.ts +92 -93
- package/src/phaser/core/const.ts +1 -1
- package/src/phaser/core/device.ts +24 -29
- package/src/phaser/core/device_util.ts +22 -26
- package/src/phaser/core/dom.ts +54 -65
- package/src/phaser/core/event_manager.ts +64 -94
- package/src/phaser/core/factory.ts +14 -14
- package/src/phaser/core/frame.ts +28 -28
- package/src/phaser/core/frame_data.test.ts +100 -0
- package/src/phaser/core/frame_data.ts +24 -24
- package/src/phaser/core/frame_util.ts +2 -2
- package/src/phaser/core/game.ts +47 -48
- package/src/phaser/core/input.ts +104 -110
- package/src/phaser/core/input_handler.test.ts +113 -0
- package/src/phaser/core/input_handler.ts +199 -218
- package/src/phaser/core/input_mouse.ts +71 -54
- package/src/phaser/core/input_mspointer.ts +52 -39
- package/src/phaser/core/input_pointer.ts +81 -80
- package/src/phaser/core/input_touch.ts +49 -36
- package/src/phaser/core/loader.ts +173 -152
- package/src/phaser/core/loader_parser.ts +39 -57
- package/src/phaser/core/raf.ts +8 -7
- package/src/phaser/core/registry.test.ts +31 -0
- package/src/phaser/core/registry.ts +9 -0
- package/src/phaser/core/scale_manager.ts +156 -152
- package/src/phaser/core/scene.ts +9 -13
- package/src/phaser/core/scene_manager.ts +47 -47
- package/src/phaser/core/signal.test.ts +4 -4
- package/src/phaser/core/signal.ts +41 -52
- package/src/phaser/core/signal_binding.ts +26 -25
- package/src/phaser/core/signal_dispatch.test.ts +180 -0
- package/src/phaser/core/sound.ts +75 -83
- package/src/phaser/core/sound_manager.ts +52 -51
- package/src/phaser/core/sound_sprite.ts +17 -16
- package/src/phaser/core/stage.ts +25 -24
- package/src/phaser/core/time.ts +52 -52
- package/src/phaser/core/timer.test.ts +187 -0
- package/src/phaser/core/timer.ts +82 -69
- package/src/phaser/core/timer_event.ts +10 -10
- package/src/phaser/core/tween.ts +90 -93
- package/src/phaser/core/tween_data.ts +45 -51
- package/src/phaser/core/tween_easing.test.ts +106 -0
- package/src/phaser/core/tween_easing.ts +151 -123
- package/src/phaser/core/tween_manager.ts +19 -18
- package/src/phaser/core/world.ts +4 -3
- package/src/phaser/display/bitmap_text.ts +56 -64
- package/src/phaser/display/button.ts +33 -32
- package/src/phaser/display/canvas/buffer.ts +8 -8
- package/src/phaser/display/canvas/graphics.ts +36 -37
- package/src/phaser/display/canvas/masker.ts +2 -2
- package/src/phaser/display/canvas/pool.test.ts +106 -0
- package/src/phaser/display/canvas/pool.ts +25 -27
- package/src/phaser/display/canvas/renderer.ts +32 -31
- package/src/phaser/display/canvas/tinter.ts +25 -25
- package/src/phaser/display/canvas/util.ts +7 -10
- package/src/phaser/display/display_object.ts +114 -118
- package/src/phaser/display/graphics.ts +121 -119
- package/src/phaser/display/graphics_data.ts +12 -12
- package/src/phaser/display/graphics_data_util.ts +2 -3
- package/src/phaser/display/group.ts +50 -57
- package/src/phaser/display/image.ts +55 -52
- package/src/phaser/display/sprite_batch.ts +3 -2
- package/src/phaser/display/sprite_util.ts +48 -54
- package/src/phaser/display/text.ts +199 -204
- package/src/phaser/display/webgl/abstract_filter.ts +9 -9
- package/src/phaser/display/webgl/base_texture.ts +21 -24
- package/src/phaser/display/webgl/blend_manager.ts +6 -10
- package/src/phaser/display/webgl/earcut.ts +73 -37
- package/src/phaser/display/webgl/earcut_node.ts +10 -10
- package/src/phaser/display/webgl/fast_sprite_batch.ts +34 -34
- package/src/phaser/display/webgl/filter_manager.ts +13 -12
- package/src/phaser/display/webgl/filter_texture.ts +14 -13
- package/src/phaser/display/webgl/graphics.ts +51 -57
- package/src/phaser/display/webgl/graphics_data.ts +15 -14
- package/src/phaser/display/webgl/mask_manager.ts +2 -2
- package/src/phaser/display/webgl/render_texture.ts +26 -25
- package/src/phaser/display/webgl/renderer.ts +57 -62
- package/src/phaser/display/webgl/shader/complex.ts +28 -12
- package/src/phaser/display/webgl/shader/fast.ts +30 -12
- package/src/phaser/display/webgl/shader/normal.ts +70 -57
- package/src/phaser/display/webgl/shader/primitive.ts +26 -11
- package/src/phaser/display/webgl/shader/shader.test.ts +148 -0
- package/src/phaser/display/webgl/shader/strip.ts +27 -12
- package/src/phaser/display/webgl/shader_manager.test.ts +124 -0
- package/src/phaser/display/webgl/shader_manager.ts +26 -34
- package/src/phaser/display/webgl/sprite_batch.ts +67 -61
- package/src/phaser/display/webgl/stencil_manager.ts +23 -34
- package/src/phaser/display/webgl/texture.ts +43 -50
- package/src/phaser/display/webgl/texture_util.ts +2 -3
- package/src/phaser/display/webgl/util.ts +26 -25
- package/src/phaser/geom/circle.test.ts +2 -3
- package/src/phaser/geom/circle.ts +36 -36
- package/src/phaser/geom/ellipse.test.ts +73 -71
- package/src/phaser/geom/ellipse.ts +14 -14
- package/src/phaser/geom/line.test.ts +5 -5
- package/src/phaser/geom/line.ts +35 -35
- package/src/phaser/geom/matrix.test.ts +1 -1
- package/src/phaser/geom/matrix.ts +27 -27
- package/src/phaser/geom/point.test.ts +1 -2
- package/src/phaser/geom/point.ts +35 -35
- package/src/phaser/geom/polygon.test.ts +82 -0
- package/src/phaser/geom/polygon.ts +16 -16
- package/src/phaser/geom/rectangle.test.ts +14 -14
- package/src/phaser/geom/rectangle.ts +83 -75
- package/src/phaser/geom/rounded_rectangle.test.ts +1 -7
- package/src/phaser/geom/rounded_rectangle.ts +9 -9
- package/src/phaser/geom/util/circle.test.ts +25 -23
- package/src/phaser/geom/util/circle.ts +9 -18
- package/src/phaser/geom/util/ellipse.test.ts +7 -5
- package/src/phaser/geom/util/ellipse.ts +3 -2
- package/src/phaser/geom/util/line.test.ts +10 -8
- package/src/phaser/geom/util/line.ts +6 -16
- package/src/phaser/geom/util/matrix.test.ts +20 -18
- package/src/phaser/geom/util/matrix.ts +8 -15
- package/src/phaser/geom/util/point.test.ts +8 -6
- package/src/phaser/geom/util/point.ts +24 -28
- package/src/phaser/geom/util/polygon.test.ts +12 -10
- package/src/phaser/geom/util/polygon.ts +2 -2
- package/src/phaser/geom/util/rectangle.test.ts +10 -8
- package/src/phaser/geom/util/rectangle.ts +18 -37
- package/src/phaser/geom/util/rounded_rectangle.test.ts +11 -9
- package/src/phaser/geom/util/rounded_rectangle.ts +1 -1
- package/src/phaser/util/math.test.ts +11 -11
- 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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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 {
|
|
60
|
+
* @param {Game} game - The game instance.
|
|
56
61
|
*/
|
|
57
|
-
constructor(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
|
-
|
|
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
|
-
|
|
123
|
-
|
|
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
|
-
|
|
131
|
-
|
|
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 {
|
|
141
|
+
* @param {Game} game - The game instance.
|
|
144
142
|
* @throws {Error}
|
|
145
143
|
*/
|
|
146
|
-
initContext(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
|
-
|
|
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 =
|
|
167
|
-
gl.id =
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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 {
|
|
185
|
+
* @param {Stage} stage - The root stage to render.
|
|
189
186
|
*/
|
|
190
|
-
render(stage:
|
|
187
|
+
public render(stage: Stage) {
|
|
191
188
|
if (this.contextLost) {
|
|
192
189
|
return;
|
|
193
190
|
}
|
|
194
|
-
const gl = this
|
|
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 {
|
|
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 {
|
|
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 {
|
|
253
|
+
* @param {BaseTexture} texture - The base texture to update.
|
|
257
254
|
* @returns {boolean} Whether the update was successful.
|
|
258
255
|
*/
|
|
259
|
-
updateTexture(texture:
|
|
256
|
+
public updateTexture(texture: BaseTexture) {
|
|
260
257
|
if (!texture.hasLoaded) {
|
|
261
258
|
return false;
|
|
262
259
|
}
|
|
263
|
-
const gl = this
|
|
264
|
-
|
|
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 (
|
|
295
|
+
public mapBlendModes() {
|
|
296
|
+
if (globalThis.PhaserRegistry.blendModesWebGL) {
|
|
302
297
|
return;
|
|
303
298
|
}
|
|
304
|
-
const gl = this
|
|
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
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
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
|
|
93
|
+
public destroy(): void {
|
|
94
|
+
this.gl?.deleteProgram(this.program);
|
|
79
95
|
this.uniforms = null;
|
|
80
96
|
this.gl = null;
|
|
81
|
-
this.
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
|
71
|
-
const program = compileProgram(gl, this.vertexSrc
|
|
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
|
|
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
|
-
|
|
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
|
|
108
|
-
|
|
109
|
-
|
|
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
|
|
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
|
|
155
|
-
gl.activeTexture(gl
|
|
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
|
|
169
|
-
const minFilter = data.minFilter
|
|
170
|
-
let wrapS = data.wrapS
|
|
171
|
-
let wrapT = data.wrapT
|
|
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,
|
|
195
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, Boolean(data.flipY));
|
|
178
196
|
if (data.width) {
|
|
179
|
-
const width = data.width
|
|
180
|
-
const height = data.height
|
|
181
|
-
const border = data.border
|
|
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
|
-
|
|
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
|
|
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
|
|
227
|
+
uniform.glFunc?.call(gl, uniform.uniformLocation, uniform.transpose, uniform.value);
|
|
214
228
|
} else {
|
|
215
|
-
uniform.glFunc
|
|
229
|
+
uniform.glFunc?.call(gl, uniform.uniformLocation, uniform.value);
|
|
216
230
|
}
|
|
217
231
|
} else if (uniform.glValueLength === 2) {
|
|
218
|
-
uniform.glFunc
|
|
232
|
+
uniform.glFunc?.call(gl, uniform.uniformLocation, uniform.value.x, uniform.value.y);
|
|
219
233
|
} else if (uniform.glValueLength === 3) {
|
|
220
|
-
uniform.glFunc
|
|
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
|
|
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
|
|
246
|
+
gl.activeTexture(glMember(gl, `TEXTURE${this.textureCount}`));
|
|
233
247
|
if (uniform.value.baseTexture._dirty[gl.id]) {
|
|
234
|
-
|
|
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 =
|
|
255
|
-
this.
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
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
|
|
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;
|