melonjs 14.5.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/LICENSE.md +1 -1
- package/README.md +6 -6
- 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 +18 -20
- 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 +56 -56
- 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 +8 -6
- 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 +59 -59
- 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 +25 -24
- 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 +35 -13
- 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 -65
- 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 +3 -3
- 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 +63 -92
- package/dist/melonjs.mjs/text/textmetrics.js +15 -15
- package/dist/melonjs.mjs/text/textstyle.js +4 -6
- 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 +41 -119
- package/dist/melonjs.mjs/video/renderer.js +70 -14
- package/dist/melonjs.mjs/video/texture/atlas.js +39 -45
- 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 +23 -19
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +80 -80
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +77 -0
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +252 -0
- package/dist/melonjs.mjs/video/webgl/compositors/webgl_compositor.js +1 -1
- 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 +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 +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 +188 -181
- package/dist/melonjs.module.js +25040 -25193
- package/dist/types/application/application.d.ts +11 -8
- package/dist/types/audio/audio.d.ts +3 -3
- package/dist/types/entity/entity.d.ts +1 -1
- package/dist/types/index.d.ts +7 -4
- 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/renderable.d.ts +6 -0
- 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 -12
- 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 +7 -21
- package/dist/types/text/textstyle.d.ts +1 -1
- package/dist/types/utils/array.d.ts +2 -2
- package/dist/types/video/canvas/canvas_renderer.d.ts +8 -81
- package/dist/types/video/renderer.d.ts +48 -4
- 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/buffer/vertex.d.ts +3 -3
- package/dist/types/video/webgl/compositors/compositor.d.ts +38 -32
- 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/glshader.d.ts +1 -1
- package/dist/types/video/webgl/webgl_renderer.d.ts +47 -37
- package/package.json +16 -17
- 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 +17 -19
- 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 +55 -55
- 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 +9 -4
- 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 +24 -23
- 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/polyfill/index.js +0 -2
- 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 +34 -12
- 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 -67
- package/src/state/stage.js +6 -6
- package/src/state/state.js +14 -14
- package/src/system/device.js +2 -2
- 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 +62 -91
- package/src/text/textmetrics.js +14 -14
- package/src/text/textstyle.js +3 -5
- 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 +39 -117
- package/src/video/renderer.js +68 -12
- package/src/video/texture/atlas.js +38 -44
- 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 +22 -18
- package/src/video/webgl/compositors/compositor.js +79 -80
- package/src/video/webgl/compositors/primitive_compositor.js +68 -0
- package/src/video/webgl/compositors/{webgl_compositor.js → quad_compositor.js} +52 -109
- package/src/video/webgl/glshader.js +6 -6
- package/src/video/webgl/shaders/primitive.vert +2 -5
- package/src/video/webgl/shaders/quad.vert +3 -1
- 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 +186 -179
- 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/dist/melonjs.mjs/video/webgl/webgl_compositor.js +0 -494
- package/src/polyfill/performance.js +0 -20
- package/src/polyfill/requestAnimationFrame.js +0 -39
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import Color from "./../../math/color.js";
|
|
2
2
|
import Matrix2d from "./../../math/matrix2.js";
|
|
3
|
-
import
|
|
3
|
+
import QuadCompositor from "./compositors/quad_compositor";
|
|
4
|
+
import PrimitiveCompositor from "./compositors/primitive_compositor";
|
|
4
5
|
import Renderer from "./../renderer.js";
|
|
5
6
|
import TextureCache from "./../texture/cache.js";
|
|
6
7
|
import { TextureAtlas, createAtlas } from "./../texture/atlas.js";
|
|
7
|
-
import {
|
|
8
|
+
import { renderer } from "./../video.js";
|
|
8
9
|
import * as event from "./../../system/event.js";
|
|
9
10
|
import pool from "./../../system/pooling.js";
|
|
10
|
-
import { isPowerOfTwo
|
|
11
|
+
import { isPowerOfTwo } from "./../../math/math.js";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* @classdesc
|
|
@@ -26,13 +27,13 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
26
27
|
* @param {boolean} [options.premultipliedAlpha=true] - in WebGL, whether the renderer will assume that colors have premultiplied alpha when canvas transparency is enabled
|
|
27
28
|
* @param {boolean} [options.subPixel=false] - Whether to enable subpixel renderering (performance hit when enabled)
|
|
28
29
|
* @param {boolean} [options.preferWebGL1=false] - if true the renderer will only use WebGL 1
|
|
30
|
+
* @param {boolean} [options.depthTest="sorting"] - ~Experimental~ the default method to sort object on the z axis in WebGL ("sorting", "z-buffer")
|
|
29
31
|
* @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.
|
|
30
32
|
* @param {number} [options.zoomX=width] - The actual width of the canvas with scaling applied
|
|
31
33
|
* @param {number} [options.zoomY=height] - The actual height of the canvas with scaling applied
|
|
32
|
-
* @param {
|
|
34
|
+
* @param {Compositor} [options.compositor] - A class that implements the compositor API for sprite rendering
|
|
33
35
|
*/
|
|
34
36
|
constructor(options) {
|
|
35
|
-
|
|
36
37
|
// parent contructor
|
|
37
38
|
super(options);
|
|
38
39
|
|
|
@@ -47,25 +48,31 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
47
48
|
/**
|
|
48
49
|
* The vendor string of the underlying graphics driver.
|
|
49
50
|
* @type {string}
|
|
50
|
-
* @default
|
|
51
|
+
* @default undefined
|
|
51
52
|
* @readonly
|
|
52
53
|
*/
|
|
53
|
-
this.GPUVendor =
|
|
54
|
+
this.GPUVendor = undefined;
|
|
54
55
|
|
|
55
56
|
/**
|
|
56
57
|
* The renderer string of the underlying graphics driver.
|
|
57
58
|
* @type {string}
|
|
58
|
-
* @default
|
|
59
|
+
* @default undefined
|
|
59
60
|
* @readonly
|
|
60
61
|
*/
|
|
61
|
-
this.GPURenderer =
|
|
62
|
+
this.GPURenderer = undefined;
|
|
62
63
|
|
|
63
64
|
/**
|
|
64
65
|
* The WebGL context
|
|
65
66
|
* @name gl
|
|
66
67
|
* @type {WebGLRenderingContext}
|
|
67
68
|
*/
|
|
68
|
-
this.context = this.gl = this.getContextGL(this.getCanvas(), options.transparent);
|
|
69
|
+
this.context = this.gl = this.getContextGL(this.getCanvas(), options.transparent, options.depthTest === "z-buffer");
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* the vertex buffer used by this WebGL Renderer
|
|
73
|
+
* @type {WebGLBuffer}
|
|
74
|
+
*/
|
|
75
|
+
this.vertexBuffer = this.gl.createBuffer();
|
|
69
76
|
|
|
70
77
|
/**
|
|
71
78
|
* Maximum number of texture unit supported under the current context
|
|
@@ -104,7 +111,13 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
104
111
|
* The current compositor used by the renderer
|
|
105
112
|
* @type {WebGLCompositor}
|
|
106
113
|
*/
|
|
107
|
-
this.currentCompositor =
|
|
114
|
+
this.currentCompositor = undefined;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* a reference to the current shader program used by the renderer
|
|
118
|
+
* @type {WebGLProgram}
|
|
119
|
+
*/
|
|
120
|
+
this.currentProgram = undefined;
|
|
108
121
|
|
|
109
122
|
/**
|
|
110
123
|
* The list of active compositors
|
|
@@ -112,14 +125,27 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
112
125
|
*/
|
|
113
126
|
this.compositors = new Map();
|
|
114
127
|
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
128
|
+
// bind the vertex buffer
|
|
129
|
+
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.vertexBuffer);
|
|
130
|
+
|
|
131
|
+
// Create both quad and primitive compositor
|
|
132
|
+
this.addCompositor(new (this.settings.compositor || QuadCompositor)(this), "quad", true);
|
|
133
|
+
this.addCompositor(new (this.settings.compositor || PrimitiveCompositor)(this), "primitive");
|
|
119
134
|
|
|
135
|
+
// depth Test settings
|
|
136
|
+
this.depthTest = options.depthTest;
|
|
120
137
|
|
|
121
138
|
// default WebGL state(s)
|
|
122
|
-
|
|
139
|
+
if (this.depthTest === "z-buffer") {
|
|
140
|
+
this.gl.enable(this.gl.DEPTH_TEST);
|
|
141
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/depthFunc
|
|
142
|
+
this.gl.depthFunc(this.gl.LEQUAL);
|
|
143
|
+
this.gl.depthMask(true);
|
|
144
|
+
} else {
|
|
145
|
+
this.gl.disable(this.gl.DEPTH_TEST);
|
|
146
|
+
this.gl.depthMask(false);
|
|
147
|
+
}
|
|
148
|
+
|
|
123
149
|
this.gl.disable(this.gl.SCISSOR_TEST);
|
|
124
150
|
this.gl.enable(this.gl.BLEND);
|
|
125
151
|
|
|
@@ -127,12 +153,16 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
127
153
|
this.setBlendMode(this.settings.blendMode);
|
|
128
154
|
|
|
129
155
|
// get GPU vendor and renderer
|
|
130
|
-
|
|
156
|
+
let debugInfo = this.gl.getExtension("WEBGL_debug_renderer_info");
|
|
131
157
|
if (debugInfo !== null) {
|
|
132
158
|
this.GPUVendor = this.gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);
|
|
133
159
|
this.GPURenderer = this.gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
|
|
134
160
|
}
|
|
135
161
|
|
|
162
|
+
// a private property that when set will make `setCompositor`
|
|
163
|
+
// to use this specific shader instead of the default one
|
|
164
|
+
this.customShader = undefined;
|
|
165
|
+
|
|
136
166
|
// Create a texture cache
|
|
137
167
|
this.cache = new TextureCache(this.maxTextures);
|
|
138
168
|
|
|
@@ -140,7 +170,7 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
140
170
|
this.type = "WebGL" + this.WebGLVersion;
|
|
141
171
|
|
|
142
172
|
// to simulate context lost and restore in WebGL:
|
|
143
|
-
//
|
|
173
|
+
// let ctx = me.video.renderer.context.getExtension('WEBGL_lose_context');
|
|
144
174
|
// ctx.loseContext()
|
|
145
175
|
this.getCanvas().addEventListener("webglcontextlost", (e) => {
|
|
146
176
|
e.preventDefault();
|
|
@@ -153,6 +183,17 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
153
183
|
this.isContextValid = true;
|
|
154
184
|
event.emit(event.ONCONTEXT_RESTORED, this);
|
|
155
185
|
}, false );
|
|
186
|
+
|
|
187
|
+
// reset the renderer on game reset
|
|
188
|
+
event.on(event.GAME_RESET, () => {
|
|
189
|
+
this.reset();
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// register to the CANVAS resize channel
|
|
193
|
+
event.on(event.CANVAS_ONRESIZE, (width, height) => {
|
|
194
|
+
this.flush();
|
|
195
|
+
this.setViewport(0, 0, width, height);
|
|
196
|
+
});
|
|
156
197
|
}
|
|
157
198
|
|
|
158
199
|
/**
|
|
@@ -161,6 +202,21 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
161
202
|
reset() {
|
|
162
203
|
super.reset();
|
|
163
204
|
|
|
205
|
+
// clear gl context
|
|
206
|
+
this.clear();
|
|
207
|
+
|
|
208
|
+
// initial viewport size
|
|
209
|
+
this.setViewport();
|
|
210
|
+
|
|
211
|
+
// rebind the vertex buffer if required (e.g in case of context loss)
|
|
212
|
+
if (this.gl.getParameter(this.gl.ARRAY_BUFFER_BINDING) !== this.vertexBuffer) {
|
|
213
|
+
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.vertexBuffer);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
this.currentCompositor = undefined;
|
|
217
|
+
this.currentProgram = undefined;
|
|
218
|
+
this.customShader = undefined;
|
|
219
|
+
|
|
164
220
|
this.compositors.forEach((compositor) => {
|
|
165
221
|
if (this.isContextValid === false) {
|
|
166
222
|
// on context lost/restore
|
|
@@ -170,35 +226,62 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
170
226
|
}
|
|
171
227
|
});
|
|
172
228
|
|
|
229
|
+
this.setCompositor("quad");
|
|
230
|
+
|
|
173
231
|
this.gl.disable(this.gl.SCISSOR_TEST);
|
|
174
|
-
|
|
175
|
-
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* add a new compositor to this renderer
|
|
236
|
+
* @param {Compositor} compositor - a compositor instance
|
|
237
|
+
* @param {String} name - a name uniquely identifying this compositor
|
|
238
|
+
* @param {Boolean} [activate=false] - true if the given compositor should be set as the active one
|
|
239
|
+
*/
|
|
240
|
+
addCompositor(compositor, name = "default", activate = false) {
|
|
241
|
+
// make sure there is no existing compositor with the same name
|
|
242
|
+
if (typeof this.compositors.get(name) !== "undefined") {
|
|
243
|
+
throw new Error("Invalid Compositor name");
|
|
176
244
|
}
|
|
177
245
|
|
|
246
|
+
// add the new compositor
|
|
247
|
+
this.compositors.set(name, compositor);
|
|
248
|
+
|
|
249
|
+
if (activate === true) {
|
|
250
|
+
// set as active one
|
|
251
|
+
this.setCompositor(name);
|
|
252
|
+
}
|
|
178
253
|
}
|
|
179
254
|
|
|
180
255
|
/**
|
|
181
256
|
* set the active compositor for this renderer
|
|
182
|
-
* @param {
|
|
257
|
+
* @param {String} name - a compositor name
|
|
258
|
+
* @param {GLShader} [shader] - an optional shader program to be used, instead of the default one, when activating the compositor
|
|
259
|
+
* @return {Compositor} an instance to the current active compositor
|
|
183
260
|
*/
|
|
184
|
-
setCompositor(
|
|
185
|
-
|
|
186
|
-
if (typeof compositor === "string") {
|
|
187
|
-
compositor = this.compositors.get(compositor);
|
|
188
|
-
}
|
|
261
|
+
setCompositor(name = "default", shader = this.customShader) {
|
|
262
|
+
let compositor = this.compositors.get(name);
|
|
189
263
|
|
|
190
264
|
if (typeof compositor === "undefined") {
|
|
191
|
-
throw new Error("Invalid
|
|
265
|
+
throw new Error("Invalid Compositor");
|
|
192
266
|
}
|
|
193
267
|
|
|
194
268
|
if (this.currentCompositor !== compositor) {
|
|
195
|
-
if (this.currentCompositor !==
|
|
269
|
+
if (this.currentCompositor !== undefined) {
|
|
196
270
|
// flush the current compositor
|
|
197
271
|
this.currentCompositor.flush();
|
|
198
272
|
}
|
|
199
|
-
// set
|
|
273
|
+
// set as the active one
|
|
200
274
|
this.currentCompositor = compositor;
|
|
201
275
|
}
|
|
276
|
+
|
|
277
|
+
if (name === "quad" && typeof shader === "object") {
|
|
278
|
+
this.currentCompositor.useShader(shader);
|
|
279
|
+
} else {
|
|
280
|
+
// (re)bind the compositor with the default shader (program & attributes)
|
|
281
|
+
this.currentCompositor.bind();
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return this.currentCompositor;
|
|
202
285
|
}
|
|
203
286
|
|
|
204
287
|
/**
|
|
@@ -208,66 +291,31 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
208
291
|
this.currentTransform.identity();
|
|
209
292
|
}
|
|
210
293
|
|
|
211
|
-
/**
|
|
212
|
-
* @ignore
|
|
213
|
-
*/
|
|
214
|
-
createFontTexture(cache) {
|
|
215
|
-
if (typeof this.fontTexture === "undefined") {
|
|
216
|
-
var canvas = this.getCanvas();
|
|
217
|
-
var width = canvas.width;
|
|
218
|
-
var height = canvas.height;
|
|
219
|
-
|
|
220
|
-
if (this.WebGLVersion === 1) {
|
|
221
|
-
if (!isPowerOfTwo(width)) {
|
|
222
|
-
width = nextPowerOfTwo(canvas.width);
|
|
223
|
-
}
|
|
224
|
-
if (!isPowerOfTwo(height)) {
|
|
225
|
-
height = nextPowerOfTwo(canvas.height);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
var image = createCanvas(width, height, true);
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* @ignore
|
|
233
|
-
*/
|
|
234
|
-
this.fontContext2D = this.getContext2d(image);
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* @ignore
|
|
238
|
-
*/
|
|
239
|
-
this.fontTexture = new TextureAtlas(createAtlas(canvas.width, canvas.height, "fontTexture"), image, cache);
|
|
240
|
-
this.currentCompositor.uploadTexture(this.fontTexture, 0, 0, 0);
|
|
241
|
-
|
|
242
|
-
} else {
|
|
243
|
-
// fontTexture was already created, just add it back into the cache
|
|
244
|
-
cache.set(this.fontContext2D.canvas, this.fontTexture);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
294
|
/**
|
|
249
295
|
* Create a pattern with the specified repetition
|
|
250
|
-
* @param {
|
|
296
|
+
* @param {HTMLImageElement|SVGImageElement|HTMLVideoElement|HTMLCanvasElement|ImageBitmap|OffscreenCanvas|VideoFrame} image - Source image to be used as the pattern's image
|
|
251
297
|
* @param {string} repeat - Define how the pattern should be repeated
|
|
252
298
|
* @returns {TextureAtlas}
|
|
253
299
|
* @see ImageLayer#repeat
|
|
254
300
|
* @example
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
301
|
+
* let tileable = renderer.createPattern(image, "repeat");
|
|
302
|
+
* let horizontal = renderer.createPattern(image, "repeat-x");
|
|
303
|
+
* let vertical = renderer.createPattern(image, "repeat-y");
|
|
304
|
+
* let basic = renderer.createPattern(image, "no-repeat");
|
|
259
305
|
*/
|
|
260
306
|
createPattern(image, repeat) {
|
|
261
307
|
|
|
308
|
+
this.setCompositor("quad");
|
|
309
|
+
|
|
262
310
|
if (renderer.WebGLVersion === 1 && (!isPowerOfTwo(image.width) || !isPowerOfTwo(image.height))) {
|
|
263
|
-
|
|
311
|
+
let src = typeof image.src !== "undefined" ? image.src : image;
|
|
264
312
|
throw new Error(
|
|
265
313
|
"[WebGL Renderer] " + src + " is not a POT texture " +
|
|
266
314
|
"(" + image.width + "x" + image.height + ")"
|
|
267
315
|
);
|
|
268
316
|
}
|
|
269
317
|
|
|
270
|
-
|
|
318
|
+
let texture = new TextureAtlas(createAtlas(image.width, image.height, "pattern", repeat), image);
|
|
271
319
|
|
|
272
320
|
// FIXME: Remove old cache entry and texture when changing the repeat mode
|
|
273
321
|
this.currentCompositor.uploadTexture(texture);
|
|
@@ -292,10 +340,27 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
292
340
|
}
|
|
293
341
|
|
|
294
342
|
/**
|
|
295
|
-
*
|
|
343
|
+
* Sets the WebGL viewport, which specifies the affine transformation of x and y from normalized device coordinates to window coordinates
|
|
344
|
+
* @param {number} [x = 0] - x the horizontal coordinate for the lower left corner of the viewport origin
|
|
345
|
+
* @param {number} [y = 0] - y the vertical coordinate for the lower left corner of the viewport origin
|
|
346
|
+
* @param {number} [w = width of the canvas] - the width of viewport
|
|
347
|
+
* @param {number} [h = height of the canvas] - the height of viewport
|
|
348
|
+
*/
|
|
349
|
+
setViewport(x = 0, y = 0, w = this.getCanvas().width, h = this.getCanvas().height) {
|
|
350
|
+
this.gl.viewport(x, y, w, h);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Clear the frame buffer
|
|
296
355
|
*/
|
|
297
356
|
clear() {
|
|
298
|
-
|
|
357
|
+
let gl = this.gl;
|
|
358
|
+
gl.clearColor(0, 0, 0, this.settings.transparent ? 0.0 : 1.0);
|
|
359
|
+
if (this.depthTest === "z-buffer") {
|
|
360
|
+
gl.clear(gl.DEPTH_BUFFER_BIT | gl.COLOR_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
|
|
361
|
+
} else {
|
|
362
|
+
gl.clear(gl.COLOR_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
|
|
363
|
+
}
|
|
299
364
|
}
|
|
300
365
|
|
|
301
366
|
/**
|
|
@@ -304,18 +369,21 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
304
369
|
* @param {boolean} [opaque=false] - Allow transparency [default] or clear the surface completely [true]
|
|
305
370
|
*/
|
|
306
371
|
clearColor(color = "#000000", opaque = false) {
|
|
307
|
-
|
|
372
|
+
let glArray;
|
|
373
|
+
let gl = this.gl;
|
|
308
374
|
|
|
309
375
|
if (color instanceof Color) {
|
|
310
376
|
glArray = color.toArray();
|
|
311
377
|
} else {
|
|
312
|
-
|
|
378
|
+
let _color = pool.pull("me.Color");
|
|
313
379
|
// reuse temporary the renderer default color object
|
|
314
380
|
glArray = _color.parseCSS(color).toArray();
|
|
315
381
|
pool.push(_color);
|
|
316
382
|
}
|
|
383
|
+
|
|
317
384
|
// clear gl context with the specified color
|
|
318
|
-
|
|
385
|
+
gl.clearColor(glArray[0], glArray[1], glArray[2], (opaque === true) ? 1.0 : glArray[3]);
|
|
386
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
319
387
|
}
|
|
320
388
|
|
|
321
389
|
/**
|
|
@@ -332,42 +400,9 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
332
400
|
this.restore();
|
|
333
401
|
}
|
|
334
402
|
|
|
335
|
-
/**
|
|
336
|
-
* @ignore
|
|
337
|
-
*/
|
|
338
|
-
drawFont(bounds) {
|
|
339
|
-
var fontContext = this.getFontContext();
|
|
340
|
-
|
|
341
|
-
// Force-upload the new texture
|
|
342
|
-
this.currentCompositor.uploadTexture(this.fontTexture, 0, 0, 0, true);
|
|
343
|
-
|
|
344
|
-
// Add the new quad
|
|
345
|
-
var uvs = this.fontTexture.getUVs(bounds.left + "," + bounds.top + "," + bounds.width + "," + bounds.height);
|
|
346
|
-
this.currentCompositor.addQuad(
|
|
347
|
-
this.fontTexture,
|
|
348
|
-
bounds.left,
|
|
349
|
-
bounds.top,
|
|
350
|
-
bounds.width,
|
|
351
|
-
bounds.height,
|
|
352
|
-
uvs[0],
|
|
353
|
-
uvs[1],
|
|
354
|
-
uvs[2],
|
|
355
|
-
uvs[3],
|
|
356
|
-
this.currentTint.toUint32(this.getGlobalAlpha())
|
|
357
|
-
);
|
|
358
|
-
|
|
359
|
-
// Clear font context2D
|
|
360
|
-
fontContext.clearRect(
|
|
361
|
-
bounds.left,
|
|
362
|
-
bounds.top,
|
|
363
|
-
bounds.width,
|
|
364
|
-
bounds.height
|
|
365
|
-
);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
403
|
/**
|
|
369
404
|
* Draw an image to the gl context
|
|
370
|
-
* @param {
|
|
405
|
+
* @param {HTMLImageElement|SVGImageElement|HTMLVideoElement|HTMLCanvasElement|ImageBitmap|OffscreenCanvas|VideoFrame} image - An element to draw into the context.
|
|
371
406
|
* @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.
|
|
372
407
|
* @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.
|
|
373
408
|
* @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.
|
|
@@ -410,8 +445,10 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
410
445
|
dy |= 0;
|
|
411
446
|
}
|
|
412
447
|
|
|
413
|
-
|
|
414
|
-
|
|
448
|
+
this.setCompositor("quad");
|
|
449
|
+
|
|
450
|
+
let texture = this.cache.get(image);
|
|
451
|
+
let uvs = texture.getUVs(sx + "," + sy + "," + sw + "," + sh);
|
|
415
452
|
this.currentCompositor.addQuad(texture, dx, dy, dw, dh, uvs[0], uvs[1], uvs[2], uvs[3], this.currentTint.toUint32(this.getGlobalAlpha()));
|
|
416
453
|
}
|
|
417
454
|
|
|
@@ -425,7 +462,8 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
425
462
|
* @see WebGLRenderer#createPattern
|
|
426
463
|
*/
|
|
427
464
|
drawPattern(pattern, x, y, width, height) {
|
|
428
|
-
|
|
465
|
+
let uvs = pattern.getUVs("0,0," + width + "," + height);
|
|
466
|
+
this.setCompositor("quad");
|
|
429
467
|
this.currentCompositor.addQuad(pattern, x, y, width, height, uvs[0], uvs[1], uvs[2], uvs[3], this.currentTint.toUint32(this.getGlobalAlpha()));
|
|
430
468
|
}
|
|
431
469
|
|
|
@@ -433,9 +471,10 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
433
471
|
* Returns the WebGL Context object of the given canvas element
|
|
434
472
|
* @param {HTMLCanvasElement} canvas
|
|
435
473
|
* @param {boolean} [transparent=false] - use true to enable transparency
|
|
474
|
+
* @param {boolean} [depth=false] - use true to enable depth buffer testing
|
|
436
475
|
* @returns {WebGLRenderingContext}
|
|
437
476
|
*/
|
|
438
|
-
getContextGL(canvas, transparent = false) {
|
|
477
|
+
getContextGL(canvas, transparent = false, depth = false) {
|
|
439
478
|
if (typeof canvas === "undefined" || canvas === null) {
|
|
440
479
|
throw new Error(
|
|
441
480
|
"You must pass a canvas element in order to create " +
|
|
@@ -443,10 +482,10 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
443
482
|
);
|
|
444
483
|
}
|
|
445
484
|
|
|
446
|
-
|
|
485
|
+
let attr = {
|
|
447
486
|
alpha : transparent,
|
|
448
487
|
antialias : this.settings.antiAlias,
|
|
449
|
-
depth :
|
|
488
|
+
depth : depth,
|
|
450
489
|
stencil: true,
|
|
451
490
|
preserveDrawingBuffer : false,
|
|
452
491
|
premultipliedAlpha: transparent ? this.settings.premultipliedAlpha : false,
|
|
@@ -454,7 +493,7 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
454
493
|
failIfMajorPerformanceCaveat : this.settings.failIfMajorPerformanceCaveat
|
|
455
494
|
};
|
|
456
495
|
|
|
457
|
-
|
|
496
|
+
let gl;
|
|
458
497
|
|
|
459
498
|
// attempt to create a WebGL2 context if requested
|
|
460
499
|
if (this.settings.preferWebGL1 === false) {
|
|
@@ -532,28 +571,14 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
532
571
|
}
|
|
533
572
|
}
|
|
534
573
|
|
|
535
|
-
/**
|
|
536
|
-
* return a reference to the font 2d Context
|
|
537
|
-
* @ignore
|
|
538
|
-
*/
|
|
539
|
-
getFontContext() {
|
|
540
|
-
if (typeof this.fontContext2D === "undefined" ) {
|
|
541
|
-
// warn the end user about performance impact
|
|
542
|
-
console.warn("[WebGL Renderer] WARNING : Using Standard me.Text with WebGL will severly impact performances !");
|
|
543
|
-
// create the font texture if not done yet
|
|
544
|
-
this.createFontTexture(this.cache);
|
|
545
|
-
}
|
|
546
|
-
return this.fontContext2D;
|
|
547
|
-
}
|
|
548
|
-
|
|
549
574
|
/**
|
|
550
575
|
* restores the canvas context
|
|
551
576
|
*/
|
|
552
577
|
restore() {
|
|
553
578
|
// do nothing if there is no saved states
|
|
554
579
|
if (this._matrixStack.length !== 0) {
|
|
555
|
-
|
|
556
|
-
|
|
580
|
+
let color = this._colorStack.pop();
|
|
581
|
+
let matrix = this._matrixStack.pop();
|
|
557
582
|
|
|
558
583
|
// restore the previous context
|
|
559
584
|
this.currentColor.copy(color);
|
|
@@ -642,7 +667,7 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
642
667
|
* @param {Color|string} color - css color string.
|
|
643
668
|
*/
|
|
644
669
|
setColor(color) {
|
|
645
|
-
|
|
670
|
+
let alpha = this.currentColor.alpha;
|
|
646
671
|
this.currentColor.copy(color);
|
|
647
672
|
this.currentColor.alpha *= alpha;
|
|
648
673
|
}
|
|
@@ -666,10 +691,7 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
666
691
|
* @param {boolean} [fill=false]
|
|
667
692
|
*/
|
|
668
693
|
strokeArc(x, y, radius, start, end, antiClockwise = false, fill = false) {
|
|
669
|
-
|
|
670
|
-
// Fast path: don't draw fully transparent
|
|
671
|
-
return;
|
|
672
|
-
}
|
|
694
|
+
this.setCompositor("primitive");
|
|
673
695
|
this.path2D.beginPath();
|
|
674
696
|
this.path2D.arc(x, y, radius, start, end, antiClockwise);
|
|
675
697
|
if (fill === false) {
|
|
@@ -702,15 +724,12 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
702
724
|
* @param {boolean} [fill=false] - also fill the shape with the current color if true
|
|
703
725
|
*/
|
|
704
726
|
strokeEllipse(x, y, w, h, fill = false) {
|
|
705
|
-
|
|
706
|
-
// Fast path: don't draw fully transparent
|
|
707
|
-
return;
|
|
708
|
-
}
|
|
727
|
+
this.setCompositor("primitive");
|
|
709
728
|
this.path2D.beginPath();
|
|
710
729
|
this.path2D.ellipse(x, y, w, h, 0, 0, 360);
|
|
711
730
|
this.path2D.closePath();
|
|
712
731
|
if (fill === false) {
|
|
713
|
-
this.currentCompositor.drawVertices(this.gl.
|
|
732
|
+
this.currentCompositor.drawVertices(this.gl.LINE_STRIP, this.path2D.points);
|
|
714
733
|
} else {
|
|
715
734
|
this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
|
|
716
735
|
}
|
|
@@ -735,14 +754,11 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
735
754
|
* @param {number} endY - the end y coordinate
|
|
736
755
|
*/
|
|
737
756
|
strokeLine(startX, startY, endX, endY) {
|
|
738
|
-
|
|
739
|
-
// Fast path: don't draw fully transparent
|
|
740
|
-
return;
|
|
741
|
-
}
|
|
757
|
+
this.setCompositor("primitive");
|
|
742
758
|
this.path2D.beginPath();
|
|
743
759
|
this.path2D.moveTo(startX, startY);
|
|
744
760
|
this.path2D.lineTo(endX, endY);
|
|
745
|
-
this.currentCompositor.drawVertices(this.gl.
|
|
761
|
+
this.currentCompositor.drawVertices(this.gl.LINES, this.path2D.points);
|
|
746
762
|
}
|
|
747
763
|
|
|
748
764
|
|
|
@@ -763,22 +779,19 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
763
779
|
* @param {boolean} [fill=false] - also fill the shape with the current color if true
|
|
764
780
|
*/
|
|
765
781
|
strokePolygon(poly, fill = false) {
|
|
766
|
-
|
|
767
|
-
// Fast path: don't draw fully transparent
|
|
768
|
-
return;
|
|
769
|
-
}
|
|
782
|
+
this.setCompositor("primitive");
|
|
770
783
|
this.translate(poly.pos.x, poly.pos.y);
|
|
771
784
|
this.path2D.beginPath();
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
for (
|
|
775
|
-
|
|
776
|
-
this.path2D.lineTo(
|
|
785
|
+
|
|
786
|
+
let points = poly.points;
|
|
787
|
+
for (let i = 1; i < points.length; i++) {
|
|
788
|
+
this.path2D.moveTo(points[i-1].x, points[i-1].y);
|
|
789
|
+
this.path2D.lineTo(points[i].x, points[i].y);
|
|
777
790
|
}
|
|
778
|
-
this.path2D.lineTo(
|
|
791
|
+
this.path2D.lineTo(points[points.length - 1].x, points[points.length - 1].y);
|
|
779
792
|
this.path2D.closePath();
|
|
780
793
|
if (fill === false) {
|
|
781
|
-
this.currentCompositor.drawVertices(this.gl.
|
|
794
|
+
this.currentCompositor.drawVertices(this.gl.LINES, this.path2D.points);
|
|
782
795
|
} else {
|
|
783
796
|
// draw all triangles
|
|
784
797
|
this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
|
|
@@ -803,14 +816,11 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
803
816
|
* @param {boolean} [fill=false] - also fill the shape with the current color if true
|
|
804
817
|
*/
|
|
805
818
|
strokeRect(x, y, width, height, fill = false) {
|
|
806
|
-
|
|
807
|
-
// Fast path: don't draw fully transparent
|
|
808
|
-
return;
|
|
809
|
-
}
|
|
819
|
+
this.setCompositor("primitive");
|
|
810
820
|
this.path2D.beginPath();
|
|
811
821
|
this.path2D.rect(x, y, width, height);
|
|
812
822
|
if (fill === false) {
|
|
813
|
-
this.currentCompositor.drawVertices(this.gl.
|
|
823
|
+
this.currentCompositor.drawVertices(this.gl.LINES, this.path2D.points);
|
|
814
824
|
} else {
|
|
815
825
|
this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
|
|
816
826
|
}
|
|
@@ -837,14 +847,11 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
837
847
|
* @param {boolean} [fill=false] - also fill the shape with the current color if true
|
|
838
848
|
*/
|
|
839
849
|
strokeRoundRect(x, y, width, height, radius, fill = false) {
|
|
840
|
-
|
|
841
|
-
// Fast path: don't draw fully transparent
|
|
842
|
-
return;
|
|
843
|
-
}
|
|
850
|
+
this.setCompositor("primitive");
|
|
844
851
|
this.path2D.beginPath();
|
|
845
852
|
this.path2D.roundRect(x, y, width, height, radius);
|
|
846
853
|
if (fill === false) {
|
|
847
|
-
this.currentCompositor.drawVertices(this.gl.
|
|
854
|
+
this.currentCompositor.drawVertices(this.gl.LINE_STRIP, this.path2D.points);
|
|
848
855
|
} else {
|
|
849
856
|
this.path2D.closePath();
|
|
850
857
|
this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
|
|
@@ -898,11 +905,11 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
898
905
|
* @param {Matrix2d} mat2d - Matrix to transform by
|
|
899
906
|
*/
|
|
900
907
|
transform(mat2d) {
|
|
901
|
-
|
|
908
|
+
let currentTransform = this.currentTransform;
|
|
902
909
|
currentTransform.multiply(mat2d);
|
|
903
910
|
if (this.settings.subPixel === false) {
|
|
904
911
|
// snap position values to pixel grid
|
|
905
|
-
|
|
912
|
+
let a = currentTransform.toArray();
|
|
906
913
|
a[6] |= 0;
|
|
907
914
|
a[7] |= 0;
|
|
908
915
|
}
|
|
@@ -914,11 +921,11 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
914
921
|
* @param {number} y
|
|
915
922
|
*/
|
|
916
923
|
translate(x, y) {
|
|
917
|
-
|
|
924
|
+
let currentTransform = this.currentTransform;
|
|
918
925
|
currentTransform.translate(x, y);
|
|
919
926
|
if (this.settings.subPixel === false) {
|
|
920
927
|
// snap position values to pixel grid
|
|
921
|
-
|
|
928
|
+
let a = currentTransform.toArray();
|
|
922
929
|
a[6] |= 0;
|
|
923
930
|
a[7] |= 0;
|
|
924
931
|
}
|
|
@@ -936,11 +943,11 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
936
943
|
* @param {number} height
|
|
937
944
|
*/
|
|
938
945
|
clipRect(x, y, width, height) {
|
|
939
|
-
|
|
940
|
-
|
|
946
|
+
let canvas = this.getCanvas();
|
|
947
|
+
let gl = this.gl;
|
|
941
948
|
// if requested box is different from the current canvas size
|
|
942
949
|
if (x !== 0 || y !== 0 || width !== canvas.width || height !== canvas.height) {
|
|
943
|
-
|
|
950
|
+
let currentScissor = this.currentScissor;
|
|
944
951
|
if (gl.isEnabled(gl.SCISSOR_TEST)) {
|
|
945
952
|
// if same as the current scissor box do nothing
|
|
946
953
|
if (currentScissor[0] === x && currentScissor[1] === y &&
|
|
@@ -979,7 +986,7 @@ import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
|
979
986
|
* @param {boolean} [invert=false] - either the given shape should define what is visible (default) or the opposite
|
|
980
987
|
*/
|
|
981
988
|
setMask(mask, invert = false) {
|
|
982
|
-
|
|
989
|
+
let gl = this.gl;
|
|
983
990
|
|
|
984
991
|
// flush the compositor
|
|
985
992
|
this.flush();
|