melonjs 17.3.0 → 18.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/{dist/types → build}/application/application.d.ts +16 -10
- package/build/application/application.d.ts.map +1 -0
- package/build/application/defaultApplicationSettings.d.ts +18 -0
- package/build/application/defaultApplicationSettings.d.ts.map +1 -0
- package/build/application/header.d.ts +11 -0
- package/build/application/header.d.ts.map +1 -0
- package/{dist/types → build}/application/resize.d.ts +2 -0
- package/build/application/resize.d.ts.map +1 -0
- package/build/application/scaleMethods.d.ts +44 -0
- package/build/application/scaleMethods.d.ts.map +1 -0
- package/build/application/settings.d.ts +85 -0
- package/build/application/settings.d.ts.map +1 -0
- package/{dist/types → build}/audio/audio.d.ts +37 -59
- package/build/audio/audio.d.ts.map +1 -0
- package/{dist/types → build}/camera/camera2d.d.ts +42 -75
- package/build/camera/camera2d.d.ts.map +1 -0
- package/build/const.d.ts +14 -0
- package/build/const.d.ts.map +1 -0
- package/build/geometries/earcut.d.ts +3 -0
- package/build/geometries/earcut.d.ts.map +1 -0
- package/build/geometries/ellipse.d.ts +117 -0
- package/build/geometries/ellipse.d.ts.map +1 -0
- package/build/geometries/line.d.ts +39 -0
- package/build/geometries/line.d.ts.map +1 -0
- package/build/geometries/observablePoint.d.ts +75 -0
- package/build/geometries/observablePoint.d.ts.map +1 -0
- package/{dist/types → build}/geometries/path2d.d.ts +11 -5
- package/build/geometries/path2d.d.ts.map +1 -0
- package/build/geometries/point.d.ts +44 -0
- package/build/geometries/point.d.ts.map +1 -0
- package/build/geometries/polygon.d.ts +182 -0
- package/build/geometries/polygon.d.ts.map +1 -0
- package/build/geometries/rectangle.d.ts +135 -0
- package/build/geometries/rectangle.d.ts.map +1 -0
- package/build/geometries/roundrect.d.ts +67 -0
- package/build/geometries/roundrect.d.ts.map +1 -0
- package/build/geometries/toarccanvas.d.ts +28 -0
- package/build/geometries/toarccanvas.d.ts.map +1 -0
- package/{dist/types → build}/index.d.ts +41 -45
- package/build/index.d.ts.map +1 -0
- package/build/index.js +28318 -0
- package/build/index.js.map +7 -0
- package/{dist/types → build}/input/gamepad.d.ts +3 -11
- package/build/input/gamepad.d.ts.map +1 -0
- package/{dist/types → build}/input/input.d.ts +4 -2
- package/build/input/input.d.ts.map +1 -0
- package/build/input/key.d.ts +105 -0
- package/build/input/key.d.ts.map +1 -0
- package/build/input/keyboard.d.ts +72 -0
- package/build/input/keyboard.d.ts.map +1 -0
- package/build/input/pointer.d.ts +180 -0
- package/build/input/pointer.d.ts.map +1 -0
- package/{dist/types → build}/input/pointerevent.d.ts +17 -15
- package/build/input/pointerevent.d.ts.map +1 -0
- package/{dist/types → build}/lang/console.d.ts +1 -0
- package/build/lang/console.d.ts.map +1 -0
- package/build/lang/deprecated.d.ts +24 -0
- package/build/lang/deprecated.d.ts.map +1 -0
- package/{dist/types → build}/level/level.d.ts +7 -7
- package/build/level/level.d.ts.map +1 -0
- package/{dist/types → build}/level/tiled/TMXGroup.d.ts +2 -2
- package/build/level/tiled/TMXGroup.d.ts.map +1 -0
- package/{dist/types → build}/level/tiled/TMXLayer.d.ts +4 -4
- package/build/level/tiled/TMXLayer.d.ts.map +1 -0
- package/{dist/types → build}/level/tiled/TMXObject.d.ts +3 -3
- package/build/level/tiled/TMXObject.d.ts.map +1 -0
- package/{dist/types → build}/level/tiled/TMXTile.d.ts +4 -5
- package/build/level/tiled/TMXTile.d.ts.map +1 -0
- package/{dist/types → build}/level/tiled/TMXTileMap.d.ts +4 -4
- package/build/level/tiled/TMXTileMap.d.ts.map +1 -0
- package/{dist/types → build}/level/tiled/TMXTileset.d.ts +3 -3
- package/build/level/tiled/TMXTileset.d.ts.map +1 -0
- package/{dist/types → build}/level/tiled/TMXTilesetGroup.d.ts +1 -1
- package/build/level/tiled/TMXTilesetGroup.d.ts.map +1 -0
- package/{dist/types → build}/level/tiled/TMXUtils.d.ts +2 -1
- package/build/level/tiled/TMXUtils.d.ts.map +1 -0
- package/{dist/types → build}/level/tiled/constants.d.ts +1 -0
- package/build/level/tiled/constants.d.ts.map +1 -0
- package/{dist/types → build}/level/tiled/renderer/TMXHexagonalRenderer.d.ts +3 -4
- package/build/level/tiled/renderer/TMXHexagonalRenderer.d.ts.map +1 -0
- package/{dist/types → build}/level/tiled/renderer/TMXIsometricRenderer.d.ts +2 -3
- package/build/level/tiled/renderer/TMXIsometricRenderer.d.ts.map +1 -0
- package/{dist/types → build}/level/tiled/renderer/TMXOrthogonalRenderer.d.ts +1 -2
- package/build/level/tiled/renderer/TMXOrthogonalRenderer.d.ts.map +1 -0
- package/{dist/types → build}/level/tiled/renderer/TMXRenderer.d.ts +7 -7
- package/build/level/tiled/renderer/TMXRenderer.d.ts.map +1 -0
- package/{dist/types → build}/level/tiled/renderer/TMXStaggeredRenderer.d.ts +1 -2
- package/build/level/tiled/renderer/TMXStaggeredRenderer.d.ts.map +1 -0
- package/{dist/types → build}/level/tiled/renderer/autodetect.d.ts +4 -3
- package/build/level/tiled/renderer/autodetect.d.ts.map +1 -0
- package/build/loader/cache.d.ts +10 -0
- package/build/loader/cache.d.ts.map +1 -0
- package/{dist/types → build}/loader/loader.d.ts +29 -53
- package/build/loader/loader.d.ts.map +1 -0
- package/{dist/types → build}/loader/loadingscreen.d.ts +1 -0
- package/build/loader/loadingscreen.d.ts.map +1 -0
- package/{dist/types → build}/loader/parsers/binary.d.ts +2 -1
- package/build/loader/parsers/binary.d.ts.map +1 -0
- package/{dist/types → build}/loader/parsers/compressed_textures/compressed_image.d.ts +1 -0
- package/build/loader/parsers/compressed_textures/compressed_image.d.ts.map +1 -0
- package/build/loader/parsers/compressed_textures/parseDDS.d.ts +2 -0
- package/build/loader/parsers/compressed_textures/parseDDS.d.ts.map +1 -0
- package/build/loader/parsers/compressed_textures/parseKTX.d.ts +2 -0
- package/build/loader/parsers/compressed_textures/parseKTX.d.ts.map +1 -0
- package/build/loader/parsers/compressed_textures/parseKTX2.d.ts +2 -0
- package/build/loader/parsers/compressed_textures/parseKTX2.d.ts.map +1 -0
- package/build/loader/parsers/compressed_textures/parsePKM.d.ts +2 -0
- package/build/loader/parsers/compressed_textures/parsePKM.d.ts.map +1 -0
- package/build/loader/parsers/compressed_textures/parsePVR.d.ts +2 -0
- package/build/loader/parsers/compressed_textures/parsePVR.d.ts.map +1 -0
- package/{dist/types → build}/loader/parsers/fetchdata.d.ts +2 -1
- package/build/loader/parsers/fetchdata.d.ts.map +1 -0
- package/{dist/types → build}/loader/parsers/fontface.d.ts +2 -1
- package/build/loader/parsers/fontface.d.ts.map +1 -0
- package/{dist/types → build}/loader/parsers/image.d.ts +2 -1
- package/build/loader/parsers/image.d.ts.map +1 -0
- package/{dist/types → build}/loader/parsers/json.d.ts +2 -1
- package/build/loader/parsers/json.d.ts.map +1 -0
- package/{dist/types → build}/loader/parsers/script.d.ts +2 -1
- package/build/loader/parsers/script.d.ts.map +1 -0
- package/{dist/types → build}/loader/parsers/tmx.d.ts +2 -1
- package/build/loader/parsers/tmx.d.ts.map +1 -0
- package/{dist/types → build}/loader/parsers/video.d.ts +2 -1
- package/build/loader/parsers/video.d.ts.map +1 -0
- package/build/math/color.d.ts +192 -0
- package/build/math/color.d.ts.map +1 -0
- package/build/math/math.d.ts +128 -0
- package/build/math/math.d.ts.map +1 -0
- package/build/math/matrix2d.d.ts +163 -0
- package/build/math/matrix2d.d.ts.map +1 -0
- package/build/math/matrix3d.d.ts +188 -0
- package/build/math/matrix3d.d.ts.map +1 -0
- package/build/math/observableVector2d.d.ts +286 -0
- package/build/math/observableVector2d.d.ts.map +1 -0
- package/build/math/observableVector2d_old.d.ts +76 -0
- package/build/math/observableVector2d_old.d.ts.map +1 -0
- package/build/math/observableVector3d.d.ts +283 -0
- package/build/math/observableVector3d.d.ts.map +1 -0
- package/build/math/observableVector3d_old.d.ts +81 -0
- package/build/math/observableVector3d_old.d.ts.map +1 -0
- package/build/math/vector2d.d.ts +253 -0
- package/build/math/vector2d.d.ts.map +1 -0
- package/build/math/vector3d.d.ts +242 -0
- package/build/math/vector3d.d.ts.map +1 -0
- package/{dist/types → build}/particles/emitter.d.ts +16 -40
- package/build/particles/emitter.d.ts.map +1 -0
- package/build/particles/particle.d.ts +47 -0
- package/build/particles/particle.d.ts.map +1 -0
- package/{dist/types → build}/particles/settings.d.ts +1 -0
- package/build/particles/settings.d.ts.map +1 -0
- package/{dist/types → build}/physics/body.d.ts +39 -21
- package/build/physics/body.d.ts.map +1 -0
- package/build/physics/bounds.d.ts +192 -0
- package/build/physics/bounds.d.ts.map +1 -0
- package/{dist/types → build}/physics/collision.d.ts +6 -4
- package/build/physics/collision.d.ts.map +1 -0
- package/{dist/types → build}/physics/detector.d.ts +13 -5
- package/build/physics/detector.d.ts.map +1 -0
- package/{dist/types → build}/physics/quadtree.d.ts +7 -18
- package/build/physics/quadtree.d.ts.map +1 -0
- package/{dist/types → build}/physics/response.d.ts +46 -5
- package/build/physics/response.d.ts.map +1 -0
- package/{dist/types → build}/physics/sat.d.ts +8 -0
- package/build/physics/sat.d.ts.map +1 -0
- package/{dist/types → build}/physics/world.d.ts +9 -4
- package/build/physics/world.d.ts.map +1 -0
- package/{dist/types → build}/plugin/plugin.d.ts +11 -18
- package/build/plugin/plugin.d.ts.map +1 -0
- package/build/polyfill/console.d.ts +2 -0
- package/build/polyfill/console.d.ts.map +1 -0
- package/build/polyfill/index.d.ts +6 -0
- package/build/polyfill/index.d.ts.map +1 -0
- package/build/polyfill/roundrect.d.ts +2 -0
- package/build/polyfill/roundrect.d.ts.map +1 -0
- package/build/pool.d.ts +39 -0
- package/build/pool.d.ts.map +1 -0
- package/{dist/types → build}/renderable/collectable.d.ts +2 -2
- package/build/renderable/collectable.d.ts.map +1 -0
- package/build/renderable/colorlayer.d.ts +41 -0
- package/build/renderable/colorlayer.d.ts.map +1 -0
- package/{dist/types → build}/renderable/container.d.ts +50 -19
- package/build/renderable/container.d.ts.map +1 -0
- package/{dist/types → build}/renderable/draggable.d.ts +5 -13
- package/build/renderable/draggable.d.ts.map +1 -0
- package/{dist/types → build}/renderable/dragndrop.d.ts +12 -21
- package/build/renderable/dragndrop.d.ts.map +1 -0
- package/{dist/types → build}/renderable/entity/entity.d.ts +17 -11
- package/build/renderable/entity/entity.d.ts.map +1 -0
- package/{dist/types → build}/renderable/imagelayer.d.ts +28 -8
- package/build/renderable/imagelayer.d.ts.map +1 -0
- package/build/renderable/light2d.d.ts +73 -0
- package/build/renderable/light2d.d.ts.map +1 -0
- package/{dist/types → build}/renderable/nineslicesprite.d.ts +9 -3
- package/build/renderable/nineslicesprite.d.ts.map +1 -0
- package/{dist/types → build}/renderable/renderable.d.ts +71 -50
- package/build/renderable/renderable.d.ts.map +1 -0
- package/{dist/types → build}/renderable/sprite.d.ts +34 -13
- package/build/renderable/sprite.d.ts.map +1 -0
- package/{dist/types → build}/renderable/text/bitmaptext.d.ts +7 -8
- package/build/renderable/text/bitmaptext.d.ts.map +1 -0
- package/build/renderable/text/bitmaptextdata.d.ts +17 -0
- package/build/renderable/text/bitmaptextdata.d.ts.map +1 -0
- package/{dist/types → build}/renderable/text/glyph.d.ts +15 -3
- package/build/renderable/text/glyph.d.ts.map +1 -0
- package/{dist/types → build}/renderable/text/text.d.ts +7 -16
- package/build/renderable/text/text.d.ts.map +1 -0
- package/{dist/types → build}/renderable/text/textmetrics.d.ts +8 -9
- package/build/renderable/text/textmetrics.d.ts.map +1 -0
- package/{dist/types → build}/renderable/text/textstyle.d.ts +1 -0
- package/build/renderable/text/textstyle.d.ts.map +1 -0
- package/{dist/types → build}/renderable/trigger.d.ts +22 -7
- package/build/renderable/trigger.d.ts.map +1 -0
- package/{dist/types → build}/renderable/ui/uibaseelement.d.ts +7 -7
- package/build/renderable/ui/uibaseelement.d.ts.map +1 -0
- package/{dist/types → build}/renderable/ui/uispriteelement.d.ts +4 -6
- package/build/renderable/ui/uispriteelement.d.ts.map +1 -0
- package/{dist/types → build}/renderable/ui/uitextbutton.d.ts +17 -4
- package/build/renderable/ui/uitextbutton.d.ts.map +1 -0
- package/{dist/types → build}/state/stage.d.ts +3 -3
- package/build/state/stage.d.ts.map +1 -0
- package/{dist/types → build}/state/state.d.ts +10 -9
- package/build/state/state.d.ts.map +1 -0
- package/{dist/types → build}/system/device.d.ts +49 -80
- package/build/system/device.d.ts.map +1 -0
- package/build/system/dom.d.ts +2 -0
- package/build/system/dom.d.ts.map +1 -0
- package/{dist/types → build}/system/event.d.ts +124 -291
- package/build/system/event.d.ts.map +1 -0
- package/build/system/eventEmitter.d.ts +19 -0
- package/build/system/eventEmitter.d.ts.map +1 -0
- package/build/system/eventEmitter.spec.d.ts +2 -0
- package/build/system/eventEmitter.spec.d.ts.map +1 -0
- package/{dist/types/system/pooling.d.ts → build/system/legacy_pool.d.ts} +22 -7
- package/build/system/legacy_pool.d.ts.map +1 -0
- package/build/system/platform.d.ts +34 -0
- package/build/system/platform.d.ts.map +1 -0
- package/build/system/pool.d.ts +26 -0
- package/build/system/pool.d.ts.map +1 -0
- package/build/system/save.d.ts +3 -0
- package/build/system/save.d.ts.map +1 -0
- package/build/system/timer.d.ts +118 -0
- package/build/system/timer.d.ts.map +1 -0
- package/build/tweens/easing.d.ts +93 -0
- package/build/tweens/easing.d.ts.map +1 -0
- package/build/tweens/interpolation.d.ts +7 -0
- package/build/tweens/interpolation.d.ts.map +1 -0
- package/build/tweens/tween.d.ts +234 -0
- package/build/tweens/tween.d.ts.map +1 -0
- package/build/utils/agent.d.ts +16 -0
- package/build/utils/agent.d.ts.map +1 -0
- package/build/utils/array-multimap.d.ts +14 -0
- package/build/utils/array-multimap.d.ts.map +1 -0
- package/build/utils/array.d.ts +30 -0
- package/build/utils/array.d.ts.map +1 -0
- package/build/utils/file.d.ts +16 -0
- package/build/utils/file.d.ts.map +1 -0
- package/build/utils/function.d.ts +24 -0
- package/build/utils/function.d.ts.map +1 -0
- package/build/utils/semver.d.ts +2 -0
- package/build/utils/semver.d.ts.map +1 -0
- package/build/utils/string.d.ts +35 -0
- package/build/utils/string.d.ts.map +1 -0
- package/build/utils/types.d.ts +5 -0
- package/build/utils/types.d.ts.map +1 -0
- package/build/utils/utils.d.ts +49 -0
- package/build/utils/utils.d.ts.map +1 -0
- package/build/version.d.ts +5 -0
- package/build/version.d.ts.map +1 -0
- package/{dist/types → build}/video/canvas/canvas_renderer.d.ts +58 -22
- package/build/video/canvas/canvas_renderer.d.ts.map +1 -0
- package/{dist/types → build}/video/renderer.d.ts +38 -17
- package/build/video/renderer.d.ts.map +1 -0
- package/{dist/types → build}/video/rendertarget/canvasrendertarget.d.ts +20 -10
- package/build/video/rendertarget/canvasrendertarget.d.ts.map +1 -0
- package/{dist/types → build}/video/texture/atlas.d.ts +14 -9
- package/build/video/texture/atlas.d.ts.map +1 -0
- package/{dist/types → build}/video/texture/cache.d.ts +4 -3
- package/build/video/texture/cache.d.ts.map +1 -0
- package/{dist/types → build}/video/texture/parser/aseprite.d.ts +1 -0
- package/build/video/texture/parser/aseprite.d.ts.map +1 -0
- package/{dist/types → build}/video/texture/parser/spritesheet.d.ts +1 -0
- package/build/video/texture/parser/spritesheet.d.ts.map +1 -0
- package/{dist/types → build}/video/texture/parser/texturepacker.d.ts +1 -0
- package/build/video/texture/parser/texturepacker.d.ts.map +1 -0
- package/build/video/utils/autodetect.d.ts +8 -0
- package/build/video/utils/autodetect.d.ts.map +1 -0
- package/{dist/types → build}/video/video.d.ts +4 -3
- package/build/video/video.d.ts.map +1 -0
- package/{dist/types → build}/video/webgl/buffer/vertex.d.ts +5 -6
- package/build/video/webgl/buffer/vertex.d.ts.map +1 -0
- package/{dist/types → build}/video/webgl/compositors/compositor.d.ts +9 -2
- package/build/video/webgl/compositors/compositor.d.ts.map +1 -0
- package/{dist/types → build}/video/webgl/compositors/primitive_compositor.d.ts +7 -3
- package/build/video/webgl/compositors/primitive_compositor.d.ts.map +1 -0
- package/{dist/types → build}/video/webgl/compositors/quad_compositor.d.ts +5 -5
- package/build/video/webgl/compositors/quad_compositor.d.ts.map +1 -0
- package/{dist/types → build}/video/webgl/glshader.d.ts +2 -2
- package/build/video/webgl/glshader.d.ts.map +1 -0
- package/{dist/types → build}/video/webgl/utils/attributes.d.ts +1 -0
- package/build/video/webgl/utils/attributes.d.ts.map +1 -0
- package/{dist/types → build}/video/webgl/utils/precision.d.ts +1 -0
- package/build/video/webgl/utils/precision.d.ts.map +1 -0
- package/{dist/types → build}/video/webgl/utils/program.d.ts +1 -0
- package/build/video/webgl/utils/program.d.ts.map +1 -0
- package/{dist/types → build}/video/webgl/utils/string.d.ts +1 -0
- package/build/video/webgl/utils/string.d.ts.map +1 -0
- package/{dist/types → build}/video/webgl/utils/uniforms.d.ts +1 -0
- package/build/video/webgl/utils/uniforms.d.ts.map +1 -0
- package/{dist/types → build}/video/webgl/webgl_renderer.d.ts +55 -43
- package/build/video/webgl/webgl_renderer.d.ts.map +1 -0
- package/package.json +83 -105
- package/LICENSE.md +0 -21
- package/README.md +0 -223
- package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +0 -14
- package/dist/melonjs.mjs/_virtual/earcut.js +0 -10
- package/dist/melonjs.mjs/_virtual/howler.js +0 -10
- package/dist/melonjs.mjs/_virtual/index.js +0 -10
- package/dist/melonjs.mjs/_virtual/re.js +0 -10
- package/dist/melonjs.mjs/application/application.js +0 -437
- package/dist/melonjs.mjs/application/header.js +0 -35
- package/dist/melonjs.mjs/application/resize.js +0 -123
- package/dist/melonjs.mjs/application/settings.js +0 -65
- package/dist/melonjs.mjs/audio/audio.js +0 -618
- package/dist/melonjs.mjs/camera/camera2d.js +0 -729
- package/dist/melonjs.mjs/const.js +0 -32
- package/dist/melonjs.mjs/geometries/ellipse.js +0 -245
- package/dist/melonjs.mjs/geometries/line.js +0 -108
- package/dist/melonjs.mjs/geometries/path2d.js +0 -474
- package/dist/melonjs.mjs/geometries/point.js +0 -80
- package/dist/melonjs.mjs/geometries/poly.js +0 -433
- package/dist/melonjs.mjs/geometries/rectangle.js +0 -330
- package/dist/melonjs.mjs/geometries/roundrect.js +0 -165
- package/dist/melonjs.mjs/geometries/toarccanvas.js +0 -103
- package/dist/melonjs.mjs/index.js +0 -239
- package/dist/melonjs.mjs/input/gamepad.js +0 -495
- package/dist/melonjs.mjs/input/input.js +0 -26
- package/dist/melonjs.mjs/input/keyboard.js +0 -470
- package/dist/melonjs.mjs/input/pointer.js +0 -393
- package/dist/melonjs.mjs/input/pointerevent.js +0 -803
- package/dist/melonjs.mjs/lang/console.js +0 -44
- package/dist/melonjs.mjs/lang/deprecated.js +0 -200
- package/dist/melonjs.mjs/level/level.js +0 -298
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +0 -120
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +0 -432
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +0 -295
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +0 -177
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +0 -574
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +0 -292
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +0 -74
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +0 -417
- package/dist/melonjs.mjs/level/tiled/constants.js +0 -17
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +0 -503
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +0 -215
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +0 -155
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +0 -113
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +0 -107
- package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +0 -38
- package/dist/melonjs.mjs/loader/cache.js +0 -30
- package/dist/melonjs.mjs/loader/loader.js +0 -728
- package/dist/melonjs.mjs/loader/loadingscreen.js +0 -118
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +0 -10
- package/dist/melonjs.mjs/loader/parsers/binary.js +0 -42
- package/dist/melonjs.mjs/loader/parsers/compressed_textures/compressed_image.js +0 -58
- package/dist/melonjs.mjs/loader/parsers/compressed_textures/parseDDS.js +0 -13
- package/dist/melonjs.mjs/loader/parsers/compressed_textures/parseKTX.js +0 -13
- package/dist/melonjs.mjs/loader/parsers/compressed_textures/parseKTX2.js +0 -13
- package/dist/melonjs.mjs/loader/parsers/compressed_textures/parsePKM.js +0 -13
- package/dist/melonjs.mjs/loader/parsers/compressed_textures/parsePVR.js +0 -136
- package/dist/melonjs.mjs/loader/parsers/fetchdata.js +0 -62
- package/dist/melonjs.mjs/loader/parsers/fontface.js +0 -62
- package/dist/melonjs.mjs/loader/parsers/image.js +0 -129
- package/dist/melonjs.mjs/loader/parsers/json.js +0 -43
- package/dist/melonjs.mjs/loader/parsers/script.js +0 -46
- package/dist/melonjs.mjs/loader/parsers/tmx.js +0 -103
- package/dist/melonjs.mjs/loader/parsers/video.js +0 -99
- package/dist/melonjs.mjs/math/color.js +0 -635
- package/dist/melonjs.mjs/math/math.js +0 -221
- package/dist/melonjs.mjs/math/matrix2.js +0 -487
- package/dist/melonjs.mjs/math/matrix3.js +0 -621
- package/dist/melonjs.mjs/math/observable_vector2.js +0 -468
- package/dist/melonjs.mjs/math/observable_vector3.js +0 -558
- package/dist/melonjs.mjs/math/vector2.js +0 -431
- package/dist/melonjs.mjs/math/vector3.js +0 -468
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +0 -45
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +0 -130
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +0 -694
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +0 -352
- package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +0 -12
- package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +0 -3246
- package/dist/melonjs.mjs/node_modules/semver/classes/comparator.js +0 -165
- package/dist/melonjs.mjs/node_modules/semver/classes/range.js +0 -565
- package/dist/melonjs.mjs/node_modules/semver/classes/semver.js +0 -317
- package/dist/melonjs.mjs/node_modules/semver/functions/clean.js +0 -17
- package/dist/melonjs.mjs/node_modules/semver/functions/cmp.js +0 -68
- package/dist/melonjs.mjs/node_modules/semver/functions/coerce.js +0 -73
- package/dist/melonjs.mjs/node_modules/semver/functions/compare-build.js +0 -18
- package/dist/melonjs.mjs/node_modules/semver/functions/compare-loose.js +0 -14
- package/dist/melonjs.mjs/node_modules/semver/functions/compare.js +0 -16
- package/dist/melonjs.mjs/node_modules/semver/functions/diff.js +0 -76
- package/dist/melonjs.mjs/node_modules/semver/functions/eq.js +0 -14
- package/dist/melonjs.mjs/node_modules/semver/functions/gt.js +0 -14
- package/dist/melonjs.mjs/node_modules/semver/functions/gte.js +0 -14
- package/dist/melonjs.mjs/node_modules/semver/functions/inc.js +0 -30
- package/dist/melonjs.mjs/node_modules/semver/functions/lt.js +0 -14
- package/dist/melonjs.mjs/node_modules/semver/functions/lte.js +0 -14
- package/dist/melonjs.mjs/node_modules/semver/functions/major.js +0 -14
- package/dist/melonjs.mjs/node_modules/semver/functions/minor.js +0 -14
- package/dist/melonjs.mjs/node_modules/semver/functions/neq.js +0 -14
- package/dist/melonjs.mjs/node_modules/semver/functions/parse.js +0 -27
- package/dist/melonjs.mjs/node_modules/semver/functions/patch.js +0 -14
- package/dist/melonjs.mjs/node_modules/semver/functions/prerelease.js +0 -17
- package/dist/melonjs.mjs/node_modules/semver/functions/rcompare.js +0 -14
- package/dist/melonjs.mjs/node_modules/semver/functions/rsort.js +0 -14
- package/dist/melonjs.mjs/node_modules/semver/functions/satisfies.js +0 -21
- package/dist/melonjs.mjs/node_modules/semver/functions/sort.js +0 -14
- package/dist/melonjs.mjs/node_modules/semver/functions/valid.js +0 -17
- package/dist/melonjs.mjs/node_modules/semver/index.js +0 -140
- package/dist/melonjs.mjs/node_modules/semver/internal/constants.js +0 -44
- package/dist/melonjs.mjs/node_modules/semver/internal/debug.js +0 -18
- package/dist/melonjs.mjs/node_modules/semver/internal/identifiers.js +0 -32
- package/dist/melonjs.mjs/node_modules/semver/internal/lrucache.js +0 -49
- package/dist/melonjs.mjs/node_modules/semver/internal/parse-options.js +0 -24
- package/dist/melonjs.mjs/node_modules/semver/internal/re.js +0 -234
- package/dist/melonjs.mjs/node_modules/semver/ranges/gtr.js +0 -15
- package/dist/melonjs.mjs/node_modules/semver/ranges/intersects.js +0 -18
- package/dist/melonjs.mjs/node_modules/semver/ranges/ltr.js +0 -15
- package/dist/melonjs.mjs/node_modules/semver/ranges/max-satisfying.js +0 -37
- package/dist/melonjs.mjs/node_modules/semver/ranges/min-satisfying.js +0 -36
- package/dist/melonjs.mjs/node_modules/semver/ranges/min-version.js +0 -74
- package/dist/melonjs.mjs/node_modules/semver/ranges/outside.js +0 -98
- package/dist/melonjs.mjs/node_modules/semver/ranges/simplify.js +0 -59
- package/dist/melonjs.mjs/node_modules/semver/ranges/subset.js +0 -261
- package/dist/melonjs.mjs/node_modules/semver/ranges/to-comparators.js +0 -19
- package/dist/melonjs.mjs/node_modules/semver/ranges/valid.js +0 -22
- package/dist/melonjs.mjs/particles/emitter.js +0 -265
- package/dist/melonjs.mjs/particles/particle.js +0 -186
- package/dist/melonjs.mjs/particles/settings.js +0 -317
- package/dist/melonjs.mjs/physics/body.js +0 -706
- package/dist/melonjs.mjs/physics/bounds.js +0 -409
- package/dist/melonjs.mjs/physics/collision.js +0 -130
- package/dist/melonjs.mjs/physics/detector.js +0 -218
- package/dist/melonjs.mjs/physics/quadtree.js +0 -396
- package/dist/melonjs.mjs/physics/response.js +0 -57
- package/dist/melonjs.mjs/physics/sat.js +0 -483
- package/dist/melonjs.mjs/physics/world.js +0 -224
- package/dist/melonjs.mjs/plugin/plugin.js +0 -168
- package/dist/melonjs.mjs/renderable/collectable.js +0 -60
- package/dist/melonjs.mjs/renderable/colorlayer.js +0 -78
- package/dist/melonjs.mjs/renderable/container.js +0 -994
- package/dist/melonjs.mjs/renderable/draggable.js +0 -121
- package/dist/melonjs.mjs/renderable/dragndrop.js +0 -114
- package/dist/melonjs.mjs/renderable/entity/entity.js +0 -254
- package/dist/melonjs.mjs/renderable/imagelayer.js +0 -288
- package/dist/melonjs.mjs/renderable/light2d.js +0 -164
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +0 -242
- package/dist/melonjs.mjs/renderable/renderable.js +0 -860
- package/dist/melonjs.mjs/renderable/sprite.js +0 -694
- package/dist/melonjs.mjs/renderable/text/bitmaptext.js +0 -421
- package/dist/melonjs.mjs/renderable/text/bitmaptextdata.js +0 -195
- package/dist/melonjs.mjs/renderable/text/glyph.js +0 -65
- package/dist/melonjs.mjs/renderable/text/text.js +0 -424
- package/dist/melonjs.mjs/renderable/text/textmetrics.js +0 -176
- package/dist/melonjs.mjs/renderable/text/textstyle.js +0 -21
- package/dist/melonjs.mjs/renderable/trigger.js +0 -158
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +0 -285
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +0 -231
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +0 -146
- package/dist/melonjs.mjs/state/stage.js +0 -235
- package/dist/melonjs.mjs/state/state.js +0 -548
- package/dist/melonjs.mjs/system/device.js +0 -872
- package/dist/melonjs.mjs/system/dom.js +0 -79
- package/dist/melonjs.mjs/system/event.js +0 -606
- package/dist/melonjs.mjs/system/platform.js +0 -43
- package/dist/melonjs.mjs/system/pooling.js +0 -182
- package/dist/melonjs.mjs/system/save.js +0 -157
- package/dist/melonjs.mjs/system/timer.js +0 -274
- package/dist/melonjs.mjs/tweens/easing.js +0 -334
- package/dist/melonjs.mjs/tweens/interpolation.js +0 -112
- package/dist/melonjs.mjs/tweens/tween.js +0 -479
- package/dist/melonjs.mjs/utils/agent.js +0 -77
- package/dist/melonjs.mjs/utils/array.js +0 -63
- package/dist/melonjs.mjs/utils/file.js +0 -54
- package/dist/melonjs.mjs/utils/function.js +0 -69
- package/dist/melonjs.mjs/utils/string.js +0 -82
- package/dist/melonjs.mjs/utils/utils.js +0 -139
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +0 -883
- package/dist/melonjs.mjs/video/renderer.js +0 -393
- package/dist/melonjs.mjs/video/rendertarget/canvasrendertarget.js +0 -310
- package/dist/melonjs.mjs/video/texture/atlas.js +0 -460
- package/dist/melonjs.mjs/video/texture/cache.js +0 -186
- package/dist/melonjs.mjs/video/texture/parser/aseprite.js +0 -78
- package/dist/melonjs.mjs/video/texture/parser/spritesheet.js +0 -77
- package/dist/melonjs.mjs/video/texture/parser/texturepacker.js +0 -64
- package/dist/melonjs.mjs/video/utils/autodetect.js +0 -27
- package/dist/melonjs.mjs/video/video.js +0 -142
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +0 -146
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +0 -234
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +0 -77
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +0 -254
- package/dist/melonjs.mjs/video/webgl/glshader.js +0 -166
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +0 -10
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +0 -10
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +0 -10
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +0 -10
- package/dist/melonjs.mjs/video/webgl/utils/attributes.js +0 -25
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +0 -38
- package/dist/melonjs.mjs/video/webgl/utils/program.js +0 -67
- package/dist/melonjs.mjs/video/webgl/utils/string.js +0 -25
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +0 -92
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +0 -1199
- package/dist/melonjs.module.js +0 -42838
- package/dist/types/application/header.d.ts +0 -5
- package/dist/types/application/settings.d.ts +0 -105
- package/dist/types/const.d.ts +0 -21
- package/dist/types/geometries/ellipse.d.ts +0 -127
- package/dist/types/geometries/line.d.ts +0 -11
- package/dist/types/geometries/point.d.ts +0 -46
- package/dist/types/geometries/poly.d.ts +0 -175
- package/dist/types/geometries/rectangle.d.ts +0 -130
- package/dist/types/geometries/roundrect.d.ts +0 -43
- package/dist/types/geometries/toarccanvas.d.ts +0 -10
- package/dist/types/input/keyboard.d.ts +0 -205
- package/dist/types/input/pointer.d.ts +0 -261
- package/dist/types/lang/deprecated.d.ts +0 -68
- package/dist/types/loader/cache.d.ts +0 -9
- package/dist/types/loader/parsers/compressed_textures/parseDDS.d.ts +0 -1
- package/dist/types/loader/parsers/compressed_textures/parseKTX.d.ts +0 -1
- package/dist/types/loader/parsers/compressed_textures/parseKTX2.d.ts +0 -1
- package/dist/types/loader/parsers/compressed_textures/parsePKM.d.ts +0 -1
- package/dist/types/loader/parsers/compressed_textures/parsePVR.d.ts +0 -1
- package/dist/types/math/color.d.ts +0 -179
- package/dist/types/math/math.d.ts +0 -149
- package/dist/types/math/matrix2.d.ts +0 -165
- package/dist/types/math/matrix3.d.ts +0 -177
- package/dist/types/math/observable_vector2.d.ts +0 -278
- package/dist/types/math/observable_vector3.d.ts +0 -277
- package/dist/types/math/vector2.d.ts +0 -255
- package/dist/types/math/vector3.d.ts +0 -266
- package/dist/types/particles/particle.d.ts +0 -32
- package/dist/types/physics/bounds.d.ts +0 -195
- package/dist/types/polyfill/console.d.ts +0 -1
- package/dist/types/polyfill/index.d.ts +0 -1
- package/dist/types/polyfill/roundrect.d.ts +0 -1
- package/dist/types/renderable/colorlayer.d.ts +0 -28
- package/dist/types/renderable/light2d.d.ts +0 -58
- package/dist/types/renderable/text/bitmaptextdata.d.ts +0 -35
- package/dist/types/system/dom.d.ts +0 -1
- package/dist/types/system/platform.d.ts +0 -33
- package/dist/types/system/save.d.ts +0 -25
- package/dist/types/system/timer.d.ts +0 -126
- package/dist/types/tweens/easing.d.ts +0 -46
- package/dist/types/tweens/interpolation.d.ts +0 -18
- package/dist/types/tweens/tween.d.ts +0 -195
- package/dist/types/utils/agent.d.ts +0 -21
- package/dist/types/utils/array.d.ts +0 -39
- package/dist/types/utils/file.d.ts +0 -27
- package/dist/types/utils/function.d.ts +0 -31
- package/dist/types/utils/string.d.ts +0 -50
- package/dist/types/utils/utils.d.ts +0 -54
- package/dist/types/video/utils/autodetect.d.ts +0 -5
- package/src/application/application.js +0 -429
- package/src/application/header.js +0 -26
- package/src/application/resize.js +0 -114
- package/src/application/settings.js +0 -56
- package/src/audio/audio.js +0 -617
- package/src/camera/camera2d.js +0 -724
- package/src/const.js +0 -23
- package/src/geometries/ellipse.js +0 -236
- package/src/geometries/line.js +0 -99
- package/src/geometries/path2d.js +0 -464
- package/src/geometries/point.js +0 -71
- package/src/geometries/poly.js +0 -424
- package/src/geometries/rectangle.js +0 -321
- package/src/geometries/roundrect.js +0 -156
- package/src/geometries/toarccanvas.js +0 -94
- package/src/index.js +0 -315
- package/src/input/gamepad.js +0 -487
- package/src/input/input.js +0 -17
- package/src/input/keyboard.js +0 -461
- package/src/input/pointer.js +0 -386
- package/src/input/pointerevent.js +0 -794
- package/src/lang/console.js +0 -36
- package/src/lang/deprecated.js +0 -192
- package/src/level/level.js +0 -290
- package/src/level/tiled/TMXGroup.js +0 -111
- package/src/level/tiled/TMXLayer.js +0 -424
- package/src/level/tiled/TMXObject.js +0 -286
- package/src/level/tiled/TMXTile.js +0 -168
- package/src/level/tiled/TMXTileMap.js +0 -569
- package/src/level/tiled/TMXTileset.js +0 -284
- package/src/level/tiled/TMXTilesetGroup.js +0 -66
- package/src/level/tiled/TMXUtils.js +0 -408
- package/src/level/tiled/constants.js +0 -8
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +0 -497
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +0 -208
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +0 -149
- package/src/level/tiled/renderer/TMXRenderer.js +0 -103
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +0 -100
- package/src/level/tiled/renderer/autodetect.js +0 -29
- package/src/loader/cache.js +0 -22
- package/src/loader/loader.js +0 -727
- package/src/loader/loadingscreen.js +0 -112
- package/src/loader/melonjs_logo.png +0 -0
- package/src/loader/parsers/binary.js +0 -33
- package/src/loader/parsers/compressed_textures/compressed_image.js +0 -49
- package/src/loader/parsers/compressed_textures/parseDDS.js +0 -5
- package/src/loader/parsers/compressed_textures/parseKTX.js +0 -5
- package/src/loader/parsers/compressed_textures/parseKTX2.js +0 -5
- package/src/loader/parsers/compressed_textures/parsePKM.js +0 -5
- package/src/loader/parsers/compressed_textures/parsePVR.js +0 -127
- package/src/loader/parsers/fetchdata.js +0 -53
- package/src/loader/parsers/fontface.js +0 -54
- package/src/loader/parsers/image.js +0 -120
- package/src/loader/parsers/json.js +0 -35
- package/src/loader/parsers/script.js +0 -37
- package/src/loader/parsers/tmx.js +0 -95
- package/src/loader/parsers/video.js +0 -90
- package/src/math/color.js +0 -627
- package/src/math/math.js +0 -212
- package/src/math/matrix2.js +0 -479
- package/src/math/matrix3.js +0 -613
- package/src/math/observable_vector2.js +0 -460
- package/src/math/observable_vector3.js +0 -550
- package/src/math/vector2.js +0 -423
- package/src/math/vector3.js +0 -460
- package/src/particles/emitter.js +0 -258
- package/src/particles/particle.js +0 -178
- package/src/particles/settings.js +0 -310
- package/src/physics/body.js +0 -698
- package/src/physics/bounds.js +0 -401
- package/src/physics/collision.js +0 -123
- package/src/physics/detector.js +0 -209
- package/src/physics/quadtree.js +0 -387
- package/src/physics/response.js +0 -48
- package/src/physics/sat.js +0 -473
- package/src/physics/world.js +0 -216
- package/src/plugin/plugin.js +0 -159
- package/src/polyfill/console.js +0 -11
- package/src/polyfill/index.js +0 -13
- package/src/polyfill/roundrect.js +0 -237
- package/src/renderable/collectable.js +0 -51
- package/src/renderable/colorlayer.js +0 -70
- package/src/renderable/container.js +0 -985
- package/src/renderable/draggable.js +0 -114
- package/src/renderable/dragndrop.js +0 -106
- package/src/renderable/entity/entity.js +0 -246
- package/src/renderable/imagelayer.js +0 -280
- package/src/renderable/light2d.js +0 -155
- package/src/renderable/nineslicesprite.js +0 -233
- package/src/renderable/renderable.js +0 -852
- package/src/renderable/sprite.js +0 -685
- package/src/renderable/text/bitmaptext.js +0 -418
- package/src/renderable/text/bitmaptextdata.js +0 -186
- package/src/renderable/text/glyph.js +0 -57
- package/src/renderable/text/text.js +0 -415
- package/src/renderable/text/textmetrics.js +0 -167
- package/src/renderable/text/textstyle.js +0 -12
- package/src/renderable/trigger.js +0 -149
- package/src/renderable/ui/uibaseelement.js +0 -276
- package/src/renderable/ui/uispriteelement.js +0 -223
- package/src/renderable/ui/uitextbutton.js +0 -140
- package/src/state/stage.js +0 -226
- package/src/state/state.js +0 -541
- package/src/system/device.js +0 -863
- package/src/system/dom.js +0 -70
- package/src/system/event.js +0 -597
- package/src/system/platform.js +0 -34
- package/src/system/pooling.js +0 -190
- package/src/system/save.js +0 -148
- package/src/system/timer.js +0 -281
- package/src/tweens/easing.js +0 -325
- package/src/tweens/interpolation.js +0 -103
- package/src/tweens/tween.js +0 -470
- package/src/utils/agent.js +0 -68
- package/src/utils/array.js +0 -54
- package/src/utils/file.js +0 -46
- package/src/utils/function.js +0 -60
- package/src/utils/string.js +0 -73
- package/src/utils/utils.js +0 -127
- package/src/video/canvas/canvas_renderer.js +0 -874
- package/src/video/renderer.js +0 -384
- package/src/video/rendertarget/canvasrendertarget.js +0 -303
- package/src/video/texture/atlas.js +0 -451
- package/src/video/texture/cache.js +0 -178
- package/src/video/texture/parser/aseprite.js +0 -69
- package/src/video/texture/parser/spritesheet.js +0 -68
- package/src/video/texture/parser/texturepacker.js +0 -55
- package/src/video/utils/autodetect.js +0 -18
- package/src/video/video.js +0 -160
- package/src/video/webgl/buffer/vertex.js +0 -137
- package/src/video/webgl/compositors/compositor.js +0 -225
- package/src/video/webgl/compositors/primitive_compositor.js +0 -68
- package/src/video/webgl/compositors/quad_compositor.js +0 -245
- package/src/video/webgl/glshader.js +0 -158
- package/src/video/webgl/shaders/primitive.frag +0 -5
- package/src/video/webgl/shaders/primitive.vert +0 -15
- package/src/video/webgl/shaders/quad.frag +0 -7
- package/src/video/webgl/shaders/quad.vert +0 -18
- package/src/video/webgl/utils/attributes.js +0 -16
- package/src/video/webgl/utils/precision.js +0 -29
- package/src/video/webgl/utils/program.js +0 -58
- package/src/video/webgl/utils/string.js +0 -16
- package/src/video/webgl/utils/uniforms.js +0 -84
- package/src/video/webgl/webgl_renderer.js +0 -1190
|
@@ -1,1190 +0,0 @@
|
|
|
1
|
-
import Color from "./../../math/color.js";
|
|
2
|
-
import Matrix2d from "./../../math/matrix2.js";
|
|
3
|
-
import QuadCompositor from "./compositors/quad_compositor";
|
|
4
|
-
import PrimitiveCompositor from "./compositors/primitive_compositor";
|
|
5
|
-
import Renderer from "./../renderer.js";
|
|
6
|
-
import TextureCache from "./../texture/cache.js";
|
|
7
|
-
import { TextureAtlas, createAtlas } from "./../texture/atlas.js";
|
|
8
|
-
import { renderer } from "./../video.js";
|
|
9
|
-
import * as event from "./../../system/event.js";
|
|
10
|
-
import pool from "./../../system/pooling.js";
|
|
11
|
-
import { isPowerOfTwo } from "./../../math/math.js";
|
|
12
|
-
|
|
13
|
-
// list of supported compressed texture formats
|
|
14
|
-
let supportedCompressedTextureFormats;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @classdesc
|
|
18
|
-
* a WebGL renderer draw
|
|
19
|
-
* @augments Renderer
|
|
20
|
-
*/
|
|
21
|
-
export default class WebGLRenderer extends Renderer {
|
|
22
|
-
/**
|
|
23
|
-
* @param {ApplicationSettings} [options] - optional parameters for the renderer
|
|
24
|
-
*/
|
|
25
|
-
constructor(options) {
|
|
26
|
-
// parent contructor
|
|
27
|
-
super(Object.assign(options, { context: "webgl" }));
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* The vendor string of the underlying graphics driver.
|
|
31
|
-
* @type {string}
|
|
32
|
-
* @default undefined
|
|
33
|
-
* @readonly
|
|
34
|
-
*/
|
|
35
|
-
this.GPUVendor = undefined;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* The renderer string of the underlying graphics driver.
|
|
39
|
-
* @type {string}
|
|
40
|
-
* @default undefined
|
|
41
|
-
* @readonly
|
|
42
|
-
*/
|
|
43
|
-
this.GPURenderer = undefined;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* The WebGL context
|
|
47
|
-
* @name gl
|
|
48
|
-
* @type {WebGLRenderingContext}
|
|
49
|
-
*/
|
|
50
|
-
this.gl = this.renderTarget.context;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* sets or returns the thickness of lines for shape drawing (limited to strokeLine)
|
|
54
|
-
* @type {number}
|
|
55
|
-
* @default 1
|
|
56
|
-
* @see WebGLRenderer#strokeLine
|
|
57
|
-
*/
|
|
58
|
-
this.lineWidth = 1;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* the vertex buffer used by this WebGL Renderer
|
|
62
|
-
* @type {WebGLBuffer}
|
|
63
|
-
*/
|
|
64
|
-
this.vertexBuffer = this.gl.createBuffer();
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Maximum number of texture unit supported under the current context
|
|
68
|
-
* @type {number}
|
|
69
|
-
* @readonly
|
|
70
|
-
*/
|
|
71
|
-
this.maxTextures = this.gl.getParameter(this.gl.MAX_TEXTURE_IMAGE_UNITS);
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* @ignore
|
|
75
|
-
*/
|
|
76
|
-
this._colorStack = [];
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* @ignore
|
|
80
|
-
*/
|
|
81
|
-
this._matrixStack = [];
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @ignore
|
|
85
|
-
*/
|
|
86
|
-
this._scissorStack = [];
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* @ignore
|
|
90
|
-
*/
|
|
91
|
-
this._blendStack = [];
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* The current transformation matrix used for transformations on the overall scene
|
|
95
|
-
* @type {Matrix2d}
|
|
96
|
-
*/
|
|
97
|
-
this.currentTransform = new Matrix2d();
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* The current compositor used by the renderer
|
|
101
|
-
* @type {WebGLCompositor}
|
|
102
|
-
*/
|
|
103
|
-
this.currentCompositor = undefined;
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* a reference to the current shader program used by the renderer
|
|
107
|
-
* @type {WebGLProgram}
|
|
108
|
-
*/
|
|
109
|
-
this.currentProgram = undefined;
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* The list of active compositors
|
|
113
|
-
* @type {Map<WebGLCompositor>}
|
|
114
|
-
*/
|
|
115
|
-
this.compositors = new Map();
|
|
116
|
-
|
|
117
|
-
// bind the vertex buffer
|
|
118
|
-
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.vertexBuffer);
|
|
119
|
-
|
|
120
|
-
// Create both quad and primitive compositor
|
|
121
|
-
this.addCompositor(new (this.settings.compositor || QuadCompositor)(this), "quad", true);
|
|
122
|
-
this.addCompositor(new (this.settings.compositor || PrimitiveCompositor)(this), "primitive");
|
|
123
|
-
|
|
124
|
-
// depth Test settings
|
|
125
|
-
this.depthTest = options.depthTest;
|
|
126
|
-
|
|
127
|
-
// default WebGL state(s)
|
|
128
|
-
if (this.depthTest === "z-buffer") {
|
|
129
|
-
this.gl.enable(this.gl.DEPTH_TEST);
|
|
130
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/depthFunc
|
|
131
|
-
this.gl.depthFunc(this.gl.LEQUAL);
|
|
132
|
-
this.gl.depthMask(true);
|
|
133
|
-
} else {
|
|
134
|
-
this.gl.disable(this.gl.DEPTH_TEST);
|
|
135
|
-
this.gl.depthMask(false);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
this.gl.disable(this.gl.SCISSOR_TEST);
|
|
139
|
-
this.gl.enable(this.gl.BLEND);
|
|
140
|
-
|
|
141
|
-
// set default mode
|
|
142
|
-
this.setBlendMode(this.settings.blendMode);
|
|
143
|
-
|
|
144
|
-
// get GPU vendor and renderer
|
|
145
|
-
let debugInfo = this.gl.getExtension("WEBGL_debug_renderer_info");
|
|
146
|
-
if (debugInfo !== null) {
|
|
147
|
-
this.GPUVendor = this.gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);
|
|
148
|
-
this.GPURenderer = this.gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// a private property that when set will make `setCompositor`
|
|
152
|
-
// to use this specific shader instead of the default one
|
|
153
|
-
this.customShader = undefined;
|
|
154
|
-
|
|
155
|
-
// Create a texture cache
|
|
156
|
-
this.cache = new TextureCache(this.maxTextures);
|
|
157
|
-
|
|
158
|
-
// set the renderer type
|
|
159
|
-
this.type = "WebGL" + this.WebGLVersion;
|
|
160
|
-
|
|
161
|
-
// to simulate context lost and restore in WebGL:
|
|
162
|
-
// let ctx = me.video.renderer.context.getExtension('WEBGL_lose_context');
|
|
163
|
-
// ctx.loseContext()
|
|
164
|
-
this.getCanvas().addEventListener("webglcontextlost", (e) => {
|
|
165
|
-
e.preventDefault();
|
|
166
|
-
this.isContextValid = false;
|
|
167
|
-
event.emit(event.ONCONTEXT_LOST, this);
|
|
168
|
-
}, false);
|
|
169
|
-
// ctx.restoreContext()
|
|
170
|
-
this.getCanvas().addEventListener("webglcontextrestored", () => {
|
|
171
|
-
this.reset();
|
|
172
|
-
this.isContextValid = true;
|
|
173
|
-
event.emit(event.ONCONTEXT_RESTORED, this);
|
|
174
|
-
}, false);
|
|
175
|
-
|
|
176
|
-
// reset the renderer on game reset
|
|
177
|
-
event.on(event.GAME_RESET, () => {
|
|
178
|
-
this.reset();
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
// register to the CANVAS resize channel
|
|
182
|
-
event.on(event.CANVAS_ONRESIZE, (width, height) => {
|
|
183
|
-
this.flush();
|
|
184
|
-
this.setViewport(0, 0, width, height);
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* The WebGL version used by this renderer (1 or 2)
|
|
190
|
-
* @type {number}
|
|
191
|
-
* @default 1
|
|
192
|
-
* @readonly
|
|
193
|
-
*/
|
|
194
|
-
get WebGLVersion() {
|
|
195
|
-
return this.renderTarget.WebGLVersion;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* return the list of supported compressed texture formats
|
|
200
|
-
* @return {Object}
|
|
201
|
-
*/
|
|
202
|
-
getSupportedCompressedTextureFormats() {
|
|
203
|
-
if (typeof supportedCompressedTextureFormats === "undefined") {
|
|
204
|
-
const gl = this.gl;
|
|
205
|
-
supportedCompressedTextureFormats = {
|
|
206
|
-
astc: gl.getExtension("WEBGL_compressed_texture_astc") || this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_astc"),
|
|
207
|
-
bptc: gl.getExtension("EXT_texture_compression_bptc") || this._gl.getExtension("WEBKIT_EXT_texture_compression_bptc"),
|
|
208
|
-
s3tc: gl.getExtension("WEBGL_compressed_texture_s3tc") || this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc"),
|
|
209
|
-
s3tc_srgb: gl.getExtension("WEBGL_compressed_texture_s3tc_srgb") || this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc_srgb"),
|
|
210
|
-
pvrtc: gl.getExtension("WEBGL_compressed_texture_pvrtc") || this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),
|
|
211
|
-
etc1: gl.getExtension("WEBGL_compressed_texture_etc1") || this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_etc1"),
|
|
212
|
-
etc2: gl.getExtension("WEBGL_compressed_texture_etc") || gl.getExtension("WEBKIT_WEBGL_compressed_texture_etc") || gl.getExtension("WEBGL_compressed_texture_es3_0")
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
return supportedCompressedTextureFormats;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* return true if the given compressed texture format is supported
|
|
220
|
-
* @param {Number} format
|
|
221
|
-
* @returns
|
|
222
|
-
*/
|
|
223
|
-
hasSupportedCompressedFormats(format) {
|
|
224
|
-
const supportedFormats = this.getSupportedCompressedTextureFormats();
|
|
225
|
-
for (var supportedFormat in supportedFormats) {
|
|
226
|
-
for (var extension in supportedFormats[supportedFormat]) {
|
|
227
|
-
if (format === supportedFormats[supportedFormat][extension]) {
|
|
228
|
-
return true;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
return false;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Reset context state
|
|
237
|
-
*/
|
|
238
|
-
reset() {
|
|
239
|
-
super.reset();
|
|
240
|
-
|
|
241
|
-
// clear all stacks
|
|
242
|
-
this._colorStack.forEach((color) => {
|
|
243
|
-
pool.push(color);
|
|
244
|
-
});
|
|
245
|
-
this._matrixStack.forEach((matrix) => {
|
|
246
|
-
pool.push(matrix);
|
|
247
|
-
});
|
|
248
|
-
this._colorStack.length = 0;
|
|
249
|
-
this._matrixStack.length = 0;
|
|
250
|
-
this._blendStack.length = 0;
|
|
251
|
-
|
|
252
|
-
// clear gl context
|
|
253
|
-
this.clear();
|
|
254
|
-
|
|
255
|
-
// initial viewport size
|
|
256
|
-
this.setViewport();
|
|
257
|
-
|
|
258
|
-
// rebind the vertex buffer if required (e.g in case of context loss)
|
|
259
|
-
if (this.gl.getParameter(this.gl.ARRAY_BUFFER_BINDING) !== this.vertexBuffer) {
|
|
260
|
-
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.vertexBuffer);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
this.currentCompositor = undefined;
|
|
264
|
-
this.currentProgram = undefined;
|
|
265
|
-
this.customShader = undefined;
|
|
266
|
-
|
|
267
|
-
this.compositors.forEach((compositor) => {
|
|
268
|
-
if (this.isContextValid === false) {
|
|
269
|
-
// on context lost/restore
|
|
270
|
-
compositor.init(this);
|
|
271
|
-
} else {
|
|
272
|
-
compositor.reset();
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
this.setCompositor("quad");
|
|
277
|
-
|
|
278
|
-
this.gl.disable(this.gl.SCISSOR_TEST);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* add a new compositor to this renderer
|
|
283
|
-
* @param {Compositor} compositor - a compositor instance
|
|
284
|
-
* @param {string} name - a name uniquely identifying this compositor
|
|
285
|
-
* @param {boolean} [activate=false] - true if the given compositor should be set as the active one
|
|
286
|
-
*/
|
|
287
|
-
addCompositor(compositor, name = "default", activate = false) {
|
|
288
|
-
// make sure there is no existing compositor with the same name
|
|
289
|
-
if (typeof this.compositors.get(name) !== "undefined") {
|
|
290
|
-
throw new Error("Invalid Compositor name");
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
// add the new compositor
|
|
294
|
-
this.compositors.set(name, compositor);
|
|
295
|
-
|
|
296
|
-
if (activate === true) {
|
|
297
|
-
// set as active one
|
|
298
|
-
this.setCompositor(name);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* set the active compositor for this renderer
|
|
304
|
-
* @param {string} name - a compositor name
|
|
305
|
-
* @param {GLShader} [shader] - an optional shader program to be used, instead of the default one, when activating the compositor
|
|
306
|
-
* @returns {Compositor} an instance to the current active compositor
|
|
307
|
-
*/
|
|
308
|
-
setCompositor(name = "default", shader = this.customShader) {
|
|
309
|
-
let compositor = this.compositors.get(name);
|
|
310
|
-
|
|
311
|
-
if (typeof compositor === "undefined") {
|
|
312
|
-
throw new Error("Invalid Compositor");
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
if (this.currentCompositor !== compositor) {
|
|
316
|
-
if (this.currentCompositor !== undefined) {
|
|
317
|
-
// flush the current compositor
|
|
318
|
-
this.currentCompositor.flush();
|
|
319
|
-
}
|
|
320
|
-
// set as the active one
|
|
321
|
-
this.currentCompositor = compositor;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
if (name === "quad" && typeof shader === "object") {
|
|
325
|
-
this.currentCompositor.useShader(shader);
|
|
326
|
-
} else {
|
|
327
|
-
// (re)bind the compositor with the default shader (program & attributes)
|
|
328
|
-
this.currentCompositor.bind();
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
return this.currentCompositor;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Reset the gl transform to identity
|
|
336
|
-
*/
|
|
337
|
-
resetTransform() {
|
|
338
|
-
this.currentTransform.identity();
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Create a pattern with the specified repetition
|
|
343
|
-
* @param {HTMLImageElement|SVGImageElement|HTMLVideoElement|HTMLCanvasElement|ImageBitmap|OffscreenCanvas|VideoFrame} image - Source image to be used as the pattern's image
|
|
344
|
-
* @param {string} repeat - Define how the pattern should be repeated
|
|
345
|
-
* @returns {TextureAtlas} the patterned texture created
|
|
346
|
-
* @see ImageLayer#repeat
|
|
347
|
-
* @example
|
|
348
|
-
* let tileable = renderer.createPattern(image, "repeat");
|
|
349
|
-
* let horizontal = renderer.createPattern(image, "repeat-x");
|
|
350
|
-
* let vertical = renderer.createPattern(image, "repeat-y");
|
|
351
|
-
* let basic = renderer.createPattern(image, "no-repeat");
|
|
352
|
-
*/
|
|
353
|
-
createPattern(image, repeat) {
|
|
354
|
-
|
|
355
|
-
this.setCompositor("quad");
|
|
356
|
-
|
|
357
|
-
if (renderer.WebGLVersion === 1 && (!isPowerOfTwo(image.width) || !isPowerOfTwo(image.height))) {
|
|
358
|
-
let src = typeof image.src !== "undefined" ? image.src : image;
|
|
359
|
-
throw new Error(
|
|
360
|
-
"[WebGL Renderer] " + src + " is not a POT texture " +
|
|
361
|
-
"(" + image.width + "x" + image.height + ")"
|
|
362
|
-
);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
let texture = new TextureAtlas(createAtlas(image.width, image.height, "pattern", repeat), image);
|
|
366
|
-
|
|
367
|
-
// FIXME: Remove old cache entry and texture when changing the repeat mode
|
|
368
|
-
this.currentCompositor.uploadTexture(texture);
|
|
369
|
-
|
|
370
|
-
return texture;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* Flush the compositor to the frame buffer
|
|
375
|
-
*/
|
|
376
|
-
flush() {
|
|
377
|
-
this.currentCompositor.flush();
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* set/change the current projection matrix (WebGL only)
|
|
382
|
-
* @param {Matrix3d} matrix - the new projection matrix
|
|
383
|
-
*/
|
|
384
|
-
setProjection(matrix) {
|
|
385
|
-
super.setProjection(matrix);
|
|
386
|
-
this.currentCompositor.setProjection(matrix);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
/**
|
|
390
|
-
* Sets the WebGL viewport, which specifies the affine transformation of x and y from normalized device coordinates to window coordinates
|
|
391
|
-
* @param {number} [x = 0] - x the horizontal coordinate for the lower left corner of the viewport origin
|
|
392
|
-
* @param {number} [y = 0] - y the vertical coordinate for the lower left corner of the viewport origin
|
|
393
|
-
* @param {number} [w = width of the canvas] - the width of viewport
|
|
394
|
-
* @param {number} [h = height of the canvas] - the height of viewport
|
|
395
|
-
*/
|
|
396
|
-
setViewport(x = 0, y = 0, w = this.getCanvas().width, h = this.getCanvas().height) {
|
|
397
|
-
this.gl.viewport(x, y, w, h);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
/**
|
|
401
|
-
* Clear the frame buffer
|
|
402
|
-
*/
|
|
403
|
-
clear() {
|
|
404
|
-
let gl = this.gl;
|
|
405
|
-
gl.clearColor(0, 0, 0, this.settings.transparent ? 0.0 : 1.0);
|
|
406
|
-
this.lineWidth = 1;
|
|
407
|
-
if (this.depthTest === "z-buffer") {
|
|
408
|
-
gl.clear(gl.DEPTH_BUFFER_BIT | gl.COLOR_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
|
|
409
|
-
} else {
|
|
410
|
-
gl.clear(gl.COLOR_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* Clears the gl context with the given color.
|
|
416
|
-
* @param {Color|string} [color="#000000"] - CSS color.
|
|
417
|
-
* @param {boolean} [opaque=false] - Allow transparency [default] or clear the surface completely [true]
|
|
418
|
-
*/
|
|
419
|
-
clearColor(color = "#000000", opaque = false) {
|
|
420
|
-
let glArray;
|
|
421
|
-
let gl = this.gl;
|
|
422
|
-
|
|
423
|
-
if (color instanceof Color) {
|
|
424
|
-
glArray = color.toArray();
|
|
425
|
-
} else {
|
|
426
|
-
let _color = pool.pull("me.Color");
|
|
427
|
-
// reuse temporary the renderer default color object
|
|
428
|
-
glArray = _color.parseCSS(color).toArray();
|
|
429
|
-
pool.push(_color);
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
// clear gl context with the specified color
|
|
433
|
-
gl.clearColor(glArray[0], glArray[1], glArray[2], (opaque === true) ? 1.0 : glArray[3]);
|
|
434
|
-
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
/**
|
|
438
|
-
* Erase the pixels in the given rectangular area by setting them to transparent black (rgba(0,0,0,0)).
|
|
439
|
-
* @param {number} x - x axis of the coordinate for the rectangle starting point.
|
|
440
|
-
* @param {number} y - y axis of the coordinate for the rectangle starting point.
|
|
441
|
-
* @param {number} width - The rectangle's width.
|
|
442
|
-
* @param {number} height - The rectangle's height.
|
|
443
|
-
*/
|
|
444
|
-
clearRect(x, y, width, height) {
|
|
445
|
-
this.save();
|
|
446
|
-
this.clipRect(x, y, width, height);
|
|
447
|
-
this.clearColor();
|
|
448
|
-
this.restore();
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
* Draw an image to the gl context
|
|
453
|
-
* @param {HTMLImageElement|SVGImageElement|HTMLVideoElement|HTMLCanvasElement|ImageBitmap|OffscreenCanvas|VideoFrame} image - An element to draw into the context.
|
|
454
|
-
* @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.
|
|
455
|
-
* @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.
|
|
456
|
-
* @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.
|
|
457
|
-
* @param {number} sh - The height of the sub-rectangle of the source image to draw into the destination context.
|
|
458
|
-
* @param {number} dx - The X coordinate in the destination canvas at which to place the top-left corner of the source image.
|
|
459
|
-
* @param {number} dy - The Y coordinate in the destination canvas at which to place the top-left corner of the source image.
|
|
460
|
-
* @param {number} dw - The width to draw the image in the destination canvas. This allows scaling of the drawn image. If not specified, the image is not scaled in width when drawn.
|
|
461
|
-
* @param {number} dh - The height to draw the image in the destination canvas. This allows scaling of the drawn image. If not specified, the image is not scaled in height when drawn.
|
|
462
|
-
* @example
|
|
463
|
-
* // Position the image on the canvas:
|
|
464
|
-
* renderer.drawImage(image, dx, dy);
|
|
465
|
-
* // Position the image on the canvas, and specify width and height of the image:
|
|
466
|
-
* renderer.drawImage(image, dx, dy, dWidth, dHeight);
|
|
467
|
-
* // Clip the image and position the clipped part on the canvas:
|
|
468
|
-
* renderer.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);
|
|
469
|
-
*/
|
|
470
|
-
drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh) {
|
|
471
|
-
if (typeof sw === "undefined") {
|
|
472
|
-
sw = dw = image.width;
|
|
473
|
-
sh = dh = image.height;
|
|
474
|
-
dx = sx;
|
|
475
|
-
dy = sy;
|
|
476
|
-
sx = 0;
|
|
477
|
-
sy = 0;
|
|
478
|
-
}
|
|
479
|
-
else if (typeof dx === "undefined") {
|
|
480
|
-
dx = sx;
|
|
481
|
-
dy = sy;
|
|
482
|
-
dw = sw;
|
|
483
|
-
dh = sh;
|
|
484
|
-
sw = image.width;
|
|
485
|
-
sh = image.height;
|
|
486
|
-
sx = 0;
|
|
487
|
-
sy = 0;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
if (this.settings.subPixel === false) {
|
|
491
|
-
// clamp to pixel grid
|
|
492
|
-
dx |= 0;
|
|
493
|
-
dy |= 0;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
this.setCompositor("quad");
|
|
497
|
-
// force reuploading if the given image is a HTMLVideoElement
|
|
498
|
-
let reupload = typeof image.videoWidth !== "undefined";
|
|
499
|
-
let texture = this.cache.get(image);
|
|
500
|
-
let uvs = texture.getUVs(sx + "," + sy + "," + sw + "," + sh);
|
|
501
|
-
this.currentCompositor.addQuad(texture, dx, dy, dw, dh, uvs[0], uvs[1], uvs[2], uvs[3], this.currentTint.toUint32(this.getGlobalAlpha()), reupload);
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
/**
|
|
505
|
-
* Draw a pattern within the given rectangle.
|
|
506
|
-
* @param {TextureAtlas} pattern - Pattern object
|
|
507
|
-
* @param {number} x - x position where to draw the pattern
|
|
508
|
-
* @param {number} y - y position where to draw the pattern
|
|
509
|
-
* @param {number} width - width of the pattern
|
|
510
|
-
* @param {number} height - height of the pattern
|
|
511
|
-
* @see WebGLRenderer#createPattern
|
|
512
|
-
*/
|
|
513
|
-
drawPattern(pattern, x, y, width, height) {
|
|
514
|
-
let uvs = pattern.getUVs("0,0," + width + "," + height);
|
|
515
|
-
this.setCompositor("quad");
|
|
516
|
-
this.currentCompositor.addQuad(pattern, x, y, width, height, uvs[0], uvs[1], uvs[2], uvs[3], this.currentTint.toUint32(this.getGlobalAlpha()));
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
/**
|
|
521
|
-
* starts a new path by emptying the list of sub-paths. Call this method when you want to create a new path
|
|
522
|
-
* @example
|
|
523
|
-
* // First path
|
|
524
|
-
* renderer.beginPath();
|
|
525
|
-
* renderer.setColor("blue");
|
|
526
|
-
* renderer.moveTo(20, 20);
|
|
527
|
-
* renderer.lineTo(200, 20);
|
|
528
|
-
* renderer.stroke();
|
|
529
|
-
* // Second path
|
|
530
|
-
* renderer.beginPath();
|
|
531
|
-
* renderer.setColor("green");
|
|
532
|
-
* renderer.moveTo(20, 20);
|
|
533
|
-
* renderer.lineTo(120, 120);
|
|
534
|
-
* renderer.stroke();
|
|
535
|
-
*/
|
|
536
|
-
beginPath() {
|
|
537
|
-
this.path2D.beginPath();
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
/**
|
|
541
|
-
* begins a new sub-path at the point specified by the given (x, y) coordinates.
|
|
542
|
-
* @param {number} x - The x axis of the point.
|
|
543
|
-
* @param {number} y - The y axis of the point.
|
|
544
|
-
*/
|
|
545
|
-
moveTo(x, y) {
|
|
546
|
-
this.path2D.moveTo(x, y);
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
/**
|
|
550
|
-
* adds a straight line to the current sub-path by connecting the sub-path's last point to the specified (x, y) coordinates.
|
|
551
|
-
*/
|
|
552
|
-
lineTo(x, y) {
|
|
553
|
-
this.path2D.lineTo(x, y);
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
/**
|
|
557
|
-
* creates a rectangular path whose starting point is at (x, y) and whose size is specified by width and height.
|
|
558
|
-
* @param {number} x - The x axis of the coordinate for the rectangle starting point.
|
|
559
|
-
* @param {number} y - The y axis of the coordinate for the rectangle starting point.
|
|
560
|
-
* @param {number} width - The rectangle's width.
|
|
561
|
-
* @param {number} height - The rectangle's height.
|
|
562
|
-
*/
|
|
563
|
-
rect(x, y, width, height) {
|
|
564
|
-
this.path2D.rect(x, y, width, height);
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
/**
|
|
568
|
-
* adds a rounded rectangle to the current path.
|
|
569
|
-
* @param {number} x - The x axis of the coordinate for the rectangle starting point.
|
|
570
|
-
* @param {number} y - The y axis of the coordinate for the rectangle starting point.
|
|
571
|
-
* @param {number} width - The rectangle's width.
|
|
572
|
-
* @param {number} height - The rectangle's height.
|
|
573
|
-
* @param {number} radius - The corner radius.
|
|
574
|
-
*/
|
|
575
|
-
roundRect(x, y, width, height, radii) {
|
|
576
|
-
this.path2D.roundRect(x, y, width, height, radii);
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
/**
|
|
580
|
-
* stroke the given shape or the current defined path
|
|
581
|
-
* @param {Rect|RoundRect|Polygon|Line|Ellipse} [shape] - a shape object to stroke
|
|
582
|
-
* @param {boolean} [fill=false] - fill the shape with the current color if true
|
|
583
|
-
*/
|
|
584
|
-
stroke(shape, fill) {
|
|
585
|
-
this.setCompositor("primitive");
|
|
586
|
-
if (typeof shape === "undefined") {
|
|
587
|
-
if (fill === true) {
|
|
588
|
-
// draw all triangles
|
|
589
|
-
this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
|
|
590
|
-
} else {
|
|
591
|
-
this.currentCompositor.drawVertices(this.gl.LINES, this.path2D.points);
|
|
592
|
-
}
|
|
593
|
-
} else {
|
|
594
|
-
super.stroke(shape, fill);
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
/**
|
|
599
|
-
* fill the given shape or the current defined path
|
|
600
|
-
* @param {Rect|RoundRect|Polygon|Line|Ellipse} [shape] - a shape object to fill
|
|
601
|
-
*/
|
|
602
|
-
fill(shape) {
|
|
603
|
-
this.stroke(shape, true);
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
/**
|
|
607
|
-
* add a straight line from the current point to the start of the current sub-path. If the shape has already been closed or has only one point, this function does nothing
|
|
608
|
-
*/
|
|
609
|
-
closePath() {
|
|
610
|
-
this.path2D.closePath();
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
/**
|
|
614
|
-
* Returns the WebGLContext instance for the renderer
|
|
615
|
-
* return a reference to the system 2d Context
|
|
616
|
-
* @returns {WebGLRenderingContext} the current WebGL context
|
|
617
|
-
*/
|
|
618
|
-
getContext() {
|
|
619
|
-
return this.gl;
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
/**
|
|
623
|
-
* set a blend mode for the given context. <br>
|
|
624
|
-
* Supported blend mode between Canvas and WebGL remderer : <br>
|
|
625
|
-
* - "normal" : this is the default mode and draws new content on top of the existing content <br>
|
|
626
|
-
* <img src="images/normal-blendmode.png" width="510"/> <br>
|
|
627
|
-
* - "multiply" : the pixels of the top layer are multiplied with the corresponding pixel of the bottom layer. A darker picture is the result. <br>
|
|
628
|
-
* <img src="images/multiply-blendmode.png" width="510"/> <br>
|
|
629
|
-
* - "additive or lighter" : where both content overlap the color is determined by adding color values. <br>
|
|
630
|
-
* <img src="images/lighter-blendmode.png" width="510"/> <br>
|
|
631
|
-
* - "screen" : The pixels are inverted, multiplied, and inverted again. A lighter picture is the result (opposite of multiply) <br>
|
|
632
|
-
* <img src="images/screen-blendmode.png" width="510"/> <br>
|
|
633
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
|
|
634
|
-
* @param {string} [mode="normal"] - blend mode : "normal", "multiply", "lighter", "additive", "screen"
|
|
635
|
-
* @param {WebGLRenderingContext} [gl] - a WebGL context
|
|
636
|
-
*/
|
|
637
|
-
setBlendMode(mode = "normal", gl = this.gl) {
|
|
638
|
-
|
|
639
|
-
if (this.currentBlendMode !== mode) {
|
|
640
|
-
this.flush();
|
|
641
|
-
gl.enable(gl.BLEND);
|
|
642
|
-
this.currentBlendMode = mode;
|
|
643
|
-
|
|
644
|
-
switch (mode) {
|
|
645
|
-
case "screen" :
|
|
646
|
-
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_COLOR);
|
|
647
|
-
break;
|
|
648
|
-
|
|
649
|
-
case "lighter" :
|
|
650
|
-
case "additive" :
|
|
651
|
-
gl.blendFunc(gl.ONE, gl.ONE);
|
|
652
|
-
break;
|
|
653
|
-
|
|
654
|
-
case "multiply" :
|
|
655
|
-
gl.blendFunc(gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA);
|
|
656
|
-
break;
|
|
657
|
-
|
|
658
|
-
default :
|
|
659
|
-
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
|
660
|
-
this.currentBlendMode = "normal";
|
|
661
|
-
break;
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
/**
|
|
667
|
-
* restores the most recently saved renderer state by popping the top entry in the drawing state stack
|
|
668
|
-
* @example
|
|
669
|
-
* // Save the current state
|
|
670
|
-
* renderer.save();
|
|
671
|
-
*
|
|
672
|
-
* // apply a transform and draw a rect
|
|
673
|
-
* renderer.tranform(matrix);
|
|
674
|
-
* renderer.fillRect(10, 10, 100, 100);
|
|
675
|
-
*
|
|
676
|
-
* // Restore to the state saved by the most recent call to save()
|
|
677
|
-
* renderer.restore();
|
|
678
|
-
*/
|
|
679
|
-
restore() {
|
|
680
|
-
// do nothing if there is no saved states
|
|
681
|
-
if (this._matrixStack.length !== 0) {
|
|
682
|
-
let color = this._colorStack.pop();
|
|
683
|
-
let matrix = this._matrixStack.pop();
|
|
684
|
-
|
|
685
|
-
// restore the previous context
|
|
686
|
-
this.currentColor.copy(color);
|
|
687
|
-
this.currentTransform.copy(matrix);
|
|
688
|
-
|
|
689
|
-
this.setBlendMode(this._blendStack.pop());
|
|
690
|
-
|
|
691
|
-
// recycle objects
|
|
692
|
-
pool.push(color);
|
|
693
|
-
pool.push(matrix);
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
if (this._scissorStack.length !== 0) {
|
|
697
|
-
// FIXME : prevent `scissor` object realloc and GC
|
|
698
|
-
this.currentScissor.set(this._scissorStack.pop());
|
|
699
|
-
} else {
|
|
700
|
-
const canvas = this.getCanvas();
|
|
701
|
-
// turn off scissor test
|
|
702
|
-
this.gl.disable(this.gl.SCISSOR_TEST);
|
|
703
|
-
this.currentScissor[0] = 0;
|
|
704
|
-
this.currentScissor[1] = 0;
|
|
705
|
-
this.currentScissor[2] = canvas.width;
|
|
706
|
-
this.currentScissor[3] = canvas.height;
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
/**
|
|
711
|
-
* saves the entire state of the renderer by pushing the current state onto a stack.
|
|
712
|
-
* @example
|
|
713
|
-
* // Save the current state
|
|
714
|
-
* renderer.save();
|
|
715
|
-
*
|
|
716
|
-
* // apply a transform and draw a rect
|
|
717
|
-
* renderer.tranform(matrix);
|
|
718
|
-
* renderer.fillRect(10, 10, 100, 100);
|
|
719
|
-
*
|
|
720
|
-
* // Restore to the state saved by the most recent call to save()
|
|
721
|
-
* renderer.restore();
|
|
722
|
-
*/
|
|
723
|
-
save() {
|
|
724
|
-
this._colorStack.push(this.currentColor.clone());
|
|
725
|
-
this._matrixStack.push(this.currentTransform.clone());
|
|
726
|
-
|
|
727
|
-
if (this.gl.isEnabled(this.gl.SCISSOR_TEST)) {
|
|
728
|
-
// FIXME avoid slice and object realloc
|
|
729
|
-
this._scissorStack.push(this.currentScissor.slice());
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
this._blendStack.push(this.getBlendMode());
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
/**
|
|
736
|
-
* adds a rotation to the transformation matrix.
|
|
737
|
-
* @param {number} angle - the rotation angle, clockwise in radians
|
|
738
|
-
* @example
|
|
739
|
-
* // Rotated rectangle
|
|
740
|
-
* renderer.rotate((45 * Math.PI) / 180);
|
|
741
|
-
* renderer.setColor("red");
|
|
742
|
-
* renderer.fillRect(10, 10, 100, 100);
|
|
743
|
-
*
|
|
744
|
-
* // Reset transformation matrix to the identity matrix
|
|
745
|
-
* renderer.setTransform(1, 0, 0, 1, 0, 0);
|
|
746
|
-
*/
|
|
747
|
-
rotate(angle) {
|
|
748
|
-
this.currentTransform.rotate(angle);
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
/**
|
|
752
|
-
* adds a scaling transformation to the renderer units horizontally and/or vertically
|
|
753
|
-
* @param {number} x - Scaling factor in the horizontal direction. A negative value flips pixels across the vertical axis. A value of 1 results in no horizontal scaling.
|
|
754
|
-
* @param {number} y - Scaling factor in the vertical direction. A negative value flips pixels across the horizontal axis. A value of 1 results in no vertical scaling
|
|
755
|
-
*/
|
|
756
|
-
scale(x, y) {
|
|
757
|
-
this.currentTransform.scale(x, y);
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
/**
|
|
761
|
-
* not used by this renderer?
|
|
762
|
-
* @ignore
|
|
763
|
-
*/
|
|
764
|
-
setAntiAlias(context, enable) {
|
|
765
|
-
super.setAntiAlias(context, enable);
|
|
766
|
-
// TODO: perhaps handle GLNEAREST or other options with texture binding
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
/**
|
|
770
|
-
* Set the global alpha
|
|
771
|
-
* @param {number} alpha - 0.0 to 1.0 values accepted.
|
|
772
|
-
*/
|
|
773
|
-
setGlobalAlpha(alpha) {
|
|
774
|
-
this.currentColor.alpha = alpha;
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
/**
|
|
778
|
-
* Return the global alpha
|
|
779
|
-
* @returns {number} global alpha value
|
|
780
|
-
*/
|
|
781
|
-
getGlobalAlpha() {
|
|
782
|
-
return this.currentColor.alpha;
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
/**
|
|
786
|
-
* Set the current fill & stroke style color.
|
|
787
|
-
* By default, or upon reset, the value is set to #000000.
|
|
788
|
-
* @param {Color|string} color - css color string.
|
|
789
|
-
*/
|
|
790
|
-
setColor(color) {
|
|
791
|
-
let alpha = this.currentColor.alpha;
|
|
792
|
-
this.currentColor.copy(color);
|
|
793
|
-
this.currentColor.alpha *= alpha;
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
/**
|
|
797
|
-
* Stroke an arc at the specified coordinates with given radius, start and end points
|
|
798
|
-
* @param {number} x - arc center point x-axis
|
|
799
|
-
* @param {number} y - arc center point y-axis
|
|
800
|
-
* @param {number} radius - arc radius
|
|
801
|
-
* @param {number} start - start angle in radians
|
|
802
|
-
* @param {number} end - end angle in radians
|
|
803
|
-
* @param {boolean} [antiClockwise=false] - draw arc anti-clockwise
|
|
804
|
-
* @param {boolean} [fill=false] - also fill the shape with the current color if true
|
|
805
|
-
*/
|
|
806
|
-
strokeArc(x, y, radius, start, end, antiClockwise = false, fill = false) {
|
|
807
|
-
this.setCompositor("primitive");
|
|
808
|
-
this.path2D.beginPath();
|
|
809
|
-
this.path2D.arc(x, y, radius, start, end, antiClockwise);
|
|
810
|
-
if (fill === false) {
|
|
811
|
-
this.currentCompositor.drawVertices(this.gl.LINES, this.path2D.points);
|
|
812
|
-
} else {
|
|
813
|
-
this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
/**
|
|
818
|
-
* Fill an arc at the specified coordinates with given radius, start and end points
|
|
819
|
-
* @param {number} x - arc center point x-axis
|
|
820
|
-
* @param {number} y - arc center point y-axis
|
|
821
|
-
* @param {number} radius - arc radius
|
|
822
|
-
* @param {number} start - start angle in radians
|
|
823
|
-
* @param {number} end - end angle in radians
|
|
824
|
-
* @param {boolean} [antiClockwise=false] - draw arc anti-clockwise
|
|
825
|
-
*/
|
|
826
|
-
fillArc(x, y, radius, start, end, antiClockwise = false) {
|
|
827
|
-
this.strokeArc(x, y, radius, start, end, antiClockwise, true);
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
/**
|
|
831
|
-
* Stroke an ellipse at the specified coordinates with given radius
|
|
832
|
-
* @param {number} x - ellipse center point x-axis
|
|
833
|
-
* @param {number} y - ellipse center point y-axis
|
|
834
|
-
* @param {number} w - horizontal radius of the ellipse
|
|
835
|
-
* @param {number} h - vertical radius of the ellipse
|
|
836
|
-
* @param {boolean} [fill=false] - also fill the shape with the current color if true
|
|
837
|
-
*/
|
|
838
|
-
strokeEllipse(x, y, w, h, fill = false) {
|
|
839
|
-
this.setCompositor("primitive");
|
|
840
|
-
this.path2D.beginPath();
|
|
841
|
-
this.path2D.ellipse(x, y, w, h, 0, 0, 360);
|
|
842
|
-
if (fill === false) {
|
|
843
|
-
this.currentCompositor.drawVertices(this.gl.LINES, this.path2D.points);
|
|
844
|
-
} else {
|
|
845
|
-
this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
/**
|
|
850
|
-
* Fill an ellipse at the specified coordinates with given radius
|
|
851
|
-
* @param {number} x - ellipse center point x-axis
|
|
852
|
-
* @param {number} y - ellipse center point y-axis
|
|
853
|
-
* @param {number} w - horizontal radius of the ellipse
|
|
854
|
-
* @param {number} h - vertical radius of the ellipse
|
|
855
|
-
*/
|
|
856
|
-
fillEllipse(x, y, w, h) {
|
|
857
|
-
this.strokeEllipse(x, y, w, h, false);
|
|
858
|
-
}
|
|
859
|
-
|
|
860
|
-
/**
|
|
861
|
-
* Stroke a line of the given two points
|
|
862
|
-
* @param {number} startX - the start x coordinate
|
|
863
|
-
* @param {number} startY - the start y coordinate
|
|
864
|
-
* @param {number} endX - the end x coordinate
|
|
865
|
-
* @param {number} endY - the end y coordinate
|
|
866
|
-
*/
|
|
867
|
-
strokeLine(startX, startY, endX, endY) {
|
|
868
|
-
this.setCompositor("primitive");
|
|
869
|
-
if (this.lineWidth === 1) {
|
|
870
|
-
this.path2D.beginPath();
|
|
871
|
-
this.path2D.moveTo(startX, startY);
|
|
872
|
-
this.path2D.lineTo(endX, endY);
|
|
873
|
-
this.currentCompositor.drawVertices(this.gl.LINES, this.path2D.points);
|
|
874
|
-
} else if (this.lineWidth > 1) {
|
|
875
|
-
const halfWidth = this.lineWidth / 2;
|
|
876
|
-
const angle = Math.atan2(endY - startY, endX - startX);
|
|
877
|
-
const dx = Math.sin(angle) * halfWidth;
|
|
878
|
-
const dy = Math.cos(angle) * halfWidth;
|
|
879
|
-
const x1 = startX - dx;
|
|
880
|
-
const y1 = startY + dy;
|
|
881
|
-
const x2 = startX + dx;
|
|
882
|
-
const y2 = startY - dy;
|
|
883
|
-
const x3 = endX + dx;
|
|
884
|
-
const y3 = endY - dy;
|
|
885
|
-
const x4 = endX - dx;
|
|
886
|
-
const y4 = endY + dy;
|
|
887
|
-
|
|
888
|
-
this.path2D.beginPath();
|
|
889
|
-
this.path2D.moveTo(x1, y1);
|
|
890
|
-
this.path2D.lineTo(x2, y2);
|
|
891
|
-
this.path2D.lineTo(x3, y3);
|
|
892
|
-
this.path2D.lineTo(x4, y4);
|
|
893
|
-
this.path2D.closePath();
|
|
894
|
-
// draw all triangles
|
|
895
|
-
this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
/**
|
|
901
|
-
* Fill a line of the given two points
|
|
902
|
-
* @param {number} startX - the start x coordinate
|
|
903
|
-
* @param {number} startY - the start y coordinate
|
|
904
|
-
* @param {number} endX - the end x coordinate
|
|
905
|
-
* @param {number} endY - the end y coordinate
|
|
906
|
-
*/
|
|
907
|
-
fillLine(startX, startY, endX, endY) {
|
|
908
|
-
this.strokeLine(startX, startY, endX, endY);
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
/**
|
|
912
|
-
* Stroke a me.Polygon on the screen with a specified color
|
|
913
|
-
* @param {Polygon} poly - the shape to draw
|
|
914
|
-
* @param {boolean} [fill=false] - also fill the shape with the current color if true
|
|
915
|
-
*/
|
|
916
|
-
strokePolygon(poly, fill = false) {
|
|
917
|
-
const points = poly.points;
|
|
918
|
-
const len = points.length;
|
|
919
|
-
|
|
920
|
-
this.setCompositor("primitive");
|
|
921
|
-
|
|
922
|
-
this.translate(poly.pos.x, poly.pos.y);
|
|
923
|
-
|
|
924
|
-
this.path2D.beginPath();
|
|
925
|
-
for (let i = 0; i < len - 1; i++) {
|
|
926
|
-
const curPoint = points[i];
|
|
927
|
-
const nextPoint = points[i + 1];
|
|
928
|
-
this.path2D.moveTo(curPoint.x, curPoint.y);
|
|
929
|
-
this.path2D.lineTo(nextPoint.x, nextPoint.y);
|
|
930
|
-
}
|
|
931
|
-
this.path2D.closePath();
|
|
932
|
-
|
|
933
|
-
if (fill === false) {
|
|
934
|
-
this.currentCompositor.drawVertices(this.gl.LINES, this.path2D.points);
|
|
935
|
-
} else {
|
|
936
|
-
// draw all triangles
|
|
937
|
-
this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
this.translate(-poly.pos.x, -poly.pos.y);
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
/**
|
|
944
|
-
* Fill a me.Polygon on the screen
|
|
945
|
-
* @param {Polygon} poly - the shape to draw
|
|
946
|
-
*/
|
|
947
|
-
fillPolygon(poly) {
|
|
948
|
-
this.strokePolygon(poly, true);
|
|
949
|
-
}
|
|
950
|
-
|
|
951
|
-
/**
|
|
952
|
-
* Draw a stroke rectangle at the specified coordinates
|
|
953
|
-
* @param {number} x - x axis of the coordinate for the rectangle starting point.
|
|
954
|
-
* @param {number} y - y axis of the coordinate for the rectangle starting point.
|
|
955
|
-
* @param {number} width - The rectangle's width.
|
|
956
|
-
* @param {number} height - The rectangle's height.
|
|
957
|
-
* @param {boolean} [fill=false] - also fill the shape with the current color if true
|
|
958
|
-
*/
|
|
959
|
-
strokeRect(x, y, width, height, fill = false) {
|
|
960
|
-
this.setCompositor("primitive");
|
|
961
|
-
this.path2D.beginPath();
|
|
962
|
-
this.path2D.rect(x, y, width, height);
|
|
963
|
-
if (fill === false) {
|
|
964
|
-
this.currentCompositor.drawVertices(this.gl.LINES, this.path2D.points);
|
|
965
|
-
} else {
|
|
966
|
-
this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
/**
|
|
971
|
-
* Draw a filled rectangle at the specified coordinates
|
|
972
|
-
* @param {number} x - x axis of the coordinate for the rectangle starting point.
|
|
973
|
-
* @param {number} y - y axis of the coordinate for the rectangle starting point.
|
|
974
|
-
* @param {number} width - The rectangle's width.
|
|
975
|
-
* @param {number} height - The rectangle's height.
|
|
976
|
-
*/
|
|
977
|
-
fillRect(x, y, width, height) {
|
|
978
|
-
this.strokeRect(x, y, width, height, true);
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
/**
|
|
982
|
-
* Stroke a rounded rectangle at the specified coordinates
|
|
983
|
-
* @param {number} x - x axis of the coordinate for the rounded rectangle starting point.
|
|
984
|
-
* @param {number} y - y axis of the coordinate for the rounded rectangle starting point.
|
|
985
|
-
* @param {number} width - The rounded rectangle's width.
|
|
986
|
-
* @param {number} height - The rounded rectangle's height.
|
|
987
|
-
* @param {number} radius - The rounded corner's radius.
|
|
988
|
-
* @param {boolean} [fill=false] - also fill the shape with the current color if true
|
|
989
|
-
*/
|
|
990
|
-
strokeRoundRect(x, y, width, height, radius, fill = false) {
|
|
991
|
-
this.setCompositor("primitive");
|
|
992
|
-
this.path2D.beginPath();
|
|
993
|
-
this.path2D.roundRect(x, y, width, height, radius);
|
|
994
|
-
if (fill === false) {
|
|
995
|
-
this.currentCompositor.drawVertices(this.gl.LINES, this.path2D.points);
|
|
996
|
-
} else {
|
|
997
|
-
this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
/**
|
|
1002
|
-
* Draw a rounded filled rectangle at the specified coordinates
|
|
1003
|
-
* @param {number} x - x axis of the coordinate for the rounded rectangle starting point.
|
|
1004
|
-
* @param {number} y - y axis of the coordinate for the rounded rectangle starting point.
|
|
1005
|
-
* @param {number} width - The rounded rectangle's width.
|
|
1006
|
-
* @param {number} height - The rounded rectangle's height.
|
|
1007
|
-
* @param {number} radius - The rounded corner's radius.
|
|
1008
|
-
*/
|
|
1009
|
-
fillRoundRect(x, y, width, height, radius) {
|
|
1010
|
-
this.strokeRoundRect(x, y, width, height, radius, true);
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
/**
|
|
1014
|
-
* Stroke a Point at the specified coordinates
|
|
1015
|
-
* @param {number} x - x axis of the coordinate for the point.
|
|
1016
|
-
* @param {number} y - y axis of the coordinate for the point.
|
|
1017
|
-
*/
|
|
1018
|
-
strokePoint(x, y) {
|
|
1019
|
-
this.strokeLine(x, y, x + 1, y + 1);
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
/**
|
|
1023
|
-
* Draw a a point at the specified coordinates
|
|
1024
|
-
* @param {number} x - x axis of the coordinate for the point.
|
|
1025
|
-
* @param {number} y - y axis of the coordinate for the point.
|
|
1026
|
-
*/
|
|
1027
|
-
fillPoint(x, y) {
|
|
1028
|
-
this.strokePoint(x, y);
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
/**
|
|
1032
|
-
* Reset (overrides) the renderer transformation matrix to the
|
|
1033
|
-
* identity one, and then apply the given transformation matrix.
|
|
1034
|
-
* @param {Matrix2d|number} a - a matrix2d to transform by, or a the a component to multiply the current matrix by
|
|
1035
|
-
* @param {number} b - the b component to multiply the current matrix by
|
|
1036
|
-
* @param {number} c - the c component to multiply the current matrix by
|
|
1037
|
-
* @param {number} d - the d component to multiply the current matrix by
|
|
1038
|
-
* @param {number} e - the e component to multiply the current matrix by
|
|
1039
|
-
* @param {number} f - the f component to multiply the current matrix by
|
|
1040
|
-
*/
|
|
1041
|
-
setTransform(a, b, c, d, e, f) {
|
|
1042
|
-
this.resetTransform();
|
|
1043
|
-
this.transform(a, b, c, d, e, f);
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
/**
|
|
1047
|
-
* Multiply given matrix into the renderer tranformation matrix
|
|
1048
|
-
* @see {@link WebGLRenderer.setTransform} which will reset the current transform matrix prior to performing the new transformation
|
|
1049
|
-
* @param {Matrix2d|number} a - a matrix2d to transform by, or a the a component to multiply the current matrix by
|
|
1050
|
-
* @param {number} b - the b component to multiply the current matrix by
|
|
1051
|
-
* @param {number} c - the c component to multiply the current matrix by
|
|
1052
|
-
* @param {number} d - the d component to multiply the current matrix by
|
|
1053
|
-
* @param {number} e - the e component to multiply the current matrix by
|
|
1054
|
-
* @param {number} f - the f component to multiply the current matrix by
|
|
1055
|
-
*/
|
|
1056
|
-
transform(a, b, c, d, e, f) {
|
|
1057
|
-
if (typeof a === "object") {
|
|
1058
|
-
this.currentTransform.multiply(a);
|
|
1059
|
-
} else {
|
|
1060
|
-
// indivudual component
|
|
1061
|
-
this.currentTransform.transform(a, b, c, d, e, f);
|
|
1062
|
-
}
|
|
1063
|
-
if (this.settings.subPixel === false) {
|
|
1064
|
-
// snap position values to pixel grid
|
|
1065
|
-
let a = this.currentTransform.toArray();
|
|
1066
|
-
a[6] |= 0;
|
|
1067
|
-
a[7] |= 0;
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
|
-
/**
|
|
1072
|
-
* adds a translation transformation to the current matrix.
|
|
1073
|
-
* @param {number} x - Distance to move in the horizontal direction. Positive values are to the right, and negative to the left.
|
|
1074
|
-
* @param {number} y - Distance to move in the vertical direction. Positive values are down, and negative are up.
|
|
1075
|
-
*/
|
|
1076
|
-
translate(x, y) {
|
|
1077
|
-
let currentTransform = this.currentTransform;
|
|
1078
|
-
currentTransform.translate(x, y);
|
|
1079
|
-
if (this.settings.subPixel === false) {
|
|
1080
|
-
// snap position values to pixel grid
|
|
1081
|
-
let a = currentTransform.toArray();
|
|
1082
|
-
a[6] |= 0;
|
|
1083
|
-
a[7] |= 0;
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
/**
|
|
1088
|
-
* clip the given region from the original canvas. Once a region is clipped,
|
|
1089
|
-
* all future drawing will be limited to the clipped region.
|
|
1090
|
-
* You can however save the current region using the save(),
|
|
1091
|
-
* and restore it (with the restore() method) any time in the future.
|
|
1092
|
-
* (<u>this is an experimental feature !</u>)
|
|
1093
|
-
* @param {number} x - x axis of the coordinate for the upper-left corner of the rectangle to start clipping from.
|
|
1094
|
-
* @param {number} y - y axis of the coordinate for the upper-left corner of the rectangle to start clipping from.
|
|
1095
|
-
* @param {number} width - the width of the rectangle to start clipping from.
|
|
1096
|
-
* @param {number} height - the height of the rectangle to start clipping from.
|
|
1097
|
-
*/
|
|
1098
|
-
clipRect(x, y, width, height) {
|
|
1099
|
-
let canvas = this.getCanvas();
|
|
1100
|
-
let gl = this.gl;
|
|
1101
|
-
// if requested box is different from the current canvas size
|
|
1102
|
-
if (x !== 0 || y !== 0 || width !== canvas.width || height !== canvas.height) {
|
|
1103
|
-
let currentScissor = this.currentScissor;
|
|
1104
|
-
if (gl.isEnabled(gl.SCISSOR_TEST)) {
|
|
1105
|
-
// if same as the current scissor box do nothing
|
|
1106
|
-
if (currentScissor[0] === x && currentScissor[1] === y &&
|
|
1107
|
-
currentScissor[2] === width && currentScissor[3] === height) {
|
|
1108
|
-
return;
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
// flush the compositor
|
|
1112
|
-
this.flush();
|
|
1113
|
-
// turn on scissor test
|
|
1114
|
-
gl.enable(this.gl.SCISSOR_TEST);
|
|
1115
|
-
// set the scissor rectangle (note : coordinates are left/bottom)
|
|
1116
|
-
gl.scissor(
|
|
1117
|
-
// scissor does not account for currentTransform, so manually adjust
|
|
1118
|
-
x + this.currentTransform.tx,
|
|
1119
|
-
canvas.height - height - y - this.currentTransform.ty,
|
|
1120
|
-
width,
|
|
1121
|
-
height
|
|
1122
|
-
);
|
|
1123
|
-
// save the new currentScissor box
|
|
1124
|
-
currentScissor[0] = x;
|
|
1125
|
-
currentScissor[1] = y;
|
|
1126
|
-
currentScissor[2] = width;
|
|
1127
|
-
currentScissor[3] = height;
|
|
1128
|
-
} else {
|
|
1129
|
-
// turn off scissor test
|
|
1130
|
-
gl.disable(gl.SCISSOR_TEST);
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
/**
|
|
1135
|
-
* A mask limits rendering elements to the shape and position of the given mask object.
|
|
1136
|
-
* If the drawing or rendering area is larger than the mask, only the intersecting part of the renderable will be visible.
|
|
1137
|
-
* (Note Mask are not preserved through renderer context save and restore and need so be manually cleared)
|
|
1138
|
-
* @see CanvasRenderer#clearMask
|
|
1139
|
-
* @param {Rect|RoundRect|Polygon|Line|Ellipse} [mask] - a shape defining the mask to be applied
|
|
1140
|
-
* @param {boolean} [invert=false] - either the given shape should define what is visible (default) or the opposite
|
|
1141
|
-
*/
|
|
1142
|
-
setMask(mask, invert = false) {
|
|
1143
|
-
let gl = this.gl;
|
|
1144
|
-
|
|
1145
|
-
// flush the compositor
|
|
1146
|
-
this.flush();
|
|
1147
|
-
|
|
1148
|
-
if (this.maskLevel === 0) {
|
|
1149
|
-
// Enable and setup GL state to write to stencil buffer
|
|
1150
|
-
gl.enable(gl.STENCIL_TEST);
|
|
1151
|
-
gl.clear(gl.STENCIL_BUFFER_BIT);
|
|
1152
|
-
}
|
|
1153
|
-
|
|
1154
|
-
this.maskLevel++;
|
|
1155
|
-
|
|
1156
|
-
gl.colorMask(false, false, false, false);
|
|
1157
|
-
gl.stencilFunc(gl.EQUAL, this.maskLevel, 1);
|
|
1158
|
-
gl.stencilOp(gl.REPLACE, gl.REPLACE, gl.REPLACE);
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
// fill the given mask shape
|
|
1162
|
-
this.fill(mask);
|
|
1163
|
-
|
|
1164
|
-
// flush the compositor
|
|
1165
|
-
this.flush();
|
|
1166
|
-
|
|
1167
|
-
gl.colorMask(true, true, true, true);
|
|
1168
|
-
|
|
1169
|
-
// Use stencil buffer to affect next rendering object
|
|
1170
|
-
if (invert === true) {
|
|
1171
|
-
gl.stencilFunc(gl.EQUAL, this.maskLevel + 1, 1);
|
|
1172
|
-
} else {
|
|
1173
|
-
gl.stencilFunc(gl.NOTEQUAL, this.maskLevel + 1, 1);
|
|
1174
|
-
}
|
|
1175
|
-
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
|
-
/**
|
|
1179
|
-
* disable (remove) the rendering mask set through setMask.
|
|
1180
|
-
* @see WebGLRenderer#setMask
|
|
1181
|
-
*/
|
|
1182
|
-
clearMask() {
|
|
1183
|
-
if (this.maskLevel > 0) {
|
|
1184
|
-
// flush the compositor
|
|
1185
|
-
this.flush();
|
|
1186
|
-
this.maskLevel = 0;
|
|
1187
|
-
this.gl.disable(this.gl.STENCIL_TEST);
|
|
1188
|
-
}
|
|
1189
|
-
}
|
|
1190
|
-
}
|