@vpmedia/phaser 1.115.0 → 1.117.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 +56 -96
- package/dist/index.js.map +1 -1
- package/dist/phaser/core/animation.d.ts.map +1 -1
- package/dist/phaser/core/animation_manager.d.ts +15 -14
- package/dist/phaser/core/animation_manager.d.ts.map +1 -1
- 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 +10 -9
- package/dist/phaser/core/cache.d.ts.map +1 -1
- package/dist/phaser/core/device_util.d.ts.map +1 -1
- package/dist/phaser/core/dom.d.ts.map +1 -1
- package/dist/phaser/core/factory.d.ts.map +1 -1
- package/dist/phaser/core/game.d.ts.map +1 -1
- package/dist/phaser/core/input.d.ts +20 -20
- package/dist/phaser/core/input.d.ts.map +1 -1
- package/dist/phaser/core/input_handler.d.ts +11 -13
- package/dist/phaser/core/input_handler.d.ts.map +1 -1
- package/dist/phaser/core/input_mouse.d.ts.map +1 -1
- package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
- package/dist/phaser/core/input_pointer.d.ts +19 -8
- package/dist/phaser/core/input_pointer.d.ts.map +1 -1
- package/dist/phaser/core/input_touch.d.ts.map +1 -1
- package/dist/phaser/core/loader.d.ts.map +1 -1
- package/dist/phaser/core/raf.d.ts.map +1 -1
- package/dist/phaser/core/scale_manager.d.ts +38 -13
- package/dist/phaser/core/scale_manager.d.ts.map +1 -1
- package/dist/phaser/core/scene.d.ts.map +1 -1
- package/dist/phaser/core/scene_manager.d.ts.map +1 -1
- package/dist/phaser/core/signal.d.ts.map +1 -1
- package/dist/phaser/core/signal_binding.d.ts.map +1 -1
- package/dist/phaser/core/sound.d.ts +2 -2
- package/dist/phaser/core/sound.d.ts.map +1 -1
- package/dist/phaser/core/sound_manager.d.ts +24 -22
- package/dist/phaser/core/sound_manager.d.ts.map +1 -1
- package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
- package/dist/phaser/core/stage.d.ts.map +1 -1
- package/dist/phaser/core/time.d.ts.map +1 -1
- package/dist/phaser/core/timer.d.ts +1 -1
- package/dist/phaser/core/timer.d.ts.map +1 -1
- package/dist/phaser/core/tween.d.ts.map +1 -1
- package/dist/phaser/core/tween_data.d.ts +26 -26
- package/dist/phaser/core/tween_data.d.ts.map +1 -1
- package/dist/phaser/core/tween_manager.d.ts.map +1 -1
- package/dist/phaser/core/world.d.ts.map +1 -1
- package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/phaser/display/canvas/masker.d.ts.map +1 -1
- package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/phaser/display/display_object.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/phaser/display/image.d.ts +2 -2
- package/dist/phaser/display/image.d.ts.map +1 -1
- package/dist/phaser/display/sprite_util.d.ts.map +1 -1
- 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 +12 -10
- package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +13 -12
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics.d.ts +9 -7
- package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/webgl/mask_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/renderer.d.ts +12 -10
- package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture.d.ts +18 -33
- 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.map +1 -1
- package/dist/phaser/geom/ellipse.d.ts.map +1 -1
- package/dist/phaser/geom/line.d.ts.map +1 -1
- package/dist/phaser/geom/matrix.d.ts +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.map +1 -1
- package/dist/phaser/geom/util/line.d.ts +5 -4
- package/dist/phaser/geom/util/line.d.ts.map +1 -1
- 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/polygon.d.ts.map +1 -1
- package/dist/phaser/geom/util/rectangle.d.ts +10 -1
- package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
- package/dist/phaser/geom/util/rounded_rectangle.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/phaser/core/animation.ts +20 -20
- package/src/phaser/core/animation_manager.ts +27 -24
- package/src/phaser/core/animation_parser.ts +2 -2
- package/src/phaser/core/array_set.ts +7 -7
- package/src/phaser/core/cache.ts +55 -51
- package/src/phaser/core/callback_context.test.ts +70 -0
- package/src/phaser/core/device_util.ts +13 -13
- package/src/phaser/core/dom.ts +26 -22
- package/src/phaser/core/factory.ts +6 -6
- package/src/phaser/core/game.ts +10 -10
- package/src/phaser/core/input.ts +37 -39
- package/src/phaser/core/input_handler.ts +90 -93
- package/src/phaser/core/input_mouse.ts +19 -19
- package/src/phaser/core/input_mspointer.ts +15 -15
- package/src/phaser/core/input_pointer.ts +37 -28
- package/src/phaser/core/input_touch.ts +17 -17
- package/src/phaser/core/loader.ts +52 -52
- package/src/phaser/core/loader_parser.ts +3 -3
- package/src/phaser/core/raf.ts +3 -3
- package/src/phaser/core/scale_manager.ts +86 -67
- package/src/phaser/core/scene.ts +7 -7
- package/src/phaser/core/scene_manager.ts +16 -16
- package/src/phaser/core/signal.ts +29 -19
- package/src/phaser/core/signal_binding.ts +4 -4
- package/src/phaser/core/sound.ts +17 -17
- package/src/phaser/core/sound_manager.ts +71 -72
- package/src/phaser/core/sound_sprite.ts +1 -1
- package/src/phaser/core/stage.ts +7 -7
- package/src/phaser/core/time.ts +16 -16
- package/src/phaser/core/timer.ts +36 -26
- package/src/phaser/core/tween.ts +23 -23
- package/src/phaser/core/tween_data.ts +41 -37
- package/src/phaser/core/tween_manager.ts +11 -11
- package/src/phaser/core/world.ts +1 -1
- package/src/phaser/display/bitmap_text.ts +13 -13
- package/src/phaser/display/button.ts +13 -13
- package/src/phaser/display/canvas/buffer.ts +3 -3
- package/src/phaser/display/canvas/graphics.ts +3 -3
- package/src/phaser/display/canvas/masker.ts +2 -2
- package/src/phaser/display/canvas/pool.ts +6 -6
- package/src/phaser/display/canvas/renderer.ts +6 -6
- package/src/phaser/display/canvas/tinter.ts +39 -8
- package/src/phaser/display/canvas/util.ts +15 -9
- package/src/phaser/display/display_object.ts +38 -38
- package/src/phaser/display/graphics.ts +30 -30
- package/src/phaser/display/graphics_data.ts +1 -1
- package/src/phaser/display/graphics_data_util.ts +1 -1
- package/src/phaser/display/group.ts +16 -16
- package/src/phaser/display/image.ts +30 -26
- package/src/phaser/display/sprite_util.ts +12 -4
- package/src/phaser/display/text.ts +55 -55
- package/src/phaser/display/webgl/abstract_filter.ts +1 -1
- package/src/phaser/display/webgl/base_texture.ts +22 -18
- package/src/phaser/display/webgl/blend_manager.ts +3 -3
- package/src/phaser/display/webgl/earcut.ts +3 -3
- package/src/phaser/display/webgl/fast_sprite_batch.ts +26 -24
- package/src/phaser/display/webgl/filter_manager.ts +7 -7
- package/src/phaser/display/webgl/filter_texture.ts +3 -3
- package/src/phaser/display/webgl/graphics.ts +43 -41
- package/src/phaser/display/webgl/graphics_data.ts +2 -2
- package/src/phaser/display/webgl/mask_manager.ts +2 -2
- package/src/phaser/display/webgl/render_texture.ts +6 -6
- package/src/phaser/display/webgl/renderer.ts +20 -25
- package/src/phaser/display/webgl/shader/normal.ts +3 -3
- package/src/phaser/display/webgl/shader_manager.ts +2 -2
- package/src/phaser/display/webgl/sprite_batch.ts +9 -9
- package/src/phaser/display/webgl/stencil_manager.ts +4 -4
- package/src/phaser/display/webgl/texture.ts +23 -42
- package/src/phaser/display/webgl/texture_util.ts +2 -2
- package/src/phaser/display/webgl/util.ts +11 -7
- package/src/phaser/geom/circle.ts +21 -21
- package/src/phaser/geom/ellipse.ts +7 -7
- package/src/phaser/geom/line.ts +29 -29
- package/src/phaser/geom/matrix.ts +13 -13
- package/src/phaser/geom/point.ts +36 -30
- package/src/phaser/geom/polygon.ts +6 -6
- package/src/phaser/geom/rectangle.ts +42 -42
- package/src/phaser/geom/rounded_rectangle.ts +2 -2
- package/src/phaser/geom/util/circle.ts +7 -7
- package/src/phaser/geom/util/ellipse.ts +1 -1
- package/src/phaser/geom/util/line.ts +13 -5
- package/src/phaser/geom/util/matrix.ts +3 -3
- package/src/phaser/geom/util/point.ts +20 -20
- package/src/phaser/geom/util/polygon.ts +1 -1
- package/src/phaser/geom/util/rectangle.ts +34 -17
- package/src/phaser/geom/util/rounded_rectangle.ts +1 -1
|
@@ -1,20 +1,21 @@
|
|
|
1
|
+
import type { BaseTexture } from './base_texture.js';
|
|
1
2
|
import type { IdentifiedWebGLRenderingContext } from './util.js';
|
|
2
3
|
import type { Image } from '../../display/image.js';
|
|
3
4
|
import type { RenderSession } from '../render_session.js';
|
|
4
5
|
|
|
5
6
|
export class FastSpriteBatch {
|
|
6
|
-
public gl!:
|
|
7
|
-
public vertSize
|
|
8
|
-
public maxSize
|
|
9
|
-
public size!:
|
|
10
|
-
public vertices!:
|
|
11
|
-
public indices!:
|
|
12
|
-
public vertexBuffer!:
|
|
13
|
-
public indexBuffer!:
|
|
14
|
-
public lastIndexCount!:
|
|
15
|
-
public drawing!:
|
|
16
|
-
public currentBatchSize!:
|
|
17
|
-
public currentBaseTexture!:
|
|
7
|
+
public gl!: IdentifiedWebGLRenderingContext;
|
|
8
|
+
public vertSize = 10;
|
|
9
|
+
public maxSize = 6e3;
|
|
10
|
+
public size!: number;
|
|
11
|
+
public vertices!: Float32Array;
|
|
12
|
+
public indices!: Uint16Array;
|
|
13
|
+
public vertexBuffer!: WebGLBuffer | null;
|
|
14
|
+
public indexBuffer!: WebGLBuffer | null;
|
|
15
|
+
public lastIndexCount!: number;
|
|
16
|
+
public drawing!: boolean;
|
|
17
|
+
public currentBatchSize!: number;
|
|
18
|
+
public currentBaseTexture!: BaseTexture | null;
|
|
18
19
|
public currentBlendMode!: any;
|
|
19
20
|
public renderSession!: RenderSession;
|
|
20
21
|
public shader!: any;
|
|
@@ -56,7 +57,7 @@ export class FastSpriteBatch {
|
|
|
56
57
|
* Sets the WebGL context for this batch.
|
|
57
58
|
* @param {WebGLRenderingContext & { id: number }} gl - The WebGL rendering context.
|
|
58
59
|
*/
|
|
59
|
-
public setContext(gl: IdentifiedWebGLRenderingContext) {
|
|
60
|
+
public setContext(gl: IdentifiedWebGLRenderingContext): void {
|
|
60
61
|
this.gl = gl;
|
|
61
62
|
// create a couple of buffers
|
|
62
63
|
this.vertexBuffer = gl.createBuffer();
|
|
@@ -74,7 +75,7 @@ export class FastSpriteBatch {
|
|
|
74
75
|
* @param {object} spriteBatch - The sprite batch to render.
|
|
75
76
|
* @param {object} renderSession - The render session to use.
|
|
76
77
|
*/
|
|
77
|
-
public begin(spriteBatch: any, renderSession: RenderSession) {
|
|
78
|
+
public begin(spriteBatch: any, renderSession: RenderSession): void {
|
|
78
79
|
this.renderSession = renderSession;
|
|
79
80
|
this.shader = this.renderSession.shaderManager.fastShader;
|
|
80
81
|
this.matrix = spriteBatch.worldTransform.toArray(true);
|
|
@@ -84,7 +85,7 @@ export class FastSpriteBatch {
|
|
|
84
85
|
/**
|
|
85
86
|
* Updates the sprite batch.
|
|
86
87
|
*/
|
|
87
|
-
public end() {
|
|
88
|
+
public end(): void {
|
|
88
89
|
this.flush();
|
|
89
90
|
}
|
|
90
91
|
|
|
@@ -92,7 +93,7 @@ export class FastSpriteBatch {
|
|
|
92
93
|
* Flushes the sprite batch to WebGL.
|
|
93
94
|
* @param {object} spriteBatch - The sprite batch to flush.
|
|
94
95
|
*/
|
|
95
|
-
public render(spriteBatch: any) {
|
|
96
|
+
public render(spriteBatch: any): void {
|
|
96
97
|
const { children } = spriteBatch;
|
|
97
98
|
const sprite = children[0];
|
|
98
99
|
// if the uvs have not updated then no point rendering just yet!
|
|
@@ -116,7 +117,7 @@ export class FastSpriteBatch {
|
|
|
116
117
|
* Renders a sprite using WebGL.
|
|
117
118
|
* @param {Image} sprite - The sprite to render.
|
|
118
119
|
*/
|
|
119
|
-
public renderSprite(sprite: Image) {
|
|
120
|
+
public renderSprite(sprite: Image): void {
|
|
120
121
|
if (!sprite.visible) {
|
|
121
122
|
return;
|
|
122
123
|
}
|
|
@@ -128,7 +129,7 @@ export class FastSpriteBatch {
|
|
|
128
129
|
return;
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
|
-
const uvs = sprite.texture._uvs
|
|
132
|
+
const uvs = sprite.texture._uvs!;
|
|
132
133
|
const { vertices } = this;
|
|
133
134
|
// const width = sprite.texture.frame.width;
|
|
134
135
|
// const height = sprite.texture.frame.height;
|
|
@@ -222,17 +223,18 @@ export class FastSpriteBatch {
|
|
|
222
223
|
/**
|
|
223
224
|
* Binds the sprite batch to the WebGL context.
|
|
224
225
|
*/
|
|
225
|
-
public flush() {
|
|
226
|
+
public flush(): void {
|
|
226
227
|
// If the batch is length 0 then return as there is nothing to draw
|
|
227
228
|
if (this.currentBatchSize === 0) {
|
|
228
229
|
return;
|
|
229
230
|
}
|
|
230
231
|
const { gl } = this;
|
|
231
232
|
// bind the current texture
|
|
232
|
-
|
|
233
|
-
|
|
233
|
+
const baseTexture = this.currentBaseTexture!;
|
|
234
|
+
if (!baseTexture._glTextures[gl.id]) {
|
|
235
|
+
this.renderSession.renderer.updateTexture(baseTexture);
|
|
234
236
|
}
|
|
235
|
-
gl.bindTexture(gl.TEXTURE_2D,
|
|
237
|
+
gl.bindTexture(gl.TEXTURE_2D, baseTexture._glTextures[gl.id] ?? null);
|
|
236
238
|
// upload the verts to the buffer
|
|
237
239
|
if (this.currentBatchSize > this.size * 0.5) {
|
|
238
240
|
gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.vertices);
|
|
@@ -251,14 +253,14 @@ export class FastSpriteBatch {
|
|
|
251
253
|
/**
|
|
252
254
|
* Renders a sprite using the sprite batch.
|
|
253
255
|
*/
|
|
254
|
-
public stop() {
|
|
256
|
+
public stop(): void {
|
|
255
257
|
this.flush();
|
|
256
258
|
}
|
|
257
259
|
|
|
258
260
|
/**
|
|
259
261
|
* Sets up the sprite batch for WebGL rendering.
|
|
260
262
|
*/
|
|
261
|
-
public start() {
|
|
263
|
+
public start(): void {
|
|
262
264
|
const { gl } = this;
|
|
263
265
|
// bind the main texture
|
|
264
266
|
gl.activeTexture(gl.TEXTURE0);
|
|
@@ -17,7 +17,7 @@ export class WebGLFilterManager {
|
|
|
17
17
|
* Initializes the filter manager with a WebGL context.
|
|
18
18
|
* @param {WebGLRenderingContext} gl - The WebGL rendering context.
|
|
19
19
|
*/
|
|
20
|
-
public setContext(gl: WebGLRenderingContext) {
|
|
20
|
+
public setContext(gl: WebGLRenderingContext): void {
|
|
21
21
|
this.gl = gl;
|
|
22
22
|
this.texturePool = [];
|
|
23
23
|
this.initShaderBuffers();
|
|
@@ -26,42 +26,42 @@ export class WebGLFilterManager {
|
|
|
26
26
|
/**
|
|
27
27
|
* Applies a filter to the specified texture.
|
|
28
28
|
*/
|
|
29
|
-
public begin() {
|
|
29
|
+
public begin(): void {
|
|
30
30
|
// TODO
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Updates the filter texture for the specified size.
|
|
35
35
|
*/
|
|
36
|
-
public pushFilter(_filterBlock: object | null) {
|
|
36
|
+
public pushFilter(_filterBlock: object | null): void {
|
|
37
37
|
// TODO
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* Resizes the filter manager to the specified dimensions.
|
|
42
42
|
*/
|
|
43
|
-
public popFilter() {
|
|
43
|
+
public popFilter(): void {
|
|
44
44
|
// TODO
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* Destroys this filter manager and cleans up resources.
|
|
49
49
|
*/
|
|
50
|
-
public applyFilterPass() {
|
|
50
|
+
public applyFilterPass(): void {
|
|
51
51
|
// TODO
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* Initializes the filter manager.
|
|
56
56
|
*/
|
|
57
|
-
public initShaderBuffers() {
|
|
57
|
+
public initShaderBuffers(): void {
|
|
58
58
|
// TODO
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
62
|
* Sets up the filter manager for WebGL rendering.
|
|
63
63
|
*/
|
|
64
|
-
public destroy() {
|
|
64
|
+
public destroy(): void {
|
|
65
65
|
// TODO
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -37,7 +37,7 @@ export class FilterTexture {
|
|
|
37
37
|
/**
|
|
38
38
|
* Destroys this filter texture and cleans up resources.
|
|
39
39
|
*/
|
|
40
|
-
public clear() {
|
|
40
|
+
public clear(): void {
|
|
41
41
|
const { gl } = this;
|
|
42
42
|
gl.clearColor(0, 0, 0, 0);
|
|
43
43
|
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
@@ -48,7 +48,7 @@ export class FilterTexture {
|
|
|
48
48
|
* @param {number} width - The new width of the filter texture.
|
|
49
49
|
* @param {number} height - The new height of the filter texture.
|
|
50
50
|
*/
|
|
51
|
-
public resize(width: number, height: number) {
|
|
51
|
+
public resize(width: number, height: number): void {
|
|
52
52
|
if (this.width === width && this.height === height) {
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
@@ -65,7 +65,7 @@ export class FilterTexture {
|
|
|
65
65
|
/**
|
|
66
66
|
* Updates the resolution of this filter texture.
|
|
67
67
|
*/
|
|
68
|
-
public destroy() {
|
|
68
|
+
public destroy(): void {
|
|
69
69
|
const { gl } = this;
|
|
70
70
|
gl.deleteFramebuffer(this.frameBuffer);
|
|
71
71
|
gl.deleteTexture(this.texture);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { GraphicsData as DisplayGraphicsData } from '../graphics_data.js';
|
|
2
|
+
import type { GraphicsWebGLBucket } from '../graphics.js';
|
|
1
3
|
import { Point } from '../../geom/point.js';
|
|
2
4
|
import { hex2rgb } from '../../util/math.js';
|
|
3
5
|
import { triangulate } from './earcut.js';
|
|
@@ -15,7 +17,7 @@ import { RoundedRectangle } from '../../geom/rounded_rectangle.js';
|
|
|
15
17
|
* Updates the graphics data for WebGL rendering.
|
|
16
18
|
* @returns {number} The number of vertices in the graphics data.
|
|
17
19
|
*/
|
|
18
|
-
export const getStencilBufferLimit = () => {
|
|
20
|
+
export const getStencilBufferLimit = (): number => {
|
|
19
21
|
globalThis.PhaserRegistry.stencilBufferLimit ??= 6;
|
|
20
22
|
return globalThis.PhaserRegistry.stencilBufferLimit;
|
|
21
23
|
};
|
|
@@ -35,14 +37,14 @@ export const getGraphicsDataPool = () => {
|
|
|
35
37
|
* @param {number} type - The type of graphics data to create.
|
|
36
38
|
* @returns {object} The newly created graphics data object.
|
|
37
39
|
*/
|
|
38
|
-
export const switchMode = (webGL:
|
|
40
|
+
export const switchMode = (webGL: GraphicsWebGLBucket, type: number) => {
|
|
39
41
|
let webGLData;
|
|
40
42
|
if (webGL.data.length === 0) {
|
|
41
43
|
webGLData = getGraphicsDataPool().pop() ?? new GraphicsData(webGL.gl);
|
|
42
44
|
webGLData.mode = type;
|
|
43
45
|
webGL.data.push(webGLData);
|
|
44
46
|
} else {
|
|
45
|
-
webGLData = webGL.data.at(-1)
|
|
47
|
+
webGLData = webGL.data.at(-1)!;
|
|
46
48
|
if (webGLData.mode !== type || type === 1) {
|
|
47
49
|
webGLData = getGraphicsDataPool().pop() ?? new GraphicsData(webGL.gl);
|
|
48
50
|
webGLData.mode = type;
|
|
@@ -58,7 +60,7 @@ export const switchMode = (webGL: any, type: number) => {
|
|
|
58
60
|
* @param {object} graphicsData - The graphics data to update.
|
|
59
61
|
* @param {GraphicsData} webGLData - The WebGL graphics data object.
|
|
60
62
|
*/
|
|
61
|
-
export const buildLine = (graphicsData:
|
|
63
|
+
export const buildLine = (graphicsData: DisplayGraphicsData, webGLData: GraphicsData): void => {
|
|
62
64
|
// TODO OPTIMISE!
|
|
63
65
|
let i = 0;
|
|
64
66
|
let { points } = graphicsData;
|
|
@@ -68,7 +70,7 @@ export const buildLine = (graphicsData: any, webGLData: GraphicsData) => {
|
|
|
68
70
|
// if the line width is an odd number add 0.5 to align to a whole pixel
|
|
69
71
|
if (graphicsData.lineWidth % 2) {
|
|
70
72
|
for (i = 0; i < points.length; i += 1) {
|
|
71
|
-
points[i] += 0.5;
|
|
73
|
+
points[i]! += 0.5;
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
// get first and last point.. figure out the middle!
|
|
@@ -122,10 +124,10 @@ export const buildLine = (graphicsData: any, webGLData: GraphicsData) => {
|
|
|
122
124
|
let denom;
|
|
123
125
|
let pdist;
|
|
124
126
|
let dist;
|
|
125
|
-
p1x = points[0]
|
|
126
|
-
p1y = points[1]
|
|
127
|
-
p2x = points[2]
|
|
128
|
-
p2y = points[3]
|
|
127
|
+
p1x = points[0]!;
|
|
128
|
+
p1y = points[1]!;
|
|
129
|
+
p2x = points[2]!;
|
|
130
|
+
p2y = points[3]!;
|
|
129
131
|
perpx = -(p1y - p2y);
|
|
130
132
|
perpy = p1x - p2x;
|
|
131
133
|
dist = Math.sqrt(perpx * perpx + perpy * perpy);
|
|
@@ -137,12 +139,12 @@ export const buildLine = (graphicsData: any, webGLData: GraphicsData) => {
|
|
|
137
139
|
verts.push(p1x - perpx, p1y - perpy, r, g, b, alpha);
|
|
138
140
|
verts.push(p1x + perpx, p1y + perpy, r, g, b, alpha);
|
|
139
141
|
for (i = 1; i < length - 1; i += 1) {
|
|
140
|
-
p1x = points[(i - 1) * 2]
|
|
141
|
-
p1y = points[(i - 1) * 2 + 1]
|
|
142
|
-
p2x = points[i * 2]
|
|
143
|
-
p2y = points[i * 2 + 1]
|
|
144
|
-
p3x = points[(i + 1) * 2]
|
|
145
|
-
p3y = points[(i + 1) * 2 + 1]
|
|
142
|
+
p1x = points[(i - 1) * 2]!;
|
|
143
|
+
p1y = points[(i - 1) * 2 + 1]!;
|
|
144
|
+
p2x = points[i * 2]!;
|
|
145
|
+
p2y = points[i * 2 + 1]!;
|
|
146
|
+
p3x = points[(i + 1) * 2]!;
|
|
147
|
+
p3y = points[(i + 1) * 2 + 1]!;
|
|
146
148
|
perpx = -(p1y - p2y);
|
|
147
149
|
perpy = p1x - p2x;
|
|
148
150
|
dist = Math.sqrt(perpx * perpx + perpy * perpy);
|
|
@@ -195,10 +197,10 @@ export const buildLine = (graphicsData: any, webGLData: GraphicsData) => {
|
|
|
195
197
|
verts.push(r, g, b, alpha);
|
|
196
198
|
}
|
|
197
199
|
}
|
|
198
|
-
p1x = points[(length - 2) * 2]
|
|
199
|
-
p1y = points[(length - 2) * 2 + 1]
|
|
200
|
-
p2x = points[(length - 1) * 2]
|
|
201
|
-
p2y = points[(length - 1) * 2 + 1]
|
|
200
|
+
p1x = points[(length - 2) * 2]!;
|
|
201
|
+
p1y = points[(length - 2) * 2 + 1]!;
|
|
202
|
+
p2x = points[(length - 1) * 2]!;
|
|
203
|
+
p2y = points[(length - 1) * 2 + 1]!;
|
|
202
204
|
perpx = -(p1y - p2y);
|
|
203
205
|
perpy = p1x - p2x;
|
|
204
206
|
dist = Math.sqrt(perpx * perpx + perpy * perpy);
|
|
@@ -223,18 +225,18 @@ export const buildLine = (graphicsData: any, webGLData: GraphicsData) => {
|
|
|
223
225
|
* @param {object} graphicsData - The graphics data to update.
|
|
224
226
|
* @param {GraphicsData} webGLData - The WebGL graphics data object.
|
|
225
227
|
*/
|
|
226
|
-
export const buildRectangle = (graphicsData:
|
|
228
|
+
export const buildRectangle = (graphicsData: DisplayGraphicsData, webGLData: GraphicsData): void => {
|
|
227
229
|
//
|
|
228
230
|
// need to convert points to a nice regular data
|
|
229
231
|
//
|
|
230
|
-
const rectData = graphicsData.shape;
|
|
232
|
+
const rectData = graphicsData.shape as Rectangle;
|
|
231
233
|
const { x } = rectData;
|
|
232
234
|
const { y } = rectData;
|
|
233
235
|
const { width } = rectData;
|
|
234
236
|
const { height } = rectData;
|
|
235
237
|
|
|
236
238
|
if (graphicsData.fill) {
|
|
237
|
-
const color = hex2rgb(graphicsData.fillColor);
|
|
239
|
+
const color = hex2rgb(graphicsData.fillColor ?? 0);
|
|
238
240
|
const alpha = graphicsData.fillAlpha;
|
|
239
241
|
const r = color[0] * alpha;
|
|
240
242
|
const g = color[1] * alpha;
|
|
@@ -279,7 +281,7 @@ export const quadraticBezierCurve = (
|
|
|
279
281
|
cpY: number,
|
|
280
282
|
toX: number,
|
|
281
283
|
toY: number
|
|
282
|
-
) => {
|
|
284
|
+
): number[] => {
|
|
283
285
|
let xa;
|
|
284
286
|
let ya;
|
|
285
287
|
let xb;
|
|
@@ -288,7 +290,7 @@ export const quadraticBezierCurve = (
|
|
|
288
290
|
let y;
|
|
289
291
|
const n = 20;
|
|
290
292
|
const points = [];
|
|
291
|
-
const getPt = (n1: number, n2: number, perc: number) => {
|
|
293
|
+
const getPt = (n1: number, n2: number, perc: number): number => {
|
|
292
294
|
const diff = n2 - n1;
|
|
293
295
|
return n1 + diff * perc;
|
|
294
296
|
};
|
|
@@ -313,8 +315,8 @@ export const quadraticBezierCurve = (
|
|
|
313
315
|
* @param {object} graphicsData - The graphics data to update.
|
|
314
316
|
* @param {GraphicsData} webGLData - The WebGL graphics data object.
|
|
315
317
|
*/
|
|
316
|
-
export const buildRoundedRectangle = (graphicsData:
|
|
317
|
-
const rrectData = graphicsData.shape;
|
|
318
|
+
export const buildRoundedRectangle = (graphicsData: DisplayGraphicsData, webGLData: GraphicsData): void => {
|
|
319
|
+
const rrectData = graphicsData.shape as RoundedRectangle;
|
|
318
320
|
const { x } = rrectData;
|
|
319
321
|
const { y } = rrectData;
|
|
320
322
|
const { width } = rrectData;
|
|
@@ -329,7 +331,7 @@ export const buildRoundedRectangle = (graphicsData: any, webGLData: GraphicsData
|
|
|
329
331
|
recPoints = recPoints.concat(quadraticBezierCurve(x + width, y + radius, x + width, y, x + width - radius, y));
|
|
330
332
|
recPoints = recPoints.concat(quadraticBezierCurve(x + radius, y, x, y, x, y + radius));
|
|
331
333
|
if (graphicsData.fill) {
|
|
332
|
-
const color = hex2rgb(graphicsData.fillColor);
|
|
334
|
+
const color = hex2rgb(graphicsData.fillColor ?? 0);
|
|
333
335
|
const alpha = graphicsData.fillAlpha;
|
|
334
336
|
const r = color[0] * alpha;
|
|
335
337
|
const g = color[1] * alpha;
|
|
@@ -347,7 +349,7 @@ export const buildRoundedRectangle = (graphicsData: any, webGLData: GraphicsData
|
|
|
347
349
|
}
|
|
348
350
|
for (let i = 0; i < recPoints.length; i += 2) {
|
|
349
351
|
// TODO verify
|
|
350
|
-
verts.push(recPoints[i]
|
|
352
|
+
verts.push(recPoints[i]!, recPoints[i + 1]!, r, g, b, alpha);
|
|
351
353
|
}
|
|
352
354
|
}
|
|
353
355
|
if (graphicsData.lineWidth) {
|
|
@@ -363,15 +365,15 @@ export const buildRoundedRectangle = (graphicsData: any, webGLData: GraphicsData
|
|
|
363
365
|
* @param {object} graphicsData - The graphics data to update.
|
|
364
366
|
* @param {GraphicsData} webGLData - The WebGL graphics data object.
|
|
365
367
|
*/
|
|
366
|
-
export const buildCircle = (graphicsData:
|
|
368
|
+
export const buildCircle = (graphicsData: DisplayGraphicsData, webGLData: GraphicsData): void => {
|
|
367
369
|
// need to convert points to a nice regular data
|
|
368
|
-
const circleData = graphicsData.shape;
|
|
370
|
+
const circleData = graphicsData.shape as Circle | Ellipse;
|
|
369
371
|
const { x } = circleData;
|
|
370
372
|
const { y } = circleData;
|
|
371
373
|
let width;
|
|
372
374
|
let height;
|
|
373
375
|
// TODO - bit hacky??
|
|
374
|
-
if (
|
|
376
|
+
if (circleData instanceof Circle) {
|
|
375
377
|
width = circleData.radius;
|
|
376
378
|
height = circleData.radius;
|
|
377
379
|
} else {
|
|
@@ -381,7 +383,7 @@ export const buildCircle = (graphicsData: any, webGLData: GraphicsData) => {
|
|
|
381
383
|
const totalSegs = 40;
|
|
382
384
|
const seg = (Math.PI * 2) / totalSegs;
|
|
383
385
|
if (graphicsData.fill) {
|
|
384
|
-
const color = hex2rgb(graphicsData.fillColor);
|
|
386
|
+
const color = hex2rgb(graphicsData.fillColor ?? 0);
|
|
385
387
|
const alpha = graphicsData.fillAlpha;
|
|
386
388
|
const r = color[0] * alpha;
|
|
387
389
|
const g = color[1] * alpha;
|
|
@@ -414,7 +416,7 @@ export const buildCircle = (graphicsData: any, webGLData: GraphicsData) => {
|
|
|
414
416
|
* @param {object} graphicsData - The graphics data to update.
|
|
415
417
|
* @param {GraphicsData} webGLData - The WebGL graphics data object.
|
|
416
418
|
*/
|
|
417
|
-
export const buildComplexPoly = (graphicsData:
|
|
419
|
+
export const buildComplexPoly = (graphicsData: DisplayGraphicsData, webGLData: GraphicsData): void => {
|
|
418
420
|
// TODO - no need to copy this as it gets turned into a Float32Array anyways..
|
|
419
421
|
const points = [...graphicsData.points];
|
|
420
422
|
if (points.length < 6) {
|
|
@@ -424,7 +426,7 @@ export const buildComplexPoly = (graphicsData: any, webGLData: GraphicsData) =>
|
|
|
424
426
|
const { indices } = webGLData;
|
|
425
427
|
webGLData.points = points;
|
|
426
428
|
webGLData.alpha = graphicsData.fillAlpha;
|
|
427
|
-
webGLData.color = hex2rgb(graphicsData.fillColor);
|
|
429
|
+
webGLData.color = hex2rgb(graphicsData.fillColor ?? 0);
|
|
428
430
|
/*
|
|
429
431
|
calculate the bounds..
|
|
430
432
|
*/
|
|
@@ -436,8 +438,8 @@ export const buildComplexPoly = (graphicsData: any, webGLData: GraphicsData) =>
|
|
|
436
438
|
let y;
|
|
437
439
|
// get size..
|
|
438
440
|
for (let i = 0; i < points.length; i += 2) {
|
|
439
|
-
x = points[i]
|
|
440
|
-
y = points[i + 1]
|
|
441
|
+
x = points[i]!;
|
|
442
|
+
y = points[i + 1]!;
|
|
441
443
|
minX = x < minX ? x : minX;
|
|
442
444
|
maxX = x > maxX ? x : maxX;
|
|
443
445
|
minY = y < minY ? y : minY;
|
|
@@ -459,7 +461,7 @@ export const buildComplexPoly = (graphicsData: any, webGLData: GraphicsData) =>
|
|
|
459
461
|
* @param {GraphicsData} webGLData - TBD.
|
|
460
462
|
* @returns {boolean} TBD.
|
|
461
463
|
*/
|
|
462
|
-
export const buildPoly = (graphicsData:
|
|
464
|
+
export const buildPoly = (graphicsData: DisplayGraphicsData, webGLData: GraphicsData): boolean => {
|
|
463
465
|
const { points } = graphicsData;
|
|
464
466
|
if (points.length < 6) {
|
|
465
467
|
return false;
|
|
@@ -469,7 +471,7 @@ export const buildPoly = (graphicsData: any, webGLData: GraphicsData) => {
|
|
|
469
471
|
const { indices } = webGLData;
|
|
470
472
|
const length = points.length / 2;
|
|
471
473
|
// sort color
|
|
472
|
-
const color = hex2rgb(graphicsData.fillColor);
|
|
474
|
+
const color = hex2rgb(graphicsData.fillColor ?? 0);
|
|
473
475
|
const alpha = graphicsData.fillAlpha;
|
|
474
476
|
const r = color[0] * alpha;
|
|
475
477
|
const g = color[1] * alpha;
|
|
@@ -487,7 +489,7 @@ export const buildPoly = (graphicsData: any, webGLData: GraphicsData) => {
|
|
|
487
489
|
indices.push(triangles[i + 2]! + vertPos);
|
|
488
490
|
}
|
|
489
491
|
for (let i = 0; i < length; i += 1) {
|
|
490
|
-
verts.push(points[i * 2]
|
|
492
|
+
verts.push(points[i * 2]!, points[i * 2 + 1]!, r, g, b, alpha);
|
|
491
493
|
}
|
|
492
494
|
return true;
|
|
493
495
|
};
|
|
@@ -497,7 +499,7 @@ export const buildPoly = (graphicsData: any, webGLData: GraphicsData) => {
|
|
|
497
499
|
* @param {Graphics} graphics - The graphics object to update.
|
|
498
500
|
* @param {WebGLRenderingContext & { id: number }} gl - The WebGL rendering context.
|
|
499
501
|
*/
|
|
500
|
-
export const updateGraphics = (graphics: Graphics, gl: IdentifiedWebGLRenderingContext) => {
|
|
502
|
+
export const updateGraphics = (graphics: Graphics, gl: IdentifiedWebGLRenderingContext): void => {
|
|
501
503
|
const stencilBufferLimit = getStencilBufferLimit();
|
|
502
504
|
// get the contexts graphics object
|
|
503
505
|
let webGL = graphics._webGL[gl.id];
|
|
@@ -582,7 +584,7 @@ export const updateGraphics = (graphics: Graphics, gl: IdentifiedWebGLRenderingC
|
|
|
582
584
|
* @param {Graphics} graphics - The graphics object to update.
|
|
583
585
|
* @param {object} renderSession - The rendering session.
|
|
584
586
|
*/
|
|
585
|
-
export const renderGraphics = (graphics: Graphics, renderSession: RenderSession) => {
|
|
587
|
+
export const renderGraphics = (graphics: Graphics, renderSession: RenderSession): void => {
|
|
586
588
|
const { gl } = renderSession;
|
|
587
589
|
const { projection } = renderSession;
|
|
588
590
|
const { offset } = renderSession;
|
|
@@ -30,7 +30,7 @@ export class GraphicsData {
|
|
|
30
30
|
/**
|
|
31
31
|
* Destroys this graphics data and cleans up resources.
|
|
32
32
|
*/
|
|
33
|
-
public reset() {
|
|
33
|
+
public reset(): void {
|
|
34
34
|
this.points = [];
|
|
35
35
|
this.indices = [];
|
|
36
36
|
this.glPoints = null;
|
|
@@ -40,7 +40,7 @@ export class GraphicsData {
|
|
|
40
40
|
/**
|
|
41
41
|
* Updates the graphics data for WebGL rendering.
|
|
42
42
|
*/
|
|
43
|
-
public upload() {
|
|
43
|
+
public upload(): void {
|
|
44
44
|
const { gl } = this;
|
|
45
45
|
// this.lastIndex = graphics.graphicsData.length;
|
|
46
46
|
this.glPoints = new Float32Array(this.points);
|
|
@@ -6,7 +6,7 @@ import type { RenderSession } from '../render_session.js';
|
|
|
6
6
|
* @param {object} maskData - The mask data to apply.
|
|
7
7
|
* @param {object} renderSession - The rendering session.
|
|
8
8
|
*/
|
|
9
|
-
export const pushMask = (maskData: any, renderSession: RenderSession) => {
|
|
9
|
+
export const pushMask = (maskData: any, renderSession: RenderSession): void => {
|
|
10
10
|
const { gl } = renderSession;
|
|
11
11
|
if (maskData.dirty) {
|
|
12
12
|
updateGraphics(maskData, gl);
|
|
@@ -26,7 +26,7 @@ export const pushMask = (maskData: any, renderSession: RenderSession) => {
|
|
|
26
26
|
* @param {object} maskData - The mask data to apply.
|
|
27
27
|
* @param {object} renderSession - The rendering session.
|
|
28
28
|
*/
|
|
29
|
-
export const popMask = (maskData: any, renderSession: RenderSession) => {
|
|
29
|
+
export const popMask = (maskData: any, renderSession: RenderSession): void => {
|
|
30
30
|
const { gl } = renderSession;
|
|
31
31
|
if (
|
|
32
32
|
maskData._webGL[gl.id] === undefined ||
|
|
@@ -71,28 +71,28 @@ export class RenderTexture extends Texture {
|
|
|
71
71
|
/**
|
|
72
72
|
* Destroys this render texture and cleans up resources.
|
|
73
73
|
*/
|
|
74
|
-
public resize() {
|
|
74
|
+
public resize(): void {
|
|
75
75
|
// TODO
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
79
|
* Updates the size of this render texture.
|
|
80
80
|
*/
|
|
81
|
-
public clear() {
|
|
81
|
+
public clear(): void {
|
|
82
82
|
// TODO
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
86
|
* Updates the resolution of this render texture.
|
|
87
87
|
*/
|
|
88
|
-
public renderWebGL() {
|
|
88
|
+
public renderWebGL(): void {
|
|
89
89
|
// TODO
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
/**
|
|
93
93
|
* Updates the scale mode of this render texture.
|
|
94
94
|
*/
|
|
95
|
-
public renderCanvas() {
|
|
95
|
+
public renderCanvas(): void {
|
|
96
96
|
// TODO
|
|
97
97
|
}
|
|
98
98
|
|
|
@@ -100,7 +100,7 @@ export class RenderTexture extends Texture {
|
|
|
100
100
|
* Gets the HTML image element for this render texture.
|
|
101
101
|
* @returns {HTMLImageElement} The HTML image element.
|
|
102
102
|
*/
|
|
103
|
-
public getImage() {
|
|
103
|
+
public getImage(): HTMLImageElement {
|
|
104
104
|
const image = new Image();
|
|
105
105
|
image.src = this.getBase64();
|
|
106
106
|
return image;
|
|
@@ -110,7 +110,7 @@ export class RenderTexture extends Texture {
|
|
|
110
110
|
* Gets the base64 string representation of this render texture.
|
|
111
111
|
* @returns {string} The base64 string representation.
|
|
112
112
|
*/
|
|
113
|
-
public getBase64() {
|
|
113
|
+
public getBase64(): string {
|
|
114
114
|
return this.getCanvas()?.toDataURL() ?? '';
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -39,19 +39,19 @@ import type { RenderSession } from '../render_session.js';
|
|
|
39
39
|
export class WebGLRenderer {
|
|
40
40
|
public gl!: IdentifiedWebGLRenderingContext;
|
|
41
41
|
public glContextId!: number;
|
|
42
|
-
public type!:
|
|
42
|
+
public type!: number;
|
|
43
43
|
public resolution!: number;
|
|
44
|
-
public autoResize!:
|
|
45
|
-
public contextLost!:
|
|
46
|
-
public clearBeforeRender!:
|
|
44
|
+
public autoResize!: boolean;
|
|
45
|
+
public contextLost!: boolean;
|
|
46
|
+
public clearBeforeRender!: boolean;
|
|
47
47
|
public width!: number;
|
|
48
48
|
public height!: number;
|
|
49
|
-
public view!:
|
|
50
|
-
public _contextOptions!:
|
|
51
|
-
public projection!:
|
|
52
|
-
public offset!:
|
|
53
|
-
public shaderManager!:
|
|
54
|
-
public spriteBatch!:
|
|
49
|
+
public view!: HTMLCanvasElement;
|
|
50
|
+
public _contextOptions!: WebGLContextAttributes;
|
|
51
|
+
public projection!: Point;
|
|
52
|
+
public offset!: Point;
|
|
53
|
+
public shaderManager!: WebGLShaderManager;
|
|
54
|
+
public spriteBatch!: WebGLSpriteBatch;
|
|
55
55
|
public filterManager!: any;
|
|
56
56
|
public stencilManager!: any;
|
|
57
57
|
public blendModeManager!: any;
|
|
@@ -105,16 +105,11 @@ export class WebGLRenderer {
|
|
|
105
105
|
/**
|
|
106
106
|
* Destroys this renderer and cleans up resources.
|
|
107
107
|
*/
|
|
108
|
-
public destroy() {
|
|
108
|
+
public destroy(): void {
|
|
109
109
|
globalThis.PhaserRegistry.GL_CONTEXTS[this.glContextId] = null;
|
|
110
|
-
this.projection = null;
|
|
111
|
-
this.offset = null;
|
|
112
110
|
this.shaderManager.destroy();
|
|
113
111
|
this.spriteBatch.destroy();
|
|
114
112
|
this.filterManager.destroy();
|
|
115
|
-
this.shaderManager = null;
|
|
116
|
-
this.spriteBatch = null;
|
|
117
|
-
this.filterManager = null;
|
|
118
113
|
if (this.gl) {
|
|
119
114
|
this.gl.canvas.width = 1;
|
|
120
115
|
this.gl.canvas.height = 1;
|
|
@@ -131,7 +126,7 @@ export class WebGLRenderer {
|
|
|
131
126
|
/**
|
|
132
127
|
* Initializes the WebGL registry.
|
|
133
128
|
*/
|
|
134
|
-
public initRegistry() {
|
|
129
|
+
public initRegistry(): void {
|
|
135
130
|
globalThis.PhaserRegistry.GL_CONTEXT_ID ??= 0;
|
|
136
131
|
globalThis.PhaserRegistry.GL_CONTEXTS ??= [];
|
|
137
132
|
globalThis.PhaserRegistry.INSTANCES ??= [];
|
|
@@ -142,7 +137,7 @@ export class WebGLRenderer {
|
|
|
142
137
|
* @param {Game} game - The game instance.
|
|
143
138
|
* @throws {Error}
|
|
144
139
|
*/
|
|
145
|
-
public initContext(game: Game) {
|
|
140
|
+
public initContext(game: Game): void {
|
|
146
141
|
game.logger.info('initContext');
|
|
147
142
|
// TODO: view.addEventListener('webglcontextcreationerror', this.onWebGLContextCreationError, false);
|
|
148
143
|
/** @type {WebGLRenderingContext & { id: number }} */
|
|
@@ -185,7 +180,7 @@ export class WebGLRenderer {
|
|
|
185
180
|
* Renders the stage to WebGL.
|
|
186
181
|
* @param {Stage} stage - The root stage to render.
|
|
187
182
|
*/
|
|
188
|
-
public render(stage: Stage) {
|
|
183
|
+
public render(stage: Stage): void {
|
|
189
184
|
if (this.contextLost) {
|
|
190
185
|
return;
|
|
191
186
|
}
|
|
@@ -210,7 +205,7 @@ export class WebGLRenderer {
|
|
|
210
205
|
* @param {object} buffer - The render buffer.
|
|
211
206
|
* @param {Matrix} matrix - The transformation matrix.
|
|
212
207
|
*/
|
|
213
|
-
public renderDisplayObject(displayObject: any, projection: Point, buffer?: any, matrix?: any) {
|
|
208
|
+
public renderDisplayObject(displayObject: any, projection: Point, buffer?: any, matrix?: any): void {
|
|
214
209
|
this.renderSession.blendModeManager.setBlendMode(BLEND_NORMAL);
|
|
215
210
|
// reset the render session data..
|
|
216
211
|
this.renderSession.drawCount = 0;
|
|
@@ -235,7 +230,7 @@ export class WebGLRenderer {
|
|
|
235
230
|
* @param {number} width - The new width of the canvas.
|
|
236
231
|
* @param {number} height - The new height of the canvas.
|
|
237
232
|
*/
|
|
238
|
-
public resize(width: number, height: number) {
|
|
233
|
+
public resize(width: number, height: number): void {
|
|
239
234
|
this.width = width * this.resolution;
|
|
240
235
|
this.height = height * this.resolution;
|
|
241
236
|
this.view.width = this.width;
|
|
@@ -254,15 +249,15 @@ export class WebGLRenderer {
|
|
|
254
249
|
* @param {BaseTexture} texture - The base texture to update.
|
|
255
250
|
* @returns {boolean} Whether the update was successful.
|
|
256
251
|
*/
|
|
257
|
-
public updateTexture(texture: BaseTexture) {
|
|
252
|
+
public updateTexture(texture: BaseTexture): boolean {
|
|
258
253
|
if (!texture.hasLoaded) {
|
|
259
254
|
return false;
|
|
260
255
|
}
|
|
261
256
|
const { gl } = this;
|
|
262
257
|
texture._glTextures[gl.id] ??= gl.createTexture();
|
|
263
|
-
gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]);
|
|
258
|
+
gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id] ?? null);
|
|
264
259
|
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultipliedAlpha);
|
|
265
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source);
|
|
260
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source!);
|
|
266
261
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, texture.scaleMode === SCALE_LINEAR ? gl.LINEAR : gl.NEAREST);
|
|
267
262
|
if (texture.mipmap && isPowerOfTwo(texture.width, texture.height)) {
|
|
268
263
|
gl.texParameteri(
|
|
@@ -293,7 +288,7 @@ export class WebGLRenderer {
|
|
|
293
288
|
/**
|
|
294
289
|
* Maps blend modes to WebGL rendering operations.
|
|
295
290
|
*/
|
|
296
|
-
public mapBlendModes() {
|
|
291
|
+
public mapBlendModes(): void {
|
|
297
292
|
if (globalThis.PhaserRegistry.blendModesWebGL) {
|
|
298
293
|
return;
|
|
299
294
|
}
|