melonjs 14.4.0 → 15.0.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/LICENSE.md +1 -1
- package/README.md +13 -57
- package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
- package/dist/melonjs.mjs/_virtual/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
- package/dist/melonjs.mjs/_virtual/howler.js +1 -1
- package/dist/melonjs.mjs/_virtual/index.js +1 -1
- package/dist/melonjs.mjs/_virtual/index2.js +1 -1
- package/dist/melonjs.mjs/_virtual/multimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/setmultimap.js +1 -1
- package/dist/melonjs.mjs/application/application.js +1 -1
- package/dist/melonjs.mjs/application/header.js +1 -1
- package/dist/melonjs.mjs/application/resize.js +1 -1
- package/dist/melonjs.mjs/application/settings.js +1 -1
- package/dist/melonjs.mjs/audio/audio.js +5 -7
- package/dist/melonjs.mjs/camera/camera2d.js +1 -1
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +43 -9
- package/dist/melonjs.mjs/geometries/ellipse.js +2 -3
- package/dist/melonjs.mjs/geometries/line.js +1 -1
- package/dist/melonjs.mjs/geometries/path2d.js +20 -44
- package/dist/melonjs.mjs/geometries/point.js +1 -6
- package/dist/melonjs.mjs/geometries/poly.js +2 -5
- package/dist/melonjs.mjs/geometries/rectangle.js +13 -9
- package/dist/melonjs.mjs/geometries/roundrect.js +1 -1
- package/dist/melonjs.mjs/index.js +10 -6
- package/dist/melonjs.mjs/input/gamepad.js +10 -16
- package/dist/melonjs.mjs/input/input.js +1 -1
- package/dist/melonjs.mjs/input/keyboard.js +1 -1
- package/dist/melonjs.mjs/input/pointer.js +1 -1
- package/dist/melonjs.mjs/input/pointerevent.js +3 -17
- package/dist/melonjs.mjs/lang/console.js +1 -1
- package/dist/melonjs.mjs/lang/deprecated.js +1 -1
- package/dist/melonjs.mjs/level/level.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +1 -8
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +8 -4
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +5 -5
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +1 -1
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
- package/dist/melonjs.mjs/loader/cache.js +24 -0
- package/dist/melonjs.mjs/loader/loader.js +331 -716
- package/dist/melonjs.mjs/loader/loadingscreen.js +4 -4
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +281 -0
- package/dist/melonjs.mjs/loader/settings.js +91 -0
- package/dist/melonjs.mjs/math/color.js +9 -8
- package/dist/melonjs.mjs/math/math.js +1 -1
- package/dist/melonjs.mjs/math/matrix2.js +7 -9
- package/dist/melonjs.mjs/math/matrix3.js +18 -21
- package/dist/melonjs.mjs/math/observable_vector2.js +3 -3
- package/dist/melonjs.mjs/math/observable_vector3.js +3 -4
- package/dist/melonjs.mjs/math/vector2.js +3 -3
- package/dist/melonjs.mjs/math/vector3.js +3 -4
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
- package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
- package/dist/melonjs.mjs/particles/emitter.js +3 -3
- package/dist/melonjs.mjs/particles/particle.js +1 -1
- package/dist/melonjs.mjs/particles/settings.js +1 -1
- package/dist/melonjs.mjs/physics/body.js +18 -14
- package/dist/melonjs.mjs/physics/bounds.js +18 -70
- package/dist/melonjs.mjs/physics/collision.js +1 -1
- package/dist/melonjs.mjs/physics/detector.js +1 -1
- package/dist/melonjs.mjs/physics/quadtree.js +1 -1
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +1 -1
- package/dist/melonjs.mjs/physics/world.js +1 -1
- package/dist/melonjs.mjs/plugin/plugin.js +3 -3
- package/dist/melonjs.mjs/renderable/collectable.js +1 -1
- package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
- package/dist/melonjs.mjs/renderable/container.js +25 -19
- package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
- package/dist/melonjs.mjs/renderable/imagelayer.js +7 -1
- package/dist/melonjs.mjs/renderable/light2d.js +1 -1
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +1 -1
- package/dist/melonjs.mjs/renderable/renderable.js +148 -105
- package/dist/melonjs.mjs/renderable/sprite.js +33 -54
- package/dist/melonjs.mjs/renderable/trigger.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +1 -3
- package/dist/melonjs.mjs/state/stage.js +1 -1
- package/dist/melonjs.mjs/state/state.js +2 -2
- package/dist/melonjs.mjs/system/device.js +2 -2
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +1 -1
- package/dist/melonjs.mjs/system/platform.js +1 -1
- package/dist/melonjs.mjs/system/pooling.js +8 -18
- package/dist/melonjs.mjs/system/save.js +1 -1
- package/dist/melonjs.mjs/system/timer.js +1 -1
- package/dist/melonjs.mjs/text/bitmaptext.js +66 -8
- package/dist/melonjs.mjs/text/bitmaptextdata.js +1 -1
- package/dist/melonjs.mjs/text/glyph.js +1 -1
- package/dist/melonjs.mjs/text/text.js +56 -86
- package/dist/melonjs.mjs/text/textmetrics.js +1 -1
- package/dist/melonjs.mjs/text/textstyle.js +4 -6
- package/dist/melonjs.mjs/tweens/easing.js +1 -1
- package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
- package/dist/melonjs.mjs/tweens/tween.js +1 -1
- package/dist/melonjs.mjs/utils/agent.js +1 -1
- package/dist/melonjs.mjs/utils/array.js +1 -1
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +1 -1
- package/dist/melonjs.mjs/utils/string.js +2 -2
- package/dist/melonjs.mjs/utils/utils.js +2 -4
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +7 -11
- package/dist/melonjs.mjs/video/renderer.js +2 -13
- package/dist/melonjs.mjs/video/texture/atlas.js +12 -17
- package/dist/melonjs.mjs/video/texture/cache.js +3 -3
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +1 -1
- package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
- package/dist/melonjs.mjs/video/video.js +2 -2
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +21 -17
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +235 -0
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +77 -0
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +249 -0
- package/dist/melonjs.mjs/video/webgl/{webgl_compositor.js → compositors/webgl_compositor.js} +20 -205
- package/dist/melonjs.mjs/video/webgl/glshader.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +2 -2
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +2 -2
- package/dist/melonjs.mjs/video/webgl/utils/attributes.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +139 -149
- package/dist/melonjs.module.js +26320 -26376
- package/dist/types/entity/entity.d.ts +3 -3
- package/dist/types/geometries/path2d.d.ts +5 -31
- package/dist/types/geometries/point.d.ts +2 -7
- package/dist/types/geometries/poly.d.ts +0 -1
- package/dist/types/index.d.ts +5 -3
- package/dist/types/loader/cache.d.ts +7 -0
- package/dist/types/loader/loader.d.ts +166 -181
- package/dist/types/loader/parser.d.ts +41 -0
- package/dist/types/loader/settings.d.ts +57 -0
- package/dist/types/particles/emitter.d.ts +4 -4
- package/dist/types/physics/bounds.d.ts +29 -84
- package/dist/types/renderable/container.d.ts +0 -11
- package/dist/types/renderable/renderable.d.ts +43 -31
- package/dist/types/renderable/sprite.d.ts +3 -3
- package/dist/types/renderable/ui/uitextbutton.d.ts +0 -1
- package/dist/types/state/state.d.ts +1 -1
- package/dist/types/system/pooling.d.ts +2 -2
- package/dist/types/text/text.d.ts +6 -20
- package/dist/types/text/textstyle.d.ts +1 -1
- package/dist/types/video/canvas/canvas_renderer.d.ts +0 -5
- package/dist/types/video/renderer.d.ts +1 -5
- package/dist/types/video/webgl/buffer/vertex.d.ts +3 -3
- package/dist/types/video/webgl/compositors/compositor.d.ts +107 -0
- package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +22 -0
- package/dist/types/video/webgl/compositors/quad_compositor.d.ts +72 -0
- package/dist/types/video/webgl/compositors/webgl_compositor.d.ts +86 -0
- package/dist/types/video/webgl/webgl_compositor.d.ts +2 -3
- package/dist/types/video/webgl/webgl_renderer.d.ts +34 -28
- package/package.json +18 -18
- package/src/audio/audio.js +4 -6
- package/src/entity/entity.js +42 -8
- package/src/geometries/ellipse.js +1 -2
- package/src/geometries/path2d.js +19 -43
- package/src/geometries/point.js +0 -5
- package/src/geometries/poly.js +1 -4
- package/src/geometries/rectangle.js +12 -8
- package/src/index.js +7 -3
- package/src/input/gamepad.js +9 -15
- package/src/input/pointerevent.js +1 -15
- package/src/level/level.js +2 -2
- package/src/level/tiled/TMXLayer.js +0 -7
- package/src/level/tiled/TMXTileMap.js +7 -3
- package/src/level/tiled/TMXTileset.js +4 -4
- package/src/loader/cache.js +16 -0
- package/src/loader/loader.js +339 -711
- package/src/loader/loadingscreen.js +3 -3
- package/src/loader/parser.js +279 -0
- package/src/loader/settings.js +85 -0
- package/src/math/color.js +8 -7
- package/src/math/matrix2.js +6 -8
- package/src/math/matrix3.js +17 -20
- package/src/math/observable_vector2.js +2 -2
- package/src/math/observable_vector3.js +2 -3
- package/src/math/vector2.js +2 -2
- package/src/math/vector3.js +2 -3
- package/src/particles/emitter.js +2 -2
- package/src/physics/body.js +17 -13
- package/src/physics/bounds.js +17 -69
- package/src/polyfill/index.js +0 -2
- package/src/renderable/container.js +24 -18
- package/src/renderable/imagelayer.js +6 -0
- package/src/renderable/renderable.js +147 -104
- package/src/renderable/sprite.js +32 -53
- package/src/renderable/ui/uitextbutton.js +0 -2
- package/src/state/state.js +1 -1
- package/src/system/device.js +1 -1
- package/src/system/pooling.js +7 -17
- package/src/text/bitmaptext.js +65 -7
- package/src/text/text.js +55 -85
- package/src/text/textstyle.js +3 -5
- package/src/utils/string.js +1 -1
- package/src/utils/utils.js +1 -3
- package/src/video/canvas/canvas_renderer.js +5 -9
- package/src/video/renderer.js +0 -11
- package/src/video/texture/atlas.js +11 -16
- package/src/video/texture/cache.js +2 -2
- package/src/video/video.js +1 -1
- package/src/video/webgl/buffer/vertex.js +20 -16
- package/src/video/webgl/compositors/compositor.js +226 -0
- package/src/video/webgl/compositors/primitive_compositor.js +68 -0
- package/src/video/webgl/compositors/quad_compositor.js +240 -0
- package/src/video/webgl/shaders/primitive.vert +2 -5
- package/src/video/webgl/shaders/quad.vert +3 -1
- package/src/video/webgl/webgl_renderer.js +137 -147
- package/dist/melonjs.mjs/_virtual/make-built-in.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-define-property.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-descriptor.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-names.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-symbols.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-property-is-enumerable.js +0 -10
- package/dist/melonjs.mjs/_virtual/shared.js +0 -10
- package/dist/melonjs.mjs/game.js +0 -29
- package/dist/melonjs.mjs/polyfill/console.js +0 -18
- package/dist/melonjs.mjs/polyfill/performance.js +0 -27
- package/dist/melonjs.mjs/polyfill/requestAnimationFrame.js +0 -46
- package/dist/melonjs.mjs/polyfill/roundrect.js +0 -242
- package/dist/melonjs.mjs/renderable/re_container.js +0 -1016
- package/dist/melonjs.mjs/video/utils/resize.js +0 -116
- package/src/polyfill/performance.js +0 -20
- package/src/polyfill/requestAnimationFrame.js +0 -39
- package/src/video/webgl/webgl_compositor.js +0 -486
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine -
|
|
2
|
+
* melonJS Game Engine - v15.0.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -7,14 +7,15 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import Color from '../../math/color.js';
|
|
9
9
|
import Matrix2d from '../../math/matrix2.js';
|
|
10
|
-
import
|
|
10
|
+
import QuadCompositor from './compositors/quad_compositor.js';
|
|
11
|
+
import PrimitiveCompositor from './compositors/primitive_compositor.js';
|
|
11
12
|
import Renderer from '../renderer.js';
|
|
12
13
|
import TextureCache from '../texture/cache.js';
|
|
13
14
|
import { TextureAtlas, createAtlas } from '../texture/atlas.js';
|
|
14
|
-
import {
|
|
15
|
-
import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js';
|
|
15
|
+
import { renderer } from '../video.js';
|
|
16
|
+
import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET, CANVAS_ONRESIZE } from '../../system/event.js';
|
|
16
17
|
import pool from '../../system/pooling.js';
|
|
17
|
-
import { isPowerOfTwo
|
|
18
|
+
import { isPowerOfTwo } from '../../math/math.js';
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* @classdesc
|
|
@@ -36,10 +37,9 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
36
37
|
* @param {string} [options.powerPreference="default"] - a hint to the user agent indicating what configuration of GPU is suitable for the WebGL context ("default", "high-performance", "low-power"). To be noted that Safari and Chrome (since version 80) both default to "low-power" to save battery life and improve the user experience on these dual-GPU machines.
|
|
37
38
|
* @param {number} [options.zoomX=width] - The actual width of the canvas with scaling applied
|
|
38
39
|
* @param {number} [options.zoomY=height] - The actual height of the canvas with scaling applied
|
|
39
|
-
* @param {
|
|
40
|
+
* @param {Compositor} [options.compositor] - A class that implements the compositor API for sprite rendering
|
|
40
41
|
*/
|
|
41
42
|
constructor(options) {
|
|
42
|
-
|
|
43
43
|
// parent contructor
|
|
44
44
|
super(options);
|
|
45
45
|
|
|
@@ -54,18 +54,18 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
54
54
|
/**
|
|
55
55
|
* The vendor string of the underlying graphics driver.
|
|
56
56
|
* @type {string}
|
|
57
|
-
* @default
|
|
57
|
+
* @default undefined
|
|
58
58
|
* @readonly
|
|
59
59
|
*/
|
|
60
|
-
this.GPUVendor =
|
|
60
|
+
this.GPUVendor = undefined;
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* The renderer string of the underlying graphics driver.
|
|
64
64
|
* @type {string}
|
|
65
|
-
* @default
|
|
65
|
+
* @default undefined
|
|
66
66
|
* @readonly
|
|
67
67
|
*/
|
|
68
|
-
this.GPURenderer =
|
|
68
|
+
this.GPURenderer = undefined;
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* The WebGL context
|
|
@@ -74,6 +74,12 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
74
74
|
*/
|
|
75
75
|
this.context = this.gl = this.getContextGL(this.getCanvas(), options.transparent);
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* the vertex buffer used by this WebGL Renderer
|
|
79
|
+
* @type {WebGLBuffer}
|
|
80
|
+
*/
|
|
81
|
+
this.vertexBuffer = this.gl.createBuffer();
|
|
82
|
+
|
|
77
83
|
/**
|
|
78
84
|
* Maximum number of texture unit supported under the current context
|
|
79
85
|
* @type {number}
|
|
@@ -111,7 +117,13 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
111
117
|
* The current compositor used by the renderer
|
|
112
118
|
* @type {WebGLCompositor}
|
|
113
119
|
*/
|
|
114
|
-
this.currentCompositor =
|
|
120
|
+
this.currentCompositor = undefined;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* a reference to the current shader program used by the renderer
|
|
124
|
+
* @type {WebGLProgram}
|
|
125
|
+
*/
|
|
126
|
+
this.currentProgram = undefined;
|
|
115
127
|
|
|
116
128
|
/**
|
|
117
129
|
* The list of active compositors
|
|
@@ -119,10 +131,12 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
119
131
|
*/
|
|
120
132
|
this.compositors = new Map();
|
|
121
133
|
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
134
|
+
// bind the vertex buffer
|
|
135
|
+
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.vertexBuffer);
|
|
136
|
+
|
|
137
|
+
// Create both quad and primitive compositor
|
|
138
|
+
this.addCompositor(new (this.settings.compositor || QuadCompositor)(this), "quad", true);
|
|
139
|
+
this.addCompositor(new (this.settings.compositor || PrimitiveCompositor)(this), "primitive");
|
|
126
140
|
|
|
127
141
|
|
|
128
142
|
// default WebGL state(s)
|
|
@@ -140,6 +154,10 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
140
154
|
this.GPURenderer = this.gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
|
|
141
155
|
}
|
|
142
156
|
|
|
157
|
+
// a private property that when set will make `setCompositor`
|
|
158
|
+
// to use this specific shader instead of the default one
|
|
159
|
+
this.customShader = undefined;
|
|
160
|
+
|
|
143
161
|
// Create a texture cache
|
|
144
162
|
this.cache = new TextureCache(this.maxTextures);
|
|
145
163
|
|
|
@@ -160,6 +178,17 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
160
178
|
this.isContextValid = true;
|
|
161
179
|
emit(ONCONTEXT_RESTORED, this);
|
|
162
180
|
}, false );
|
|
181
|
+
|
|
182
|
+
// reset the renderer on game reset
|
|
183
|
+
on(GAME_RESET, () => {
|
|
184
|
+
this.reset();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// register to the CANVAS resize channel
|
|
188
|
+
on(CANVAS_ONRESIZE, (width, height) => {
|
|
189
|
+
this.flush();
|
|
190
|
+
this.setViewport(0, 0, width, height);
|
|
191
|
+
});
|
|
163
192
|
}
|
|
164
193
|
|
|
165
194
|
/**
|
|
@@ -168,6 +197,21 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
168
197
|
reset() {
|
|
169
198
|
super.reset();
|
|
170
199
|
|
|
200
|
+
// clear gl context
|
|
201
|
+
this.clear();
|
|
202
|
+
|
|
203
|
+
// initial viewport size
|
|
204
|
+
this.setViewport();
|
|
205
|
+
|
|
206
|
+
// rebind the vertex buffer if required (e.g in case of context loss)
|
|
207
|
+
if (this.gl.getParameter(this.gl.ARRAY_BUFFER_BINDING) !== this.vertexBuffer) {
|
|
208
|
+
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.vertexBuffer);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
this.currentCompositor = undefined;
|
|
212
|
+
this.currentProgram = undefined;
|
|
213
|
+
this.customShader = undefined;
|
|
214
|
+
|
|
171
215
|
this.compositors.forEach((compositor) => {
|
|
172
216
|
if (this.isContextValid === false) {
|
|
173
217
|
// on context lost/restore
|
|
@@ -177,35 +221,62 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
177
221
|
}
|
|
178
222
|
});
|
|
179
223
|
|
|
224
|
+
this.setCompositor("quad");
|
|
225
|
+
|
|
180
226
|
this.gl.disable(this.gl.SCISSOR_TEST);
|
|
181
|
-
|
|
182
|
-
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* add a new compositor to this renderer
|
|
231
|
+
* @param {Compositor} compositor - a compositor instance
|
|
232
|
+
* @param {String} name - a name uniquely identifying this compositor
|
|
233
|
+
* @param {Boolean} [activate=false] - true if the given compositor should be set as the active one
|
|
234
|
+
*/
|
|
235
|
+
addCompositor(compositor, name = "default", activate = false) {
|
|
236
|
+
// make sure there is no existing compositor with the same name
|
|
237
|
+
if (typeof this.compositors.get(name) !== "undefined") {
|
|
238
|
+
throw new Error("Invalid Compositor name");
|
|
183
239
|
}
|
|
184
240
|
|
|
241
|
+
// add the new compositor
|
|
242
|
+
this.compositors.set(name, compositor);
|
|
243
|
+
|
|
244
|
+
if (activate === true) {
|
|
245
|
+
// set as active one
|
|
246
|
+
this.setCompositor(name);
|
|
247
|
+
}
|
|
185
248
|
}
|
|
186
249
|
|
|
187
250
|
/**
|
|
188
251
|
* set the active compositor for this renderer
|
|
189
|
-
* @param {
|
|
252
|
+
* @param {String} name - a compositor name
|
|
253
|
+
* @param {GLShader} [shader] - an optional shader program to be used, instead of the default one, when activating the compositor
|
|
254
|
+
* @return {Compositor} an instance to the current active compositor
|
|
190
255
|
*/
|
|
191
|
-
setCompositor(
|
|
192
|
-
|
|
193
|
-
if (typeof compositor === "string") {
|
|
194
|
-
compositor = this.compositors.get(compositor);
|
|
195
|
-
}
|
|
256
|
+
setCompositor(name = "default", shader = this.customShader) {
|
|
257
|
+
let compositor = this.compositors.get(name);
|
|
196
258
|
|
|
197
259
|
if (typeof compositor === "undefined") {
|
|
198
|
-
throw new Error("Invalid
|
|
260
|
+
throw new Error("Invalid Compositor");
|
|
199
261
|
}
|
|
200
262
|
|
|
201
263
|
if (this.currentCompositor !== compositor) {
|
|
202
|
-
if (this.currentCompositor !==
|
|
264
|
+
if (this.currentCompositor !== undefined) {
|
|
203
265
|
// flush the current compositor
|
|
204
266
|
this.currentCompositor.flush();
|
|
205
267
|
}
|
|
206
|
-
// set
|
|
268
|
+
// set as the active one
|
|
207
269
|
this.currentCompositor = compositor;
|
|
208
270
|
}
|
|
271
|
+
|
|
272
|
+
if (name === "quad" && typeof shader === "object") {
|
|
273
|
+
this.currentCompositor.useShader(shader);
|
|
274
|
+
} else {
|
|
275
|
+
// (re)bind the compositor with the default shader (program & attributes)
|
|
276
|
+
this.currentCompositor.bind();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return this.currentCompositor;
|
|
209
280
|
}
|
|
210
281
|
|
|
211
282
|
/**
|
|
@@ -215,43 +286,6 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
215
286
|
this.currentTransform.identity();
|
|
216
287
|
}
|
|
217
288
|
|
|
218
|
-
/**
|
|
219
|
-
* @ignore
|
|
220
|
-
*/
|
|
221
|
-
createFontTexture(cache) {
|
|
222
|
-
if (typeof this.fontTexture === "undefined") {
|
|
223
|
-
var canvas = this.getCanvas();
|
|
224
|
-
var width = canvas.width;
|
|
225
|
-
var height = canvas.height;
|
|
226
|
-
|
|
227
|
-
if (this.WebGLVersion === 1) {
|
|
228
|
-
if (!isPowerOfTwo(width)) {
|
|
229
|
-
width = nextPowerOfTwo(canvas.width);
|
|
230
|
-
}
|
|
231
|
-
if (!isPowerOfTwo(height)) {
|
|
232
|
-
height = nextPowerOfTwo(canvas.height);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
var image = createCanvas(width, height, true);
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* @ignore
|
|
240
|
-
*/
|
|
241
|
-
this.fontContext2D = this.getContext2d(image);
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* @ignore
|
|
245
|
-
*/
|
|
246
|
-
this.fontTexture = new TextureAtlas(createAtlas(canvas.width, canvas.height, "fontTexture"), image, cache);
|
|
247
|
-
this.currentCompositor.uploadTexture(this.fontTexture, 0, 0, 0);
|
|
248
|
-
|
|
249
|
-
} else {
|
|
250
|
-
// fontTexture was already created, just add it back into the cache
|
|
251
|
-
cache.set(this.fontContext2D.canvas, this.fontTexture);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
289
|
/**
|
|
256
290
|
* Create a pattern with the specified repetition
|
|
257
291
|
* @param {Image} image - Source image
|
|
@@ -266,6 +300,8 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
266
300
|
*/
|
|
267
301
|
createPattern(image, repeat) {
|
|
268
302
|
|
|
303
|
+
this.setCompositor("quad");
|
|
304
|
+
|
|
269
305
|
if (renderer.WebGLVersion === 1 && (!isPowerOfTwo(image.width) || !isPowerOfTwo(image.height))) {
|
|
270
306
|
var src = typeof image.src !== "undefined" ? image.src : image;
|
|
271
307
|
throw new Error(
|
|
@@ -299,10 +335,23 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
299
335
|
}
|
|
300
336
|
|
|
301
337
|
/**
|
|
302
|
-
*
|
|
338
|
+
* Sets the WebGL viewport, which specifies the affine transformation of x and y from normalized device coordinates to window coordinates
|
|
339
|
+
* @param {number} [x = 0] - x the horizontal coordinate for the lower left corner of the viewport origin
|
|
340
|
+
* @param {number} [y = 0] - y the vertical coordinate for the lower left corner of the viewport origin
|
|
341
|
+
* @param {number} [w = width of the canvas] - the width of viewport
|
|
342
|
+
* @param {number} [h = height of the canvas] - the height of viewport
|
|
343
|
+
*/
|
|
344
|
+
setViewport(x = 0, y = 0, w = this.getCanvas().width, h = this.getCanvas().height) {
|
|
345
|
+
this.gl.viewport(x, y, w, h);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Clear the frame buffer
|
|
303
350
|
*/
|
|
304
351
|
clear() {
|
|
305
|
-
|
|
352
|
+
var gl = this.gl;
|
|
353
|
+
gl.clearColor(0, 0, 0, this.settings.transparent ? 0.0 : 1.0);
|
|
354
|
+
gl.clear(gl.COLOR_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
|
|
306
355
|
}
|
|
307
356
|
|
|
308
357
|
/**
|
|
@@ -312,6 +361,7 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
312
361
|
*/
|
|
313
362
|
clearColor(color = "#000000", opaque = false) {
|
|
314
363
|
var glArray;
|
|
364
|
+
var gl = this.gl;
|
|
315
365
|
|
|
316
366
|
if (color instanceof Color) {
|
|
317
367
|
glArray = color.toArray();
|
|
@@ -321,8 +371,10 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
321
371
|
glArray = _color.parseCSS(color).toArray();
|
|
322
372
|
pool.push(_color);
|
|
323
373
|
}
|
|
374
|
+
|
|
324
375
|
// clear gl context with the specified color
|
|
325
|
-
|
|
376
|
+
gl.clearColor(glArray[0], glArray[1], glArray[2], (opaque === true) ? 1.0 : glArray[3]);
|
|
377
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
326
378
|
}
|
|
327
379
|
|
|
328
380
|
/**
|
|
@@ -339,39 +391,6 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
339
391
|
this.restore();
|
|
340
392
|
}
|
|
341
393
|
|
|
342
|
-
/**
|
|
343
|
-
* @ignore
|
|
344
|
-
*/
|
|
345
|
-
drawFont(bounds) {
|
|
346
|
-
var fontContext = this.getFontContext();
|
|
347
|
-
|
|
348
|
-
// Force-upload the new texture
|
|
349
|
-
this.currentCompositor.uploadTexture(this.fontTexture, 0, 0, 0, true);
|
|
350
|
-
|
|
351
|
-
// Add the new quad
|
|
352
|
-
var uvs = this.fontTexture.getUVs(bounds.left + "," + bounds.top + "," + bounds.width + "," + bounds.height);
|
|
353
|
-
this.currentCompositor.addQuad(
|
|
354
|
-
this.fontTexture,
|
|
355
|
-
bounds.left,
|
|
356
|
-
bounds.top,
|
|
357
|
-
bounds.width,
|
|
358
|
-
bounds.height,
|
|
359
|
-
uvs[0],
|
|
360
|
-
uvs[1],
|
|
361
|
-
uvs[2],
|
|
362
|
-
uvs[3],
|
|
363
|
-
this.currentTint.toUint32(this.getGlobalAlpha())
|
|
364
|
-
);
|
|
365
|
-
|
|
366
|
-
// Clear font context2D
|
|
367
|
-
fontContext.clearRect(
|
|
368
|
-
bounds.left,
|
|
369
|
-
bounds.top,
|
|
370
|
-
bounds.width,
|
|
371
|
-
bounds.height
|
|
372
|
-
);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
394
|
/**
|
|
376
395
|
* Draw an image to the gl context
|
|
377
396
|
* @param {Image} image - An element to draw into the context. The specification permits any canvas image source (CanvasImageSource), specifically, a CSSImageValue, an HTMLImageElement, an SVGImageElement, an HTMLVideoElement, an HTMLCanvasElement, an ImageBitmap, or an OffscreenCanvas.
|
|
@@ -417,6 +436,8 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
417
436
|
dy |= 0;
|
|
418
437
|
}
|
|
419
438
|
|
|
439
|
+
this.setCompositor("quad");
|
|
440
|
+
|
|
420
441
|
var texture = this.cache.get(image);
|
|
421
442
|
var uvs = texture.getUVs(sx + "," + sy + "," + sw + "," + sh);
|
|
422
443
|
this.currentCompositor.addQuad(texture, dx, dy, dw, dh, uvs[0], uvs[1], uvs[2], uvs[3], this.currentTint.toUint32(this.getGlobalAlpha()));
|
|
@@ -433,6 +454,7 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
433
454
|
*/
|
|
434
455
|
drawPattern(pattern, x, y, width, height) {
|
|
435
456
|
var uvs = pattern.getUVs("0,0," + width + "," + height);
|
|
457
|
+
this.setCompositor("quad");
|
|
436
458
|
this.currentCompositor.addQuad(pattern, x, y, width, height, uvs[0], uvs[1], uvs[2], uvs[3], this.currentTint.toUint32(this.getGlobalAlpha()));
|
|
437
459
|
}
|
|
438
460
|
|
|
@@ -539,20 +561,6 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
539
561
|
}
|
|
540
562
|
}
|
|
541
563
|
|
|
542
|
-
/**
|
|
543
|
-
* return a reference to the font 2d Context
|
|
544
|
-
* @ignore
|
|
545
|
-
*/
|
|
546
|
-
getFontContext() {
|
|
547
|
-
if (typeof this.fontContext2D === "undefined" ) {
|
|
548
|
-
// warn the end user about performance impact
|
|
549
|
-
console.warn("[WebGL Renderer] WARNING : Using Standard me.Text with WebGL will severly impact performances !");
|
|
550
|
-
// create the font texture if not done yet
|
|
551
|
-
this.createFontTexture(this.cache);
|
|
552
|
-
}
|
|
553
|
-
return this.fontContext2D;
|
|
554
|
-
}
|
|
555
|
-
|
|
556
564
|
/**
|
|
557
565
|
* restores the canvas context
|
|
558
566
|
*/
|
|
@@ -673,10 +681,7 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
673
681
|
* @param {boolean} [fill=false]
|
|
674
682
|
*/
|
|
675
683
|
strokeArc(x, y, radius, start, end, antiClockwise = false, fill = false) {
|
|
676
|
-
|
|
677
|
-
// Fast path: don't draw fully transparent
|
|
678
|
-
return;
|
|
679
|
-
}
|
|
684
|
+
this.setCompositor("primitive");
|
|
680
685
|
this.path2D.beginPath();
|
|
681
686
|
this.path2D.arc(x, y, radius, start, end, antiClockwise);
|
|
682
687
|
if (fill === false) {
|
|
@@ -709,15 +714,12 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
709
714
|
* @param {boolean} [fill=false] - also fill the shape with the current color if true
|
|
710
715
|
*/
|
|
711
716
|
strokeEllipse(x, y, w, h, fill = false) {
|
|
712
|
-
|
|
713
|
-
// Fast path: don't draw fully transparent
|
|
714
|
-
return;
|
|
715
|
-
}
|
|
717
|
+
this.setCompositor("primitive");
|
|
716
718
|
this.path2D.beginPath();
|
|
717
719
|
this.path2D.ellipse(x, y, w, h, 0, 0, 360);
|
|
718
720
|
this.path2D.closePath();
|
|
719
721
|
if (fill === false) {
|
|
720
|
-
this.currentCompositor.drawVertices(this.gl.
|
|
722
|
+
this.currentCompositor.drawVertices(this.gl.LINE_STRIP, this.path2D.points);
|
|
721
723
|
} else {
|
|
722
724
|
this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
|
|
723
725
|
}
|
|
@@ -742,14 +744,11 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
742
744
|
* @param {number} endY - the end y coordinate
|
|
743
745
|
*/
|
|
744
746
|
strokeLine(startX, startY, endX, endY) {
|
|
745
|
-
|
|
746
|
-
// Fast path: don't draw fully transparent
|
|
747
|
-
return;
|
|
748
|
-
}
|
|
747
|
+
this.setCompositor("primitive");
|
|
749
748
|
this.path2D.beginPath();
|
|
750
749
|
this.path2D.moveTo(startX, startY);
|
|
751
750
|
this.path2D.lineTo(endX, endY);
|
|
752
|
-
this.currentCompositor.drawVertices(this.gl.
|
|
751
|
+
this.currentCompositor.drawVertices(this.gl.LINES, this.path2D.points);
|
|
753
752
|
}
|
|
754
753
|
|
|
755
754
|
|
|
@@ -770,22 +769,19 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
770
769
|
* @param {boolean} [fill=false] - also fill the shape with the current color if true
|
|
771
770
|
*/
|
|
772
771
|
strokePolygon(poly, fill = false) {
|
|
773
|
-
|
|
774
|
-
// Fast path: don't draw fully transparent
|
|
775
|
-
return;
|
|
776
|
-
}
|
|
772
|
+
this.setCompositor("primitive");
|
|
777
773
|
this.translate(poly.pos.x, poly.pos.y);
|
|
778
774
|
this.path2D.beginPath();
|
|
779
|
-
|
|
780
|
-
var
|
|
781
|
-
for (var i = 1; i <
|
|
782
|
-
|
|
783
|
-
this.path2D.lineTo(
|
|
775
|
+
|
|
776
|
+
var points = poly.points;
|
|
777
|
+
for (var i = 1; i < points.length; i++) {
|
|
778
|
+
this.path2D.moveTo(points[i-1].x, points[i-1].y);
|
|
779
|
+
this.path2D.lineTo(points[i].x, points[i].y);
|
|
784
780
|
}
|
|
785
|
-
this.path2D.lineTo(
|
|
781
|
+
this.path2D.lineTo(points[points.length - 1].x, points[points.length - 1].y);
|
|
786
782
|
this.path2D.closePath();
|
|
787
783
|
if (fill === false) {
|
|
788
|
-
this.currentCompositor.drawVertices(this.gl.
|
|
784
|
+
this.currentCompositor.drawVertices(this.gl.LINES, this.path2D.points);
|
|
789
785
|
} else {
|
|
790
786
|
// draw all triangles
|
|
791
787
|
this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
|
|
@@ -810,14 +806,11 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
810
806
|
* @param {boolean} [fill=false] - also fill the shape with the current color if true
|
|
811
807
|
*/
|
|
812
808
|
strokeRect(x, y, width, height, fill = false) {
|
|
813
|
-
|
|
814
|
-
// Fast path: don't draw fully transparent
|
|
815
|
-
return;
|
|
816
|
-
}
|
|
809
|
+
this.setCompositor("primitive");
|
|
817
810
|
this.path2D.beginPath();
|
|
818
811
|
this.path2D.rect(x, y, width, height);
|
|
819
812
|
if (fill === false) {
|
|
820
|
-
this.currentCompositor.drawVertices(this.gl.
|
|
813
|
+
this.currentCompositor.drawVertices(this.gl.LINES, this.path2D.points);
|
|
821
814
|
} else {
|
|
822
815
|
this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
|
|
823
816
|
}
|
|
@@ -844,14 +837,11 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
|
|
|
844
837
|
* @param {boolean} [fill=false] - also fill the shape with the current color if true
|
|
845
838
|
*/
|
|
846
839
|
strokeRoundRect(x, y, width, height, radius, fill = false) {
|
|
847
|
-
|
|
848
|
-
// Fast path: don't draw fully transparent
|
|
849
|
-
return;
|
|
850
|
-
}
|
|
840
|
+
this.setCompositor("primitive");
|
|
851
841
|
this.path2D.beginPath();
|
|
852
842
|
this.path2D.roundRect(x, y, width, height, radius);
|
|
853
843
|
if (fill === false) {
|
|
854
|
-
this.currentCompositor.drawVertices(this.gl.
|
|
844
|
+
this.currentCompositor.drawVertices(this.gl.LINE_STRIP, this.path2D.points);
|
|
855
845
|
} else {
|
|
856
846
|
this.path2D.closePath();
|
|
857
847
|
this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
|