@vpmedia/phaser 1.114.0 → 1.115.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 +400 -377
- package/dist/index.js.map +1 -1
- package/dist/phaser/core/animation_manager.d.ts +2 -1
- package/dist/phaser/core/animation_manager.d.ts.map +1 -1
- package/dist/phaser/core/array_set.d.ts +1 -1
- package/dist/phaser/core/array_set.d.ts.map +1 -1
- package/dist/phaser/core/cache.d.ts +1 -1
- package/dist/phaser/core/cache.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/game.d.ts +2 -0
- package/dist/phaser/core/game.d.ts.map +1 -1
- package/dist/phaser/core/input.d.ts +5 -5
- package/dist/phaser/core/input.d.ts.map +1 -1
- package/dist/phaser/core/input_event.d.ts +35 -0
- package/dist/phaser/core/input_event.d.ts.map +1 -0
- package/dist/phaser/core/input_handler.d.ts +2 -2
- package/dist/phaser/core/input_handler.d.ts.map +1 -1
- package/dist/phaser/core/input_mouse.d.ts +27 -26
- package/dist/phaser/core/input_mouse.d.ts.map +1 -1
- package/dist/phaser/core/input_mspointer.d.ts +16 -15
- package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
- package/dist/phaser/core/input_pointer.d.ts +9 -8
- package/dist/phaser/core/input_pointer.d.ts.map +1 -1
- package/dist/phaser/core/input_touch.d.ts +18 -17
- package/dist/phaser/core/input_touch.d.ts.map +1 -1
- package/dist/phaser/core/loader.d.ts +64 -30
- package/dist/phaser/core/loader.d.ts.map +1 -1
- 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_manager.d.ts +14 -4
- package/dist/phaser/core/scene_manager.d.ts.map +1 -1
- package/dist/phaser/core/signal.d.ts +8 -8
- package/dist/phaser/core/signal.d.ts.map +1 -1
- package/dist/phaser/core/signal_binding.d.ts +2 -2
- package/dist/phaser/core/signal_binding.d.ts.map +1 -1
- package/dist/phaser/core/sound.d.ts +1 -1
- package/dist/phaser/core/sound.d.ts.map +1 -1
- package/dist/phaser/core/sound_manager.d.ts +3 -3
- package/dist/phaser/core/sound_manager.d.ts.map +1 -1
- package/dist/phaser/core/sound_sprite.d.ts +1 -1
- package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
- package/dist/phaser/core/timer.d.ts +5 -5
- package/dist/phaser/core/timer.d.ts.map +1 -1
- package/dist/phaser/core/timer_event.d.ts +2 -2
- package/dist/phaser/core/timer_event.d.ts.map +1 -1
- package/dist/phaser/core/tween.d.ts +4 -4
- package/dist/phaser/core/tween.d.ts.map +1 -1
- package/dist/phaser/core/tween_data.d.ts +2 -1
- package/dist/phaser/core/tween_data.d.ts.map +1 -1
- package/dist/phaser/core/tween_manager.d.ts +1 -1
- package/dist/phaser/core/tween_manager.d.ts.map +1 -1
- package/dist/phaser/display/button.d.ts +1 -1
- package/dist/phaser/display/button.d.ts.map +1 -1
- package/dist/phaser/display/canvas/buffer.d.ts +3 -3
- package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/graphics.d.ts +2 -2
- package/dist/phaser/display/canvas/graphics.d.ts.map +1 -1
- package/dist/phaser/display/canvas/masker.d.ts +5 -2
- package/dist/phaser/display/canvas/masker.d.ts.map +1 -1
- package/dist/phaser/display/canvas/renderer.d.ts +6 -5
- package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/tinter.d.ts +2 -1
- package/dist/phaser/display/canvas/tinter.d.ts.map +1 -1
- package/dist/phaser/display/canvas/util.d.ts +11 -4
- package/dist/phaser/display/canvas/util.d.ts.map +1 -1
- package/dist/phaser/display/display_object.d.ts +4 -3
- package/dist/phaser/display/display_object.d.ts.map +1 -1
- package/dist/phaser/display/graphics.d.ts +47 -27
- package/dist/phaser/display/graphics.d.ts.map +1 -1
- package/dist/phaser/display/graphics_data.d.ts +20 -11
- package/dist/phaser/display/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/image.d.ts +4 -3
- package/dist/phaser/display/image.d.ts.map +1 -1
- package/dist/phaser/display/render_session.d.ts +44 -0
- package/dist/phaser/display/render_session.d.ts.map +1 -0
- package/dist/phaser/display/sprite_util.d.ts +4 -3
- package/dist/phaser/display/sprite_util.d.ts.map +1 -1
- package/dist/phaser/display/text.d.ts +64 -30
- package/dist/phaser/display/text.d.ts.map +1 -1
- package/dist/phaser/display/webgl/base_texture.d.ts +3 -3
- package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts +25 -25
- package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut_node.d.ts +2 -2
- package/dist/phaser/display/webgl/earcut_node.d.ts.map +1 -1
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +3 -2
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts +1 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics.d.ts +2 -1
- package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics_data.d.ts +9 -9
- package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/webgl/mask_manager.d.ts +3 -2
- package/dist/phaser/display/webgl/mask_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/render_texture.d.ts +3 -3
- package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/renderer.d.ts +5 -4
- package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/normal.d.ts +3 -1
- package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader_manager.d.ts +10 -4
- package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/sprite_batch.d.ts +4 -3
- package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/stencil_manager.d.ts +4 -3
- package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture.d.ts +6 -6
- package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/phaser/core/animation_manager.ts +2 -2
- package/src/phaser/core/array_set.ts +1 -1
- package/src/phaser/core/cache.ts +1 -1
- package/src/phaser/core/factory.ts +1 -1
- package/src/phaser/core/game.ts +2 -0
- package/src/phaser/core/input.ts +7 -6
- package/src/phaser/core/input_event.ts +34 -0
- package/src/phaser/core/input_handler.ts +2 -11
- package/src/phaser/core/input_mouse.ts +53 -36
- package/src/phaser/core/input_mspointer.ts +54 -29
- package/src/phaser/core/input_pointer.test.ts +149 -0
- package/src/phaser/core/input_pointer.ts +20 -21
- package/src/phaser/core/input_touch.ts +48 -31
- package/src/phaser/core/loader.test.ts +139 -0
- package/src/phaser/core/loader.ts +146 -83
- package/src/phaser/core/scale_manager.ts +1 -1
- package/src/phaser/core/scene_manager.ts +16 -8
- package/src/phaser/core/signal.ts +8 -8
- package/src/phaser/core/signal_binding.ts +2 -2
- package/src/phaser/core/sound.ts +4 -4
- package/src/phaser/core/sound_manager.ts +17 -19
- package/src/phaser/core/sound_sprite.ts +2 -2
- package/src/phaser/core/timer.ts +6 -6
- package/src/phaser/core/timer_event.ts +2 -2
- package/src/phaser/core/tween.ts +6 -6
- package/src/phaser/core/tween_data.ts +2 -1
- package/src/phaser/core/tween_manager.ts +1 -1
- package/src/phaser/display/button.ts +1 -1
- package/src/phaser/display/canvas/buffer.ts +3 -3
- package/src/phaser/display/canvas/graphics.ts +24 -20
- package/src/phaser/display/canvas/masker.ts +5 -2
- package/src/phaser/display/canvas/renderer.ts +10 -11
- package/src/phaser/display/canvas/tinter.ts +4 -3
- package/src/phaser/display/canvas/util.ts +15 -5
- package/src/phaser/display/display_object.ts +6 -5
- package/src/phaser/display/graphics.test.ts +122 -0
- package/src/phaser/display/graphics.ts +73 -64
- package/src/phaser/display/graphics_data.ts +22 -12
- package/src/phaser/display/image.ts +4 -3
- package/src/phaser/display/render_session.ts +45 -0
- package/src/phaser/display/sprite_util.ts +10 -8
- package/src/phaser/display/text.test.ts +27 -1
- package/src/phaser/display/text.ts +181 -117
- package/src/phaser/display/webgl/base_texture.ts +3 -3
- package/src/phaser/display/webgl/earcut.test.ts +132 -0
- package/src/phaser/display/webgl/earcut.ts +84 -74
- package/src/phaser/display/webgl/earcut_node.ts +5 -5
- package/src/phaser/display/webgl/fast_sprite_batch.ts +4 -4
- package/src/phaser/display/webgl/filter_manager.ts +1 -1
- package/src/phaser/display/webgl/graphics.ts +26 -17
- package/src/phaser/display/webgl/graphics_data.ts +9 -9
- package/src/phaser/display/webgl/mask_manager.ts +3 -2
- package/src/phaser/display/webgl/render_texture.ts +3 -3
- package/src/phaser/display/webgl/renderer.ts +7 -6
- package/src/phaser/display/webgl/shader/normal.ts +23 -6
- package/src/phaser/display/webgl/shader_manager.ts +15 -6
- package/src/phaser/display/webgl/sprite_batch.ts +4 -3
- package/src/phaser/display/webgl/stencil_manager.ts +10 -3
- package/src/phaser/display/webgl/texture.ts +6 -6
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { GEOM_CIRCLE, GEOM_ELLIPSE, GEOM_POLYGON, GEOM_RECTANGLE, GEOM_ROUNDED_RECTANGLE } from '../../core/const.js';
|
|
2
1
|
import { Point } from '../../geom/point.js';
|
|
3
2
|
import { hex2rgb } from '../../util/math.js';
|
|
4
3
|
import { triangulate } from './earcut.js';
|
|
5
4
|
import { GraphicsData } from './graphics_data.js';
|
|
6
5
|
import type { IdentifiedWebGLRenderingContext } from './util.js';
|
|
7
6
|
import type { Graphics } from '../graphics.js';
|
|
7
|
+
import type { RenderSession } from '../render_session.js';
|
|
8
|
+
import { Circle } from '../../geom/circle.js';
|
|
9
|
+
import { Ellipse } from '../../geom/ellipse.js';
|
|
10
|
+
import { Polygon } from '../../geom/polygon.js';
|
|
11
|
+
import { Rectangle } from '../../geom/rectangle.js';
|
|
12
|
+
import { RoundedRectangle } from '../../geom/rounded_rectangle.js';
|
|
8
13
|
|
|
9
14
|
/**
|
|
10
15
|
* Updates the graphics data for WebGL rendering.
|
|
@@ -366,7 +371,7 @@ export const buildCircle = (graphicsData: any, webGLData: GraphicsData) => {
|
|
|
366
371
|
let width;
|
|
367
372
|
let height;
|
|
368
373
|
// TODO - bit hacky??
|
|
369
|
-
if (graphicsData.
|
|
374
|
+
if (graphicsData.shape instanceof Circle) {
|
|
370
375
|
width = circleData.radius;
|
|
371
376
|
height = circleData.radius;
|
|
372
377
|
} else {
|
|
@@ -509,7 +514,7 @@ export const updateGraphics = (graphics: Graphics, gl: IdentifiedWebGLRenderingC
|
|
|
509
514
|
graphics.clearDirty = false;
|
|
510
515
|
// lop through and return all the webGLDatas to the object pool so than can be reused later on
|
|
511
516
|
for (i = 0; i < webGL.data.length; i += 1) {
|
|
512
|
-
const graphicsData = webGL.data[i]
|
|
517
|
+
const graphicsData = webGL.data[i]!;
|
|
513
518
|
graphicsData.reset();
|
|
514
519
|
getGraphicsDataPool().push(graphicsData);
|
|
515
520
|
}
|
|
@@ -522,14 +527,14 @@ export const updateGraphics = (graphics: Graphics, gl: IdentifiedWebGLRenderingC
|
|
|
522
527
|
// if the object is a complex fill then the new stencil buffer technique will be used
|
|
523
528
|
// other wise graphics objects will be pushed into a batch..
|
|
524
529
|
for (i = webGL.lastIndex; i < graphics.graphicsData.length; i += 1) {
|
|
525
|
-
const data = graphics.graphicsData[i]
|
|
526
|
-
if (data.
|
|
530
|
+
const data = graphics.graphicsData[i]!;
|
|
531
|
+
if (data.shape instanceof Polygon) {
|
|
527
532
|
// need to add the points the the graphics object..
|
|
528
533
|
data.points = [...data.shape.points];
|
|
529
534
|
if (data.shape.closed) {
|
|
530
535
|
// close the poly if the value is true!
|
|
531
536
|
if (data.points[0] !== data.points.at(-2) || data.points[1] !== data.points.at(-1)) {
|
|
532
|
-
data.points.push(data.points[0]
|
|
537
|
+
data.points.push(data.points[0]!, data.points[1]!);
|
|
533
538
|
}
|
|
534
539
|
}
|
|
535
540
|
// MAKE SURE WE HAVE THE CORRECT TYPE..
|
|
@@ -554,21 +559,20 @@ export const updateGraphics = (graphics: Graphics, gl: IdentifiedWebGLRenderingC
|
|
|
554
559
|
}
|
|
555
560
|
} else {
|
|
556
561
|
webGLData = switchMode(webGL, 0);
|
|
557
|
-
if (data.
|
|
562
|
+
if (data.shape instanceof Rectangle) {
|
|
558
563
|
buildRectangle(data, webGLData);
|
|
559
|
-
} else if (data.
|
|
564
|
+
} else if (data.shape instanceof Circle || data.shape instanceof Ellipse) {
|
|
560
565
|
buildCircle(data, webGLData);
|
|
561
|
-
} else if (data.
|
|
566
|
+
} else if (data.shape instanceof RoundedRectangle) {
|
|
562
567
|
buildRoundedRectangle(data, webGLData);
|
|
563
568
|
}
|
|
564
569
|
}
|
|
565
570
|
webGL.lastIndex += 1;
|
|
566
571
|
}
|
|
567
572
|
// upload all the dirty data...
|
|
568
|
-
for (
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
webGLData.upload();
|
|
573
|
+
for (const uploadable of webGL.data) {
|
|
574
|
+
if (uploadable.dirty) {
|
|
575
|
+
uploadable.upload();
|
|
572
576
|
}
|
|
573
577
|
}
|
|
574
578
|
};
|
|
@@ -578,11 +582,14 @@ export const updateGraphics = (graphics: Graphics, gl: IdentifiedWebGLRenderingC
|
|
|
578
582
|
* @param {Graphics} graphics - The graphics object to update.
|
|
579
583
|
* @param {object} renderSession - The rendering session.
|
|
580
584
|
*/
|
|
581
|
-
export const renderGraphics = (graphics: Graphics, renderSession:
|
|
585
|
+
export const renderGraphics = (graphics: Graphics, renderSession: RenderSession) => {
|
|
582
586
|
const { gl } = renderSession;
|
|
583
587
|
const { projection } = renderSession;
|
|
584
588
|
const { offset } = renderSession;
|
|
585
589
|
let shader = renderSession.shaderManager.primitiveShader;
|
|
590
|
+
if (!shader) {
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
586
593
|
let webGLData;
|
|
587
594
|
if (graphics.dirty) {
|
|
588
595
|
updateGraphics(graphics, gl);
|
|
@@ -594,16 +601,18 @@ export const renderGraphics = (graphics: Graphics, renderSession: any) => {
|
|
|
594
601
|
}
|
|
595
602
|
// This could be speeded up for sure!
|
|
596
603
|
for (let i = 0; i < webGL.data.length; i += 1) {
|
|
597
|
-
|
|
598
|
-
|
|
604
|
+
webGLData = webGL.data[i]!;
|
|
605
|
+
if (webGLData.mode === 1) {
|
|
599
606
|
renderSession.stencilManager.pushStencil(graphics, webGLData, renderSession);
|
|
600
607
|
// render quad..
|
|
601
608
|
gl.drawElements(gl.TRIANGLE_FAN, 4, gl.UNSIGNED_SHORT, (webGLData.indices.length - 4) * 2);
|
|
602
609
|
renderSession.stencilManager.popStencil(graphics, webGLData, renderSession);
|
|
603
610
|
} else {
|
|
604
|
-
webGLData = webGL.data[i];
|
|
605
611
|
renderSession.shaderManager.setShader(shader); // activatePrimitiveShader();
|
|
606
612
|
shader = renderSession.shaderManager.primitiveShader;
|
|
613
|
+
if (!shader) {
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
607
616
|
gl.uniformMatrix3fv(shader.translationMatrix, false, graphics.worldTransform.toArray(true));
|
|
608
617
|
gl.uniform1f(shader.flipY, 1);
|
|
609
618
|
gl.uniform2f(shader.projectionVector, projection.x, -projection.y);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export class GraphicsData {
|
|
2
2
|
public glPoints!: Float32Array | null;
|
|
3
3
|
public glIndicies!: Uint16Array | null;
|
|
4
|
-
public gl
|
|
5
|
-
public color
|
|
6
|
-
public points
|
|
7
|
-
public indices
|
|
8
|
-
public buffer
|
|
9
|
-
public indexBuffer
|
|
10
|
-
public mode
|
|
11
|
-
public alpha
|
|
12
|
-
public dirty
|
|
4
|
+
public gl: WebGLRenderingContext;
|
|
5
|
+
public color: number[];
|
|
6
|
+
public points: number[];
|
|
7
|
+
public indices: number[];
|
|
8
|
+
public buffer: WebGLBuffer | null;
|
|
9
|
+
public indexBuffer: WebGLBuffer | null;
|
|
10
|
+
public mode: number;
|
|
11
|
+
public alpha: number;
|
|
12
|
+
public dirty: boolean;
|
|
13
13
|
/**
|
|
14
14
|
* Creates a new GraphicsData instance.
|
|
15
15
|
* @param {WebGLRenderingContext} gl - The WebGL rendering context.
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { updateGraphics } from './graphics.js';
|
|
2
|
+
import type { RenderSession } from '../render_session.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Sets up the mask manager for WebGL rendering.
|
|
5
6
|
* @param {object} maskData - The mask data to apply.
|
|
6
7
|
* @param {object} renderSession - The rendering session.
|
|
7
8
|
*/
|
|
8
|
-
export const pushMask = (maskData: any, renderSession:
|
|
9
|
+
export const pushMask = (maskData: any, renderSession: RenderSession) => {
|
|
9
10
|
const { gl } = renderSession;
|
|
10
11
|
if (maskData.dirty) {
|
|
11
12
|
updateGraphics(maskData, gl);
|
|
@@ -25,7 +26,7 @@ export const pushMask = (maskData: any, renderSession: any) => {
|
|
|
25
26
|
* @param {object} maskData - The mask data to apply.
|
|
26
27
|
* @param {object} renderSession - The rendering session.
|
|
27
28
|
*/
|
|
28
|
-
export const popMask = (maskData: any, renderSession:
|
|
29
|
+
export const popMask = (maskData: any, renderSession: RenderSession) => {
|
|
29
30
|
const { gl } = renderSession;
|
|
30
31
|
if (
|
|
31
32
|
maskData._webGL[gl.id] === undefined ||
|
|
@@ -10,9 +10,9 @@ import type { CanvasRenderer } from '../canvas/renderer.js';
|
|
|
10
10
|
|
|
11
11
|
export class RenderTexture extends Texture {
|
|
12
12
|
[key: string]: any;
|
|
13
|
-
declare public width:
|
|
14
|
-
declare public height:
|
|
15
|
-
public resolution!:
|
|
13
|
+
declare public width: number;
|
|
14
|
+
declare public height: number;
|
|
15
|
+
public resolution!: number;
|
|
16
16
|
declare public frame: any;
|
|
17
17
|
declare public crop: any;
|
|
18
18
|
public renderer!: any;
|
|
@@ -34,17 +34,18 @@ import { WebGLSpriteBatch } from './sprite_batch.js';
|
|
|
34
34
|
import { WebGLStencilManager } from './stencil_manager.js';
|
|
35
35
|
import type { IdentifiedWebGLRenderingContext } from './util.js';
|
|
36
36
|
import { getWebGLContextErrorCode, getWebGLContextErrorName } from './util.js';
|
|
37
|
+
import type { RenderSession } from '../render_session.js';
|
|
37
38
|
|
|
38
39
|
export class WebGLRenderer {
|
|
39
40
|
public gl!: IdentifiedWebGLRenderingContext;
|
|
40
41
|
public glContextId!: number;
|
|
41
42
|
public type!: any;
|
|
42
|
-
public resolution!:
|
|
43
|
+
public resolution!: number;
|
|
43
44
|
public autoResize!: any;
|
|
44
45
|
public contextLost!: any;
|
|
45
46
|
public clearBeforeRender!: any;
|
|
46
|
-
public width!:
|
|
47
|
-
public height!:
|
|
47
|
+
public width!: number;
|
|
48
|
+
public height!: number;
|
|
48
49
|
public view!: any;
|
|
49
50
|
public _contextOptions!: any;
|
|
50
51
|
public projection!: any;
|
|
@@ -54,7 +55,7 @@ export class WebGLRenderer {
|
|
|
54
55
|
public filterManager!: any;
|
|
55
56
|
public stencilManager!: any;
|
|
56
57
|
public blendModeManager!: any;
|
|
57
|
-
public renderSession!:
|
|
58
|
+
public renderSession!: RenderSession;
|
|
58
59
|
/**
|
|
59
60
|
* Creates a new WebGLRenderer instance.
|
|
60
61
|
* @param {Game} game - The game instance.
|
|
@@ -85,7 +86,8 @@ export class WebGLRenderer {
|
|
|
85
86
|
this.filterManager = new WebGLFilterManager();
|
|
86
87
|
this.stencilManager = new WebGLStencilManager();
|
|
87
88
|
this.blendModeManager = new WebGLBlendModeManager();
|
|
88
|
-
this.
|
|
89
|
+
// Only the WebGL half of the session applies to this renderer.
|
|
90
|
+
this.renderSession = {} as RenderSession;
|
|
89
91
|
this.renderSession.gl = this.gl;
|
|
90
92
|
this.renderSession.drawCount = 0;
|
|
91
93
|
this.renderSession.shaderManager = this.shaderManager;
|
|
@@ -121,7 +123,6 @@ export class WebGLRenderer {
|
|
|
121
123
|
loseContextExt.loseContext();
|
|
122
124
|
}
|
|
123
125
|
}
|
|
124
|
-
this.renderSession = null;
|
|
125
126
|
remove(this);
|
|
126
127
|
globalThis.PhaserRegistry.INSTANCES[this.glContextId] = null;
|
|
127
128
|
globalThis.PhaserRegistry.GL_CONTEXT_ID -= 1;
|
|
@@ -23,13 +23,22 @@ const defaultVertexSrc = [
|
|
|
23
23
|
|
|
24
24
|
const glMember = (gl: WebGLRenderingContext, name: string): any => (gl as unknown as Record<string, unknown>)[name];
|
|
25
25
|
|
|
26
|
+
/** Applies one of the gl uniform setters, whose signatures vary by uniform kind. */
|
|
27
|
+
const callUniformSetter = (setter: unknown, gl: WebGLRenderingContext, ...args: unknown[]): void => {
|
|
28
|
+
if (typeof setter === 'function') {
|
|
29
|
+
(setter as (...rest: unknown[]) => void).apply(gl, args);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
26
33
|
// this shader is used for the default sprite rendering
|
|
27
34
|
|
|
28
35
|
export type ShaderUniform = {
|
|
29
36
|
type: string;
|
|
30
37
|
value: any;
|
|
31
38
|
uniformLocation?: WebGLUniformLocation | null;
|
|
32
|
-
|
|
39
|
+
/** One of the gl uniform setters. Their arities differ by uniform kind, so the stored value is
|
|
40
|
+
* opaque and applied through callUniformSetter. */
|
|
41
|
+
glFunc?: unknown;
|
|
33
42
|
glMatrix?: boolean;
|
|
34
43
|
glValueLength?: number;
|
|
35
44
|
transpose?: boolean;
|
|
@@ -224,16 +233,24 @@ export class NormalShader {
|
|
|
224
233
|
for (const uniform of Object.values(this.uniforms)) {
|
|
225
234
|
if (uniform.glValueLength === 1) {
|
|
226
235
|
if (uniform.glMatrix === true) {
|
|
227
|
-
uniform.glFunc
|
|
236
|
+
callUniformSetter(uniform.glFunc, gl, uniform.uniformLocation, uniform.transpose, uniform.value);
|
|
228
237
|
} else {
|
|
229
|
-
uniform.glFunc
|
|
238
|
+
callUniformSetter(uniform.glFunc, gl, uniform.uniformLocation, uniform.value);
|
|
230
239
|
}
|
|
231
240
|
} else if (uniform.glValueLength === 2) {
|
|
232
|
-
uniform.glFunc
|
|
241
|
+
callUniformSetter(uniform.glFunc, gl, uniform.uniformLocation, uniform.value.x, uniform.value.y);
|
|
233
242
|
} else if (uniform.glValueLength === 3) {
|
|
234
|
-
|
|
243
|
+
callUniformSetter(
|
|
244
|
+
uniform.glFunc,
|
|
245
|
+
gl,
|
|
246
|
+
uniform.uniformLocation,
|
|
247
|
+
uniform.value.x,
|
|
248
|
+
uniform.value.y,
|
|
249
|
+
uniform.value.z
|
|
250
|
+
);
|
|
235
251
|
} else if (uniform.glValueLength === 4) {
|
|
236
|
-
|
|
252
|
+
callUniformSetter(
|
|
253
|
+
uniform.glFunc,
|
|
237
254
|
gl,
|
|
238
255
|
uniform.uniformLocation,
|
|
239
256
|
uniform.value.x,
|
|
@@ -5,6 +5,13 @@ import { PrimitiveShader } from './shader/primitive.js';
|
|
|
5
5
|
import { StripShader } from './shader/strip.js';
|
|
6
6
|
import type { IdentifiedWebGLRenderingContext } from './util.js';
|
|
7
7
|
|
|
8
|
+
/** The structural subset of a shader that the manager binds. */
|
|
9
|
+
export type ManagedShader = {
|
|
10
|
+
_UID: string;
|
|
11
|
+
program: WebGLProgram | null;
|
|
12
|
+
attributes: (number | undefined)[] | null;
|
|
13
|
+
};
|
|
14
|
+
|
|
8
15
|
export class WebGLShaderManager {
|
|
9
16
|
public gl!: IdentifiedWebGLRenderingContext;
|
|
10
17
|
public primitiveShader: PrimitiveShader | null = null;
|
|
@@ -15,8 +22,8 @@ export class WebGLShaderManager {
|
|
|
15
22
|
public maxAttibs = 10;
|
|
16
23
|
public attribState: (boolean | undefined)[];
|
|
17
24
|
public tempAttribState: (boolean | undefined)[];
|
|
18
|
-
public stack:
|
|
19
|
-
public currentShader:
|
|
25
|
+
public stack: ManagedShader[];
|
|
26
|
+
public currentShader: ManagedShader | null = null;
|
|
20
27
|
public _currentId: string | null = null;
|
|
21
28
|
/**
|
|
22
29
|
* Initializes the shader manager with a WebGL context.
|
|
@@ -48,7 +55,7 @@ export class WebGLShaderManager {
|
|
|
48
55
|
* Sets up the shader manager for WebGL rendering.
|
|
49
56
|
* @param {number[]} attribs - The attribute locations to set up.
|
|
50
57
|
*/
|
|
51
|
-
public setAttribs(attribs: number[]) {
|
|
58
|
+
public setAttribs(attribs: (number | undefined)[]) {
|
|
52
59
|
// reset temp state
|
|
53
60
|
let i;
|
|
54
61
|
for (i = 0; i < this.tempAttribState.length; i += 1) {
|
|
@@ -56,7 +63,9 @@ export class WebGLShaderManager {
|
|
|
56
63
|
}
|
|
57
64
|
// set the new attribs
|
|
58
65
|
for (const attribId of attribs) {
|
|
59
|
-
|
|
66
|
+
if (attribId !== undefined) {
|
|
67
|
+
this.tempAttribState[attribId] = true;
|
|
68
|
+
}
|
|
60
69
|
}
|
|
61
70
|
const { gl } = this;
|
|
62
71
|
for (i = 0; i < this.attribState.length; i += 1) {
|
|
@@ -76,14 +85,14 @@ export class WebGLShaderManager {
|
|
|
76
85
|
* @param {NormalShader} shader - The shader to set up.
|
|
77
86
|
* @returns {boolean} Whether the shader setup was successful.
|
|
78
87
|
*/
|
|
79
|
-
public setShader(shader:
|
|
88
|
+
public setShader(shader: ManagedShader): boolean {
|
|
80
89
|
if (this._currentId === shader._UID) {
|
|
81
90
|
return false;
|
|
82
91
|
}
|
|
83
92
|
this._currentId = shader._UID;
|
|
84
93
|
this.currentShader = shader;
|
|
85
94
|
this.gl.useProgram(shader.program);
|
|
86
|
-
this.setAttribs(shader.attributes);
|
|
95
|
+
this.setAttribs(shader.attributes ?? []);
|
|
87
96
|
return true;
|
|
88
97
|
}
|
|
89
98
|
|
|
@@ -4,6 +4,7 @@ import type { IdentifiedWebGLRenderingContext } from './util.js';
|
|
|
4
4
|
import type { Image } from '../../display/image.js';
|
|
5
5
|
import type { Matrix } from '../../geom/matrix.js';
|
|
6
6
|
import type { BaseTexture } from './base_texture.js';
|
|
7
|
+
import type { RenderSession } from '../render_session.js';
|
|
7
8
|
|
|
8
9
|
export class WebGLSpriteBatch {
|
|
9
10
|
public vertSize = 5;
|
|
@@ -26,7 +27,7 @@ export class WebGLSpriteBatch {
|
|
|
26
27
|
public vertexBuffer!: WebGLBuffer | null;
|
|
27
28
|
public indexBuffer!: WebGLBuffer | null;
|
|
28
29
|
public currentBlendMode!: number;
|
|
29
|
-
public renderSession!:
|
|
30
|
+
public renderSession!: RenderSession;
|
|
30
31
|
public shader!: NormalShader | null;
|
|
31
32
|
/**
|
|
32
33
|
* Creates a new SpriteBatch instance.
|
|
@@ -96,7 +97,7 @@ export class WebGLSpriteBatch {
|
|
|
96
97
|
* Renders the sprite batch using WebGL.
|
|
97
98
|
* @param {object} renderSession - The render session to use.
|
|
98
99
|
*/
|
|
99
|
-
public begin(renderSession:
|
|
100
|
+
public begin(renderSession: RenderSession) {
|
|
100
101
|
this.renderSession = renderSession;
|
|
101
102
|
this.shader = this.renderSession.shaderManager.defaultShader;
|
|
102
103
|
this.start();
|
|
@@ -114,7 +115,7 @@ export class WebGLSpriteBatch {
|
|
|
114
115
|
* @param {Image} sprite - The sprite to render.
|
|
115
116
|
* @param {Matrix} matrix - The transformation matrix.
|
|
116
117
|
*/
|
|
117
|
-
public render(sprite: Image, matrix: Matrix) {
|
|
118
|
+
public render(sprite: Image, matrix: Matrix | null = null) {
|
|
118
119
|
const { texture } = sprite;
|
|
119
120
|
// They provided an alternative rendering matrix, so use it
|
|
120
121
|
let wt = sprite.worldTransform;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { hex2rgb } from '../../util/math.js';
|
|
2
2
|
import type { Graphics } from '../graphics.js';
|
|
3
3
|
import type { GraphicsData } from './graphics_data.js';
|
|
4
|
+
import type { RenderSession } from '../render_session.js';
|
|
4
5
|
|
|
5
6
|
export class WebGLStencilManager {
|
|
6
7
|
public gl!: WebGLRenderingContext;
|
|
@@ -37,7 +38,7 @@ export class WebGLStencilManager {
|
|
|
37
38
|
* @param {GraphicsData} webGLData - The WebGL graphics data.
|
|
38
39
|
* @param {object} renderSession - The rendering session.
|
|
39
40
|
*/
|
|
40
|
-
public pushStencil(graphics: Graphics, webGLData: GraphicsData, renderSession:
|
|
41
|
+
public pushStencil(graphics: Graphics, webGLData: GraphicsData, renderSession: RenderSession) {
|
|
41
42
|
const { gl } = renderSession;
|
|
42
43
|
this.bindGraphics(graphics, webGLData, renderSession);
|
|
43
44
|
if (this.stencilStack.length === 0) {
|
|
@@ -95,7 +96,7 @@ export class WebGLStencilManager {
|
|
|
95
96
|
* @param {GraphicsData} webGLData - The WebGL graphics data.
|
|
96
97
|
* @param {object} renderSession - The rendering session.
|
|
97
98
|
*/
|
|
98
|
-
public bindGraphics(graphics: Graphics, webGLData: GraphicsData, renderSession:
|
|
99
|
+
public bindGraphics(graphics: Graphics, webGLData: GraphicsData, renderSession: RenderSession) {
|
|
99
100
|
// if(this._currentGraphics === graphics)return;
|
|
100
101
|
// this._currentGraphics = graphics;
|
|
101
102
|
const { gl } = renderSession;
|
|
@@ -105,6 +106,9 @@ export class WebGLStencilManager {
|
|
|
105
106
|
let shader; // = renderSession.shaderManager.primitiveShader;
|
|
106
107
|
if (webGLData.mode === 1) {
|
|
107
108
|
shader = renderSession.shaderManager.complexPrimitiveShader;
|
|
109
|
+
if (!shader) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
108
112
|
renderSession.shaderManager.setShader(shader);
|
|
109
113
|
gl.uniform1f(shader.flipY, renderSession.flipY);
|
|
110
114
|
gl.uniformMatrix3fv(shader.translationMatrix, false, graphics.worldTransform.toArray(true));
|
|
@@ -121,6 +125,9 @@ export class WebGLStencilManager {
|
|
|
121
125
|
} else {
|
|
122
126
|
// renderSession.shaderManager.activatePrimitiveShader();
|
|
123
127
|
shader = renderSession.shaderManager.primitiveShader;
|
|
128
|
+
if (!shader) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
124
131
|
renderSession.shaderManager.setShader(shader);
|
|
125
132
|
gl.uniformMatrix3fv(shader.translationMatrix, false, graphics.worldTransform.toArray(true));
|
|
126
133
|
gl.uniform1f(shader.flipY, renderSession.flipY);
|
|
@@ -142,7 +149,7 @@ export class WebGLStencilManager {
|
|
|
142
149
|
* @param {GraphicsData} webGLData - The WebGL graphics data.
|
|
143
150
|
* @param {object} renderSession - The rendering session.
|
|
144
151
|
*/
|
|
145
|
-
public popStencil(graphics: Graphics, webGLData: GraphicsData, renderSession:
|
|
152
|
+
public popStencil(graphics: Graphics, webGLData: GraphicsData, renderSession: RenderSession) {
|
|
146
153
|
const { gl } = renderSession;
|
|
147
154
|
this.stencilStack.pop();
|
|
148
155
|
this.count -= 1;
|
|
@@ -6,13 +6,13 @@ export class TextureUvs {
|
|
|
6
6
|
public baseTexture!: any;
|
|
7
7
|
public frame!: any;
|
|
8
8
|
public trim!: any;
|
|
9
|
-
public valid!:
|
|
9
|
+
public valid!: boolean;
|
|
10
10
|
public isTiling!: any;
|
|
11
11
|
public requiresUpdate!: any;
|
|
12
12
|
public requiresReTint!: any;
|
|
13
13
|
public _uvs!: any;
|
|
14
|
-
public width!:
|
|
15
|
-
public height!:
|
|
14
|
+
public width!: number;
|
|
15
|
+
public height!: number;
|
|
16
16
|
public crop!: any;
|
|
17
17
|
public x0: any = 0;
|
|
18
18
|
public y0: any = 0;
|
|
@@ -37,13 +37,13 @@ export class Texture {
|
|
|
37
37
|
public baseTexture!: any;
|
|
38
38
|
public frame!: any;
|
|
39
39
|
public trim!: any;
|
|
40
|
-
public valid!:
|
|
40
|
+
public valid!: boolean;
|
|
41
41
|
public isTiling!: any;
|
|
42
42
|
public requiresUpdate!: any;
|
|
43
43
|
public requiresReTint!: any;
|
|
44
44
|
public _uvs!: any;
|
|
45
|
-
public width!:
|
|
46
|
-
public height!:
|
|
45
|
+
public width!: number;
|
|
46
|
+
public height!: number;
|
|
47
47
|
public crop!: any;
|
|
48
48
|
/**
|
|
49
49
|
* Creates a new Texture instance.
|