melonjs 15.0.0 → 15.1.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/README.md +4 -4
- 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 +7 -3
- 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 +27 -17
- package/dist/melonjs.mjs/application/header.js +6 -5
- package/dist/melonjs.mjs/application/resize.js +20 -20
- package/dist/melonjs.mjs/application/settings.js +1 -1
- package/dist/melonjs.mjs/audio/audio.js +17 -17
- package/dist/melonjs.mjs/camera/camera2d.js +10 -10
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +4 -4
- package/dist/melonjs.mjs/geometries/ellipse.js +6 -6
- package/dist/melonjs.mjs/geometries/line.js +9 -9
- package/dist/melonjs.mjs/geometries/path2d.js +53 -53
- package/dist/melonjs.mjs/geometries/point.js +2 -2
- package/dist/melonjs.mjs/geometries/poly.js +29 -29
- package/dist/melonjs.mjs/geometries/rectangle.js +8 -8
- package/dist/melonjs.mjs/geometries/roundrect.js +6 -6
- package/dist/melonjs.mjs/index.js +5 -5
- package/dist/melonjs.mjs/input/gamepad.js +30 -30
- package/dist/melonjs.mjs/input/input.js +2 -2
- package/dist/melonjs.mjs/input/keyboard.js +15 -15
- package/dist/melonjs.mjs/input/pointer.js +2 -2
- package/dist/melonjs.mjs/input/pointerevent.js +58 -58
- package/dist/melonjs.mjs/lang/console.js +3 -3
- package/dist/melonjs.mjs/lang/deprecated.js +2 -2
- package/dist/melonjs.mjs/level/level.js +9 -9
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +31 -31
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +19 -19
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +15 -15
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +46 -41
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +30 -30
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +21 -21
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +10 -10
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +6 -6
- package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
- package/dist/melonjs.mjs/loader/cache.js +1 -1
- package/dist/melonjs.mjs/loader/loader.js +7 -7
- package/dist/melonjs.mjs/loader/loadingscreen.js +2 -2
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +13 -13
- package/dist/melonjs.mjs/loader/settings.js +3 -3
- package/dist/melonjs.mjs/math/color.js +21 -21
- package/dist/melonjs.mjs/math/math.js +2 -2
- package/dist/melonjs.mjs/math/matrix2.js +22 -22
- package/dist/melonjs.mjs/math/matrix3.js +52 -52
- package/dist/melonjs.mjs/math/observable_vector2.js +12 -12
- package/dist/melonjs.mjs/math/observable_vector3.js +22 -22
- package/dist/melonjs.mjs/math/vector2.js +11 -11
- package/dist/melonjs.mjs/math/vector3.js +21 -21
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +45 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +130 -0
- 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 +2 -2
- 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 +5 -5
- package/dist/melonjs.mjs/particles/particle.js +8 -8
- package/dist/melonjs.mjs/particles/settings.js +3 -3
- package/dist/melonjs.mjs/physics/body.js +17 -17
- package/dist/melonjs.mjs/physics/bounds.js +12 -12
- package/dist/melonjs.mjs/physics/collision.js +3 -3
- package/dist/melonjs.mjs/physics/detector.js +14 -14
- package/dist/melonjs.mjs/physics/quadtree.js +19 -19
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +60 -60
- package/dist/melonjs.mjs/physics/world.js +4 -4
- package/dist/melonjs.mjs/plugin/plugin.js +11 -11
- package/dist/melonjs.mjs/renderable/collectable.js +2 -2
- package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
- package/dist/melonjs.mjs/renderable/container.js +77 -59
- package/dist/melonjs.mjs/renderable/dragndrop.js +5 -5
- package/dist/melonjs.mjs/renderable/imagelayer.js +7 -6
- package/dist/melonjs.mjs/renderable/light2d.js +6 -6
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +12 -12
- package/dist/melonjs.mjs/renderable/renderable.js +11 -11
- package/dist/melonjs.mjs/renderable/sprite.js +25 -25
- package/dist/melonjs.mjs/renderable/trigger.js +11 -9
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +97 -27
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +25 -25
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +83 -63
- package/dist/melonjs.mjs/state/stage.js +7 -7
- package/dist/melonjs.mjs/state/state.js +15 -15
- 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 +2 -2
- package/dist/melonjs.mjs/system/platform.js +1 -1
- package/dist/melonjs.mjs/system/pooling.js +9 -9
- package/dist/melonjs.mjs/system/save.js +6 -6
- package/dist/melonjs.mjs/system/timer.js +16 -12
- package/dist/melonjs.mjs/text/bitmaptext.js +20 -20
- package/dist/melonjs.mjs/text/bitmaptextdata.js +22 -22
- package/dist/melonjs.mjs/text/glyph.js +3 -3
- package/dist/melonjs.mjs/text/text.js +10 -9
- package/dist/melonjs.mjs/text/textmetrics.js +15 -15
- package/dist/melonjs.mjs/text/textstyle.js +1 -1
- package/dist/melonjs.mjs/tweens/easing.js +4 -4
- package/dist/melonjs.mjs/tweens/interpolation.js +8 -8
- package/dist/melonjs.mjs/tweens/tween.js +11 -11
- package/dist/melonjs.mjs/utils/agent.js +6 -6
- package/dist/melonjs.mjs/utils/array.js +4 -4
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +5 -5
- package/dist/melonjs.mjs/utils/string.js +3 -3
- package/dist/melonjs.mjs/utils/utils.js +16 -16
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +35 -109
- package/dist/melonjs.mjs/video/renderer.js +74 -7
- package/dist/melonjs.mjs/video/texture/atlas.js +37 -37
- package/dist/melonjs.mjs/video/texture/cache.js +9 -10
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +63 -3
- 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 +3 -3
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +5 -5
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +5 -5
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +18 -15
- package/dist/melonjs.mjs/video/webgl/glshader.js +7 -7
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/attributes.js +2 -2
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/program.js +7 -7
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +4 -4
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +55 -38
- package/dist/melonjs.module.js +1747 -1809
- package/dist/types/application/application.d.ts +11 -8
- package/dist/types/audio/audio.d.ts +3 -3
- package/dist/types/index.d.ts +4 -3
- package/dist/types/input/input.d.ts +1 -1
- package/dist/types/input/keyboard.d.ts +1 -1
- package/dist/types/input/pointerevent.d.ts +6 -6
- package/dist/types/level/level.d.ts +2 -2
- package/dist/types/level/tiled/TMXLayer.d.ts +4 -4
- package/dist/types/level/tiled/TMXTileMap.d.ts +2 -2
- package/dist/types/level/tiled/TMXUtils.d.ts +5 -4
- package/dist/types/loader/loader.d.ts +2 -2
- package/dist/types/loader/settings.d.ts +2 -2
- package/dist/types/particles/emitter.d.ts +1 -1
- package/dist/types/physics/collision.d.ts +1 -1
- package/dist/types/physics/detector.d.ts +1 -1
- package/dist/types/plugin/plugin.d.ts +2 -2
- package/dist/types/renderable/container.d.ts +21 -17
- package/dist/types/renderable/sprite.d.ts +11 -11
- package/dist/types/renderable/trigger.d.ts +1 -1
- package/dist/types/renderable/ui/uibaseelement.d.ts +28 -6
- package/dist/types/renderable/ui/uispriteelement.d.ts +12 -14
- package/dist/types/renderable/ui/uitextbutton.d.ts +52 -11
- package/dist/types/state/stage.d.ts +1 -1
- package/dist/types/system/device.d.ts +1 -1
- package/dist/types/system/pooling.d.ts +3 -3
- package/dist/types/system/timer.d.ts +5 -5
- package/dist/types/text/bitmaptext.d.ts +1 -1
- package/dist/types/text/text.d.ts +1 -1
- package/dist/types/utils/array.d.ts +2 -2
- package/dist/types/video/canvas/canvas_renderer.d.ts +8 -76
- package/dist/types/video/renderer.d.ts +48 -0
- package/dist/types/video/texture/atlas.d.ts +3 -3
- package/dist/types/video/texture/canvas_texture.d.ts +40 -0
- package/dist/types/video/webgl/glshader.d.ts +1 -1
- package/dist/types/video/webgl/webgl_renderer.d.ts +13 -9
- package/package.json +14 -14
- package/src/application/application.js +26 -16
- package/src/application/header.js +5 -4
- package/src/application/resize.js +19 -19
- package/src/audio/audio.js +16 -16
- package/src/camera/camera2d.js +9 -9
- package/src/entity/entity.js +3 -3
- package/src/geometries/ellipse.js +5 -5
- package/src/geometries/line.js +8 -8
- package/src/geometries/path2d.js +52 -52
- package/src/geometries/point.js +1 -1
- package/src/geometries/poly.js +28 -28
- package/src/geometries/rectangle.js +7 -7
- package/src/geometries/roundrect.js +5 -5
- package/src/index.js +3 -2
- package/src/input/gamepad.js +29 -29
- package/src/input/input.js +1 -1
- package/src/input/keyboard.js +14 -14
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +52 -52
- package/src/lang/console.js +2 -2
- package/src/lang/deprecated.js +1 -1
- package/src/level/level.js +8 -8
- package/src/level/tiled/TMXGroup.js +2 -2
- package/src/level/tiled/TMXLayer.js +30 -30
- package/src/level/tiled/TMXObject.js +7 -7
- package/src/level/tiled/TMXTile.js +7 -7
- package/src/level/tiled/TMXTileMap.js +18 -18
- package/src/level/tiled/TMXTileset.js +14 -14
- package/src/level/tiled/TMXTilesetGroup.js +2 -2
- package/src/level/tiled/TMXUtils.js +45 -40
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +29 -29
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +20 -20
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +9 -9
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +5 -5
- package/src/loader/loader.js +6 -6
- package/src/loader/loadingscreen.js +1 -1
- package/src/loader/parser.js +12 -12
- package/src/loader/settings.js +2 -2
- package/src/math/color.js +20 -20
- package/src/math/math.js +1 -1
- package/src/math/matrix2.js +21 -21
- package/src/math/matrix3.js +51 -51
- package/src/math/observable_vector2.js +11 -11
- package/src/math/observable_vector3.js +21 -21
- package/src/math/vector2.js +10 -10
- package/src/math/vector3.js +20 -20
- package/src/particles/emitter.js +4 -4
- package/src/particles/particle.js +7 -7
- package/src/particles/settings.js +2 -2
- package/src/physics/body.js +16 -16
- package/src/physics/bounds.js +11 -11
- package/src/physics/collision.js +2 -2
- package/src/physics/detector.js +13 -13
- package/src/physics/quadtree.js +18 -18
- package/src/physics/sat.js +59 -59
- package/src/physics/world.js +3 -3
- package/src/plugin/plugin.js +8 -8
- package/src/renderable/collectable.js +1 -1
- package/src/renderable/container.js +76 -58
- package/src/renderable/dragndrop.js +4 -4
- package/src/renderable/imagelayer.js +6 -5
- package/src/renderable/light2d.js +5 -5
- package/src/renderable/nineslicesprite.js +11 -11
- package/src/renderable/renderable.js +10 -10
- package/src/renderable/sprite.js +24 -24
- package/src/renderable/trigger.js +10 -8
- package/src/renderable/ui/uibaseelement.js +96 -26
- package/src/renderable/ui/uispriteelement.js +24 -24
- package/src/renderable/ui/uitextbutton.js +85 -65
- package/src/state/stage.js +6 -6
- package/src/state/state.js +14 -14
- package/src/system/device.js +1 -1
- package/src/system/event.js +1 -1
- package/src/system/pooling.js +8 -8
- package/src/system/save.js +5 -5
- package/src/system/timer.js +15 -11
- package/src/text/bitmaptext.js +19 -19
- package/src/text/bitmaptextdata.js +21 -21
- package/src/text/glyph.js +2 -2
- package/src/text/text.js +9 -8
- package/src/text/textmetrics.js +14 -14
- package/src/tweens/easing.js +3 -3
- package/src/tweens/interpolation.js +7 -7
- package/src/tweens/tween.js +10 -10
- package/src/utils/agent.js +5 -5
- package/src/utils/array.js +3 -3
- package/src/utils/function.js +4 -4
- package/src/utils/string.js +2 -2
- package/src/utils/utils.js +15 -15
- package/src/video/canvas/canvas_renderer.js +34 -108
- package/src/video/renderer.js +72 -5
- package/src/video/texture/atlas.js +36 -36
- package/src/video/texture/cache.js +6 -6
- package/src/video/texture/canvas_texture.js +62 -2
- package/src/video/video.js +1 -1
- package/src/video/webgl/buffer/vertex.js +2 -2
- package/src/video/webgl/compositors/compositor.js +4 -4
- package/src/video/webgl/compositors/primitive_compositor.js +4 -4
- package/src/video/webgl/compositors/quad_compositor.js +17 -14
- package/src/video/webgl/glshader.js +6 -6
- package/src/video/webgl/utils/attributes.js +1 -1
- package/src/video/webgl/utils/program.js +6 -6
- package/src/video/webgl/utils/uniforms.js +3 -3
- package/src/video/webgl/webgl_renderer.js +54 -37
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v15.
|
|
2
|
+
* melonJS Game Engine - v15.1.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
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @ignore
|
|
10
10
|
*/
|
|
11
11
|
function compileShader(gl, type, source) {
|
|
12
|
-
|
|
12
|
+
let shader = gl.createShader(type);
|
|
13
13
|
gl.shaderSource(shader, source);
|
|
14
14
|
gl.compileShader(shader);
|
|
15
15
|
|
|
@@ -25,10 +25,10 @@ function compileShader(gl, type, source) {
|
|
|
25
25
|
* @ignore
|
|
26
26
|
*/
|
|
27
27
|
function compileProgram(gl, vertex, fragment, attributes) {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
let vertShader = compileShader(gl, gl.VERTEX_SHADER, vertex);
|
|
29
|
+
let fragShader = compileShader(gl, gl.FRAGMENT_SHADER, fragment);
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
let program = gl.createProgram();
|
|
32
32
|
|
|
33
33
|
gl.attachShader(program, vertShader);
|
|
34
34
|
gl.attachShader(program, fragShader);
|
|
@@ -36,14 +36,14 @@ function compileProgram(gl, vertex, fragment, attributes) {
|
|
|
36
36
|
|
|
37
37
|
// force vertex attributes to use location 0 as starting location to prevent
|
|
38
38
|
// browser to do complicated emulation when running on desktop OpenGL (e.g. on macOS)
|
|
39
|
-
for (
|
|
39
|
+
for (let location in attributes) {
|
|
40
40
|
gl.bindAttribLocation(program, attributes[location], location);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
gl.linkProgram(program);
|
|
44
44
|
|
|
45
45
|
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
46
|
-
|
|
46
|
+
let error_msg =
|
|
47
47
|
"Error initializing Shader " + this + "\n" +
|
|
48
48
|
"gl.VALIDATE_STATUS: " + gl.getProgramParameter(program, gl.VALIDATE_STATUS) + "\n" +
|
|
49
49
|
"gl.getError()" + gl.getError() + "\n" +
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v15.
|
|
2
|
+
* melonJS Game Engine - v15.1.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
|
|
@@ -32,7 +32,7 @@ const fnHash = {
|
|
|
32
32
|
* @ignore
|
|
33
33
|
*/
|
|
34
34
|
function extractUniforms(gl, shader) {
|
|
35
|
-
|
|
35
|
+
let uniforms = {},
|
|
36
36
|
uniRx = /uniform\s+(\w+)\s+(\w+)/g,
|
|
37
37
|
uniformsData = {},
|
|
38
38
|
descriptor = {},
|
|
@@ -48,7 +48,7 @@ function extractUniforms(gl, shader) {
|
|
|
48
48
|
|
|
49
49
|
// Get uniform references
|
|
50
50
|
Object.keys(uniformsData).forEach((name) => {
|
|
51
|
-
|
|
51
|
+
let type = uniformsData[name];
|
|
52
52
|
locations[name] = gl.getUniformLocation(shader.program, name);
|
|
53
53
|
|
|
54
54
|
descriptor[name] = {
|
|
@@ -74,7 +74,7 @@ function extractUniforms(gl, shader) {
|
|
|
74
74
|
* A generic setter for uniform vectors
|
|
75
75
|
*/
|
|
76
76
|
return function (val) {
|
|
77
|
-
|
|
77
|
+
let fnv = fn;
|
|
78
78
|
if (val.length && fn.slice(-1) !== "v") {
|
|
79
79
|
fnv += "v";
|
|
80
80
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v15.
|
|
2
|
+
* melonJS Game Engine - v15.1.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
|
|
@@ -34,6 +34,7 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
34
34
|
* @param {boolean} [options.premultipliedAlpha=true] - in WebGL, whether the renderer will assume that colors have premultiplied alpha when canvas transparency is enabled
|
|
35
35
|
* @param {boolean} [options.subPixel=false] - Whether to enable subpixel renderering (performance hit when enabled)
|
|
36
36
|
* @param {boolean} [options.preferWebGL1=false] - if true the renderer will only use WebGL 1
|
|
37
|
+
* @param {boolean} [options.depthTest="sorting"] - ~Experimental~ the default method to sort object on the z axis in WebGL ("sorting", "z-buffer")
|
|
37
38
|
* @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.
|
|
38
39
|
* @param {number} [options.zoomX=width] - The actual width of the canvas with scaling applied
|
|
39
40
|
* @param {number} [options.zoomY=height] - The actual height of the canvas with scaling applied
|
|
@@ -72,7 +73,7 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
72
73
|
* @name gl
|
|
73
74
|
* @type {WebGLRenderingContext}
|
|
74
75
|
*/
|
|
75
|
-
this.context = this.gl = this.getContextGL(this.getCanvas(), options.transparent);
|
|
76
|
+
this.context = this.gl = this.getContextGL(this.getCanvas(), options.transparent, options.depthTest === "z-buffer");
|
|
76
77
|
|
|
77
78
|
/**
|
|
78
79
|
* the vertex buffer used by this WebGL Renderer
|
|
@@ -138,9 +139,20 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
138
139
|
this.addCompositor(new (this.settings.compositor || QuadCompositor)(this), "quad", true);
|
|
139
140
|
this.addCompositor(new (this.settings.compositor || PrimitiveCompositor)(this), "primitive");
|
|
140
141
|
|
|
142
|
+
// depth Test settings
|
|
143
|
+
this.depthTest = options.depthTest;
|
|
141
144
|
|
|
142
145
|
// default WebGL state(s)
|
|
143
|
-
|
|
146
|
+
if (this.depthTest === "z-buffer") {
|
|
147
|
+
this.gl.enable(this.gl.DEPTH_TEST);
|
|
148
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/depthFunc
|
|
149
|
+
this.gl.depthFunc(this.gl.LEQUAL);
|
|
150
|
+
this.gl.depthMask(true);
|
|
151
|
+
} else {
|
|
152
|
+
this.gl.disable(this.gl.DEPTH_TEST);
|
|
153
|
+
this.gl.depthMask(false);
|
|
154
|
+
}
|
|
155
|
+
|
|
144
156
|
this.gl.disable(this.gl.SCISSOR_TEST);
|
|
145
157
|
this.gl.enable(this.gl.BLEND);
|
|
146
158
|
|
|
@@ -148,7 +160,7 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
148
160
|
this.setBlendMode(this.settings.blendMode);
|
|
149
161
|
|
|
150
162
|
// get GPU vendor and renderer
|
|
151
|
-
|
|
163
|
+
let debugInfo = this.gl.getExtension("WEBGL_debug_renderer_info");
|
|
152
164
|
if (debugInfo !== null) {
|
|
153
165
|
this.GPUVendor = this.gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);
|
|
154
166
|
this.GPURenderer = this.gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
|
|
@@ -165,7 +177,7 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
165
177
|
this.type = "WebGL" + this.WebGLVersion;
|
|
166
178
|
|
|
167
179
|
// to simulate context lost and restore in WebGL:
|
|
168
|
-
//
|
|
180
|
+
// let ctx = me.video.renderer.context.getExtension('WEBGL_lose_context');
|
|
169
181
|
// ctx.loseContext()
|
|
170
182
|
this.getCanvas().addEventListener("webglcontextlost", (e) => {
|
|
171
183
|
e.preventDefault();
|
|
@@ -288,29 +300,29 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
288
300
|
|
|
289
301
|
/**
|
|
290
302
|
* Create a pattern with the specified repetition
|
|
291
|
-
* @param {
|
|
303
|
+
* @param {HTMLImageElement|SVGImageElement|HTMLVideoElement|HTMLCanvasElement|ImageBitmap|OffscreenCanvas|VideoFrame} image - Source image to be used as the pattern's image
|
|
292
304
|
* @param {string} repeat - Define how the pattern should be repeated
|
|
293
305
|
* @returns {TextureAtlas}
|
|
294
306
|
* @see ImageLayer#repeat
|
|
295
307
|
* @example
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
308
|
+
* let tileable = renderer.createPattern(image, "repeat");
|
|
309
|
+
* let horizontal = renderer.createPattern(image, "repeat-x");
|
|
310
|
+
* let vertical = renderer.createPattern(image, "repeat-y");
|
|
311
|
+
* let basic = renderer.createPattern(image, "no-repeat");
|
|
300
312
|
*/
|
|
301
313
|
createPattern(image, repeat) {
|
|
302
314
|
|
|
303
315
|
this.setCompositor("quad");
|
|
304
316
|
|
|
305
317
|
if (renderer.WebGLVersion === 1 && (!isPowerOfTwo(image.width) || !isPowerOfTwo(image.height))) {
|
|
306
|
-
|
|
318
|
+
let src = typeof image.src !== "undefined" ? image.src : image;
|
|
307
319
|
throw new Error(
|
|
308
320
|
"[WebGL Renderer] " + src + " is not a POT texture " +
|
|
309
321
|
"(" + image.width + "x" + image.height + ")"
|
|
310
322
|
);
|
|
311
323
|
}
|
|
312
324
|
|
|
313
|
-
|
|
325
|
+
let texture = new TextureAtlas(createAtlas(image.width, image.height, "pattern", repeat), image);
|
|
314
326
|
|
|
315
327
|
// FIXME: Remove old cache entry and texture when changing the repeat mode
|
|
316
328
|
this.currentCompositor.uploadTexture(texture);
|
|
@@ -349,9 +361,13 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
349
361
|
* Clear the frame buffer
|
|
350
362
|
*/
|
|
351
363
|
clear() {
|
|
352
|
-
|
|
364
|
+
let gl = this.gl;
|
|
353
365
|
gl.clearColor(0, 0, 0, this.settings.transparent ? 0.0 : 1.0);
|
|
354
|
-
|
|
366
|
+
if (this.depthTest === "z-buffer") {
|
|
367
|
+
gl.clear(gl.DEPTH_BUFFER_BIT | gl.COLOR_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
|
|
368
|
+
} else {
|
|
369
|
+
gl.clear(gl.COLOR_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
|
|
370
|
+
}
|
|
355
371
|
}
|
|
356
372
|
|
|
357
373
|
/**
|
|
@@ -360,13 +376,13 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
360
376
|
* @param {boolean} [opaque=false] - Allow transparency [default] or clear the surface completely [true]
|
|
361
377
|
*/
|
|
362
378
|
clearColor(color = "#000000", opaque = false) {
|
|
363
|
-
|
|
364
|
-
|
|
379
|
+
let glArray;
|
|
380
|
+
let gl = this.gl;
|
|
365
381
|
|
|
366
382
|
if (color instanceof Color) {
|
|
367
383
|
glArray = color.toArray();
|
|
368
384
|
} else {
|
|
369
|
-
|
|
385
|
+
let _color = pool.pull("me.Color");
|
|
370
386
|
// reuse temporary the renderer default color object
|
|
371
387
|
glArray = _color.parseCSS(color).toArray();
|
|
372
388
|
pool.push(_color);
|
|
@@ -393,7 +409,7 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
393
409
|
|
|
394
410
|
/**
|
|
395
411
|
* Draw an image to the gl context
|
|
396
|
-
* @param {
|
|
412
|
+
* @param {HTMLImageElement|SVGImageElement|HTMLVideoElement|HTMLCanvasElement|ImageBitmap|OffscreenCanvas|VideoFrame} image - An element to draw into the context.
|
|
397
413
|
* @param {number} sx - The X coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.
|
|
398
414
|
* @param {number} sy - The Y coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.
|
|
399
415
|
* @param {number} sw - The width of the sub-rectangle of the source image to draw into the destination context. If not specified, the entire rectangle from the coordinates specified by sx and sy to the bottom-right corner of the image is used.
|
|
@@ -438,8 +454,8 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
438
454
|
|
|
439
455
|
this.setCompositor("quad");
|
|
440
456
|
|
|
441
|
-
|
|
442
|
-
|
|
457
|
+
let texture = this.cache.get(image);
|
|
458
|
+
let uvs = texture.getUVs(sx + "," + sy + "," + sw + "," + sh);
|
|
443
459
|
this.currentCompositor.addQuad(texture, dx, dy, dw, dh, uvs[0], uvs[1], uvs[2], uvs[3], this.currentTint.toUint32(this.getGlobalAlpha()));
|
|
444
460
|
}
|
|
445
461
|
|
|
@@ -453,7 +469,7 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
453
469
|
* @see WebGLRenderer#createPattern
|
|
454
470
|
*/
|
|
455
471
|
drawPattern(pattern, x, y, width, height) {
|
|
456
|
-
|
|
472
|
+
let uvs = pattern.getUVs("0,0," + width + "," + height);
|
|
457
473
|
this.setCompositor("quad");
|
|
458
474
|
this.currentCompositor.addQuad(pattern, x, y, width, height, uvs[0], uvs[1], uvs[2], uvs[3], this.currentTint.toUint32(this.getGlobalAlpha()));
|
|
459
475
|
}
|
|
@@ -462,9 +478,10 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
462
478
|
* Returns the WebGL Context object of the given canvas element
|
|
463
479
|
* @param {HTMLCanvasElement} canvas
|
|
464
480
|
* @param {boolean} [transparent=false] - use true to enable transparency
|
|
481
|
+
* @param {boolean} [depth=false] - use true to enable depth buffer testing
|
|
465
482
|
* @returns {WebGLRenderingContext}
|
|
466
483
|
*/
|
|
467
|
-
getContextGL(canvas, transparent = false) {
|
|
484
|
+
getContextGL(canvas, transparent = false, depth = false) {
|
|
468
485
|
if (typeof canvas === "undefined" || canvas === null) {
|
|
469
486
|
throw new Error(
|
|
470
487
|
"You must pass a canvas element in order to create " +
|
|
@@ -472,10 +489,10 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
472
489
|
);
|
|
473
490
|
}
|
|
474
491
|
|
|
475
|
-
|
|
492
|
+
let attr = {
|
|
476
493
|
alpha : transparent,
|
|
477
494
|
antialias : this.settings.antiAlias,
|
|
478
|
-
depth :
|
|
495
|
+
depth : depth,
|
|
479
496
|
stencil: true,
|
|
480
497
|
preserveDrawingBuffer : false,
|
|
481
498
|
premultipliedAlpha: transparent ? this.settings.premultipliedAlpha : false,
|
|
@@ -483,7 +500,7 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
483
500
|
failIfMajorPerformanceCaveat : this.settings.failIfMajorPerformanceCaveat
|
|
484
501
|
};
|
|
485
502
|
|
|
486
|
-
|
|
503
|
+
let gl;
|
|
487
504
|
|
|
488
505
|
// attempt to create a WebGL2 context if requested
|
|
489
506
|
if (this.settings.preferWebGL1 === false) {
|
|
@@ -567,8 +584,8 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
567
584
|
restore() {
|
|
568
585
|
// do nothing if there is no saved states
|
|
569
586
|
if (this._matrixStack.length !== 0) {
|
|
570
|
-
|
|
571
|
-
|
|
587
|
+
let color = this._colorStack.pop();
|
|
588
|
+
let matrix = this._matrixStack.pop();
|
|
572
589
|
|
|
573
590
|
// restore the previous context
|
|
574
591
|
this.currentColor.copy(color);
|
|
@@ -657,7 +674,7 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
657
674
|
* @param {Color|string} color - css color string.
|
|
658
675
|
*/
|
|
659
676
|
setColor(color) {
|
|
660
|
-
|
|
677
|
+
let alpha = this.currentColor.alpha;
|
|
661
678
|
this.currentColor.copy(color);
|
|
662
679
|
this.currentColor.alpha *= alpha;
|
|
663
680
|
}
|
|
@@ -773,8 +790,8 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
773
790
|
this.translate(poly.pos.x, poly.pos.y);
|
|
774
791
|
this.path2D.beginPath();
|
|
775
792
|
|
|
776
|
-
|
|
777
|
-
for (
|
|
793
|
+
let points = poly.points;
|
|
794
|
+
for (let i = 1; i < points.length; i++) {
|
|
778
795
|
this.path2D.moveTo(points[i-1].x, points[i-1].y);
|
|
779
796
|
this.path2D.lineTo(points[i].x, points[i].y);
|
|
780
797
|
}
|
|
@@ -895,11 +912,11 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
895
912
|
* @param {Matrix2d} mat2d - Matrix to transform by
|
|
896
913
|
*/
|
|
897
914
|
transform(mat2d) {
|
|
898
|
-
|
|
915
|
+
let currentTransform = this.currentTransform;
|
|
899
916
|
currentTransform.multiply(mat2d);
|
|
900
917
|
if (this.settings.subPixel === false) {
|
|
901
918
|
// snap position values to pixel grid
|
|
902
|
-
|
|
919
|
+
let a = currentTransform.toArray();
|
|
903
920
|
a[6] |= 0;
|
|
904
921
|
a[7] |= 0;
|
|
905
922
|
}
|
|
@@ -911,11 +928,11 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
911
928
|
* @param {number} y
|
|
912
929
|
*/
|
|
913
930
|
translate(x, y) {
|
|
914
|
-
|
|
931
|
+
let currentTransform = this.currentTransform;
|
|
915
932
|
currentTransform.translate(x, y);
|
|
916
933
|
if (this.settings.subPixel === false) {
|
|
917
934
|
// snap position values to pixel grid
|
|
918
|
-
|
|
935
|
+
let a = currentTransform.toArray();
|
|
919
936
|
a[6] |= 0;
|
|
920
937
|
a[7] |= 0;
|
|
921
938
|
}
|
|
@@ -933,11 +950,11 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
933
950
|
* @param {number} height
|
|
934
951
|
*/
|
|
935
952
|
clipRect(x, y, width, height) {
|
|
936
|
-
|
|
937
|
-
|
|
953
|
+
let canvas = this.getCanvas();
|
|
954
|
+
let gl = this.gl;
|
|
938
955
|
// if requested box is different from the current canvas size
|
|
939
956
|
if (x !== 0 || y !== 0 || width !== canvas.width || height !== canvas.height) {
|
|
940
|
-
|
|
957
|
+
let currentScissor = this.currentScissor;
|
|
941
958
|
if (gl.isEnabled(gl.SCISSOR_TEST)) {
|
|
942
959
|
// if same as the current scissor box do nothing
|
|
943
960
|
if (currentScissor[0] === x && currentScissor[1] === y &&
|
|
@@ -976,7 +993,7 @@ import { isPowerOfTwo } from '../../math/math.js';
|
|
|
976
993
|
* @param {boolean} [invert=false] - either the given shape should define what is visible (default) or the opposite
|
|
977
994
|
*/
|
|
978
995
|
setMask(mask, invert = false) {
|
|
979
|
-
|
|
996
|
+
let gl = this.gl;
|
|
980
997
|
|
|
981
998
|
// flush the compositor
|
|
982
999
|
this.flush();
|