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.
Files changed (315) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +6 -6
  3. package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
  4. package/dist/melonjs.mjs/_virtual/arraymultimap.js +1 -1
  5. package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
  6. package/dist/melonjs.mjs/_virtual/howler.js +1 -1
  7. package/dist/melonjs.mjs/_virtual/index.js +7 -3
  8. package/dist/melonjs.mjs/_virtual/index2.js +1 -1
  9. package/dist/melonjs.mjs/_virtual/multimap.js +1 -1
  10. package/dist/melonjs.mjs/_virtual/setmultimap.js +1 -1
  11. package/dist/melonjs.mjs/application/application.js +27 -17
  12. package/dist/melonjs.mjs/application/header.js +6 -5
  13. package/dist/melonjs.mjs/application/resize.js +20 -20
  14. package/dist/melonjs.mjs/application/settings.js +1 -1
  15. package/dist/melonjs.mjs/audio/audio.js +18 -20
  16. package/dist/melonjs.mjs/camera/camera2d.js +10 -10
  17. package/dist/melonjs.mjs/const.js +1 -1
  18. package/dist/melonjs.mjs/entity/entity.js +4 -4
  19. package/dist/melonjs.mjs/geometries/ellipse.js +6 -6
  20. package/dist/melonjs.mjs/geometries/line.js +9 -9
  21. package/dist/melonjs.mjs/geometries/path2d.js +56 -56
  22. package/dist/melonjs.mjs/geometries/point.js +2 -2
  23. package/dist/melonjs.mjs/geometries/poly.js +29 -29
  24. package/dist/melonjs.mjs/geometries/rectangle.js +8 -8
  25. package/dist/melonjs.mjs/geometries/roundrect.js +6 -6
  26. package/dist/melonjs.mjs/index.js +8 -6
  27. package/dist/melonjs.mjs/input/gamepad.js +30 -30
  28. package/dist/melonjs.mjs/input/input.js +2 -2
  29. package/dist/melonjs.mjs/input/keyboard.js +15 -15
  30. package/dist/melonjs.mjs/input/pointer.js +2 -2
  31. package/dist/melonjs.mjs/input/pointerevent.js +59 -59
  32. package/dist/melonjs.mjs/lang/console.js +3 -3
  33. package/dist/melonjs.mjs/lang/deprecated.js +2 -2
  34. package/dist/melonjs.mjs/level/level.js +9 -9
  35. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +3 -3
  36. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +31 -31
  37. package/dist/melonjs.mjs/level/tiled/TMXObject.js +8 -8
  38. package/dist/melonjs.mjs/level/tiled/TMXTile.js +8 -8
  39. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +19 -19
  40. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +15 -15
  41. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +3 -3
  42. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +46 -41
  43. package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
  44. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +30 -30
  45. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +21 -21
  46. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +10 -10
  47. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
  48. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +6 -6
  49. package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
  50. package/dist/melonjs.mjs/loader/cache.js +1 -1
  51. package/dist/melonjs.mjs/loader/loader.js +7 -7
  52. package/dist/melonjs.mjs/loader/loadingscreen.js +2 -2
  53. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
  54. package/dist/melonjs.mjs/loader/parser.js +13 -13
  55. package/dist/melonjs.mjs/loader/settings.js +3 -3
  56. package/dist/melonjs.mjs/math/color.js +25 -24
  57. package/dist/melonjs.mjs/math/math.js +2 -2
  58. package/dist/melonjs.mjs/math/matrix2.js +22 -22
  59. package/dist/melonjs.mjs/math/matrix3.js +52 -52
  60. package/dist/melonjs.mjs/math/observable_vector2.js +12 -12
  61. package/dist/melonjs.mjs/math/observable_vector3.js +22 -22
  62. package/dist/melonjs.mjs/math/vector2.js +11 -11
  63. package/dist/melonjs.mjs/math/vector3.js +21 -21
  64. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +45 -0
  65. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +130 -0
  66. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
  67. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
  68. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
  69. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
  70. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
  71. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +2 -2
  72. package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
  73. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
  74. package/dist/melonjs.mjs/particles/emitter.js +5 -5
  75. package/dist/melonjs.mjs/particles/particle.js +8 -8
  76. package/dist/melonjs.mjs/particles/settings.js +3 -3
  77. package/dist/melonjs.mjs/physics/body.js +17 -17
  78. package/dist/melonjs.mjs/physics/bounds.js +12 -12
  79. package/dist/melonjs.mjs/physics/collision.js +3 -3
  80. package/dist/melonjs.mjs/physics/detector.js +14 -14
  81. package/dist/melonjs.mjs/physics/quadtree.js +19 -19
  82. package/dist/melonjs.mjs/physics/response.js +1 -1
  83. package/dist/melonjs.mjs/physics/sat.js +60 -60
  84. package/dist/melonjs.mjs/physics/world.js +4 -4
  85. package/dist/melonjs.mjs/plugin/plugin.js +11 -11
  86. package/dist/melonjs.mjs/renderable/collectable.js +2 -2
  87. package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
  88. package/dist/melonjs.mjs/renderable/container.js +77 -59
  89. package/dist/melonjs.mjs/renderable/dragndrop.js +5 -5
  90. package/dist/melonjs.mjs/renderable/imagelayer.js +7 -6
  91. package/dist/melonjs.mjs/renderable/light2d.js +6 -6
  92. package/dist/melonjs.mjs/renderable/nineslicesprite.js +12 -12
  93. package/dist/melonjs.mjs/renderable/renderable.js +35 -13
  94. package/dist/melonjs.mjs/renderable/sprite.js +25 -25
  95. package/dist/melonjs.mjs/renderable/trigger.js +11 -9
  96. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +97 -27
  97. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +25 -25
  98. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +83 -65
  99. package/dist/melonjs.mjs/state/stage.js +7 -7
  100. package/dist/melonjs.mjs/state/state.js +15 -15
  101. package/dist/melonjs.mjs/system/device.js +3 -3
  102. package/dist/melonjs.mjs/system/dom.js +1 -1
  103. package/dist/melonjs.mjs/system/event.js +2 -2
  104. package/dist/melonjs.mjs/system/platform.js +1 -1
  105. package/dist/melonjs.mjs/system/pooling.js +9 -9
  106. package/dist/melonjs.mjs/system/save.js +6 -6
  107. package/dist/melonjs.mjs/system/timer.js +16 -12
  108. package/dist/melonjs.mjs/text/bitmaptext.js +20 -20
  109. package/dist/melonjs.mjs/text/bitmaptextdata.js +22 -22
  110. package/dist/melonjs.mjs/text/glyph.js +3 -3
  111. package/dist/melonjs.mjs/text/text.js +63 -92
  112. package/dist/melonjs.mjs/text/textmetrics.js +15 -15
  113. package/dist/melonjs.mjs/text/textstyle.js +4 -6
  114. package/dist/melonjs.mjs/tweens/easing.js +4 -4
  115. package/dist/melonjs.mjs/tweens/interpolation.js +8 -8
  116. package/dist/melonjs.mjs/tweens/tween.js +11 -11
  117. package/dist/melonjs.mjs/utils/agent.js +6 -6
  118. package/dist/melonjs.mjs/utils/array.js +4 -4
  119. package/dist/melonjs.mjs/utils/file.js +1 -1
  120. package/dist/melonjs.mjs/utils/function.js +5 -5
  121. package/dist/melonjs.mjs/utils/string.js +3 -3
  122. package/dist/melonjs.mjs/utils/utils.js +16 -16
  123. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +41 -119
  124. package/dist/melonjs.mjs/video/renderer.js +70 -14
  125. package/dist/melonjs.mjs/video/texture/atlas.js +39 -45
  126. package/dist/melonjs.mjs/video/texture/cache.js +9 -10
  127. package/dist/melonjs.mjs/video/texture/canvas_texture.js +63 -3
  128. package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
  129. package/dist/melonjs.mjs/video/video.js +2 -2
  130. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +23 -19
  131. package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +80 -80
  132. package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +77 -0
  133. package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +252 -0
  134. package/dist/melonjs.mjs/video/webgl/compositors/webgl_compositor.js +1 -1
  135. package/dist/melonjs.mjs/video/webgl/glshader.js +7 -7
  136. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
  137. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +2 -2
  138. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
  139. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +2 -2
  140. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +2 -2
  141. package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
  142. package/dist/melonjs.mjs/video/webgl/utils/program.js +7 -7
  143. package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
  144. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +4 -4
  145. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +188 -181
  146. package/dist/melonjs.module.js +25040 -25193
  147. package/dist/types/application/application.d.ts +11 -8
  148. package/dist/types/audio/audio.d.ts +3 -3
  149. package/dist/types/entity/entity.d.ts +1 -1
  150. package/dist/types/index.d.ts +7 -4
  151. package/dist/types/input/input.d.ts +1 -1
  152. package/dist/types/input/keyboard.d.ts +1 -1
  153. package/dist/types/input/pointerevent.d.ts +6 -6
  154. package/dist/types/level/level.d.ts +2 -2
  155. package/dist/types/level/tiled/TMXLayer.d.ts +4 -4
  156. package/dist/types/level/tiled/TMXTileMap.d.ts +2 -2
  157. package/dist/types/level/tiled/TMXUtils.d.ts +5 -4
  158. package/dist/types/loader/loader.d.ts +2 -2
  159. package/dist/types/loader/settings.d.ts +2 -2
  160. package/dist/types/particles/emitter.d.ts +1 -1
  161. package/dist/types/physics/collision.d.ts +1 -1
  162. package/dist/types/physics/detector.d.ts +1 -1
  163. package/dist/types/plugin/plugin.d.ts +2 -2
  164. package/dist/types/renderable/container.d.ts +21 -17
  165. package/dist/types/renderable/renderable.d.ts +6 -0
  166. package/dist/types/renderable/sprite.d.ts +11 -11
  167. package/dist/types/renderable/trigger.d.ts +1 -1
  168. package/dist/types/renderable/ui/uibaseelement.d.ts +28 -6
  169. package/dist/types/renderable/ui/uispriteelement.d.ts +12 -14
  170. package/dist/types/renderable/ui/uitextbutton.d.ts +52 -12
  171. package/dist/types/state/stage.d.ts +1 -1
  172. package/dist/types/system/device.d.ts +1 -1
  173. package/dist/types/system/pooling.d.ts +3 -3
  174. package/dist/types/system/timer.d.ts +5 -5
  175. package/dist/types/text/bitmaptext.d.ts +1 -1
  176. package/dist/types/text/text.d.ts +7 -21
  177. package/dist/types/text/textstyle.d.ts +1 -1
  178. package/dist/types/utils/array.d.ts +2 -2
  179. package/dist/types/video/canvas/canvas_renderer.d.ts +8 -81
  180. package/dist/types/video/renderer.d.ts +48 -4
  181. package/dist/types/video/texture/atlas.d.ts +3 -3
  182. package/dist/types/video/texture/canvas_texture.d.ts +40 -0
  183. package/dist/types/video/webgl/buffer/vertex.d.ts +3 -3
  184. package/dist/types/video/webgl/compositors/compositor.d.ts +38 -32
  185. package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +22 -0
  186. package/dist/types/video/webgl/compositors/quad_compositor.d.ts +72 -0
  187. package/dist/types/video/webgl/glshader.d.ts +1 -1
  188. package/dist/types/video/webgl/webgl_renderer.d.ts +47 -37
  189. package/package.json +16 -17
  190. package/src/application/application.js +26 -16
  191. package/src/application/header.js +5 -4
  192. package/src/application/resize.js +19 -19
  193. package/src/audio/audio.js +17 -19
  194. package/src/camera/camera2d.js +9 -9
  195. package/src/entity/entity.js +3 -3
  196. package/src/geometries/ellipse.js +5 -5
  197. package/src/geometries/line.js +8 -8
  198. package/src/geometries/path2d.js +55 -55
  199. package/src/geometries/point.js +1 -1
  200. package/src/geometries/poly.js +28 -28
  201. package/src/geometries/rectangle.js +7 -7
  202. package/src/geometries/roundrect.js +5 -5
  203. package/src/index.js +9 -4
  204. package/src/input/gamepad.js +29 -29
  205. package/src/input/input.js +1 -1
  206. package/src/input/keyboard.js +14 -14
  207. package/src/input/pointer.js +1 -1
  208. package/src/input/pointerevent.js +52 -52
  209. package/src/lang/console.js +2 -2
  210. package/src/lang/deprecated.js +1 -1
  211. package/src/level/level.js +8 -8
  212. package/src/level/tiled/TMXGroup.js +2 -2
  213. package/src/level/tiled/TMXLayer.js +30 -30
  214. package/src/level/tiled/TMXObject.js +7 -7
  215. package/src/level/tiled/TMXTile.js +7 -7
  216. package/src/level/tiled/TMXTileMap.js +18 -18
  217. package/src/level/tiled/TMXTileset.js +14 -14
  218. package/src/level/tiled/TMXTilesetGroup.js +2 -2
  219. package/src/level/tiled/TMXUtils.js +45 -40
  220. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +29 -29
  221. package/src/level/tiled/renderer/TMXIsometricRenderer.js +20 -20
  222. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +9 -9
  223. package/src/level/tiled/renderer/TMXRenderer.js +1 -1
  224. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +5 -5
  225. package/src/loader/loader.js +6 -6
  226. package/src/loader/loadingscreen.js +1 -1
  227. package/src/loader/parser.js +12 -12
  228. package/src/loader/settings.js +2 -2
  229. package/src/math/color.js +24 -23
  230. package/src/math/math.js +1 -1
  231. package/src/math/matrix2.js +21 -21
  232. package/src/math/matrix3.js +51 -51
  233. package/src/math/observable_vector2.js +11 -11
  234. package/src/math/observable_vector3.js +21 -21
  235. package/src/math/vector2.js +10 -10
  236. package/src/math/vector3.js +20 -20
  237. package/src/particles/emitter.js +4 -4
  238. package/src/particles/particle.js +7 -7
  239. package/src/particles/settings.js +2 -2
  240. package/src/physics/body.js +16 -16
  241. package/src/physics/bounds.js +11 -11
  242. package/src/physics/collision.js +2 -2
  243. package/src/physics/detector.js +13 -13
  244. package/src/physics/quadtree.js +18 -18
  245. package/src/physics/sat.js +59 -59
  246. package/src/physics/world.js +3 -3
  247. package/src/plugin/plugin.js +8 -8
  248. package/src/polyfill/index.js +0 -2
  249. package/src/renderable/collectable.js +1 -1
  250. package/src/renderable/container.js +76 -58
  251. package/src/renderable/dragndrop.js +4 -4
  252. package/src/renderable/imagelayer.js +6 -5
  253. package/src/renderable/light2d.js +5 -5
  254. package/src/renderable/nineslicesprite.js +11 -11
  255. package/src/renderable/renderable.js +34 -12
  256. package/src/renderable/sprite.js +24 -24
  257. package/src/renderable/trigger.js +10 -8
  258. package/src/renderable/ui/uibaseelement.js +96 -26
  259. package/src/renderable/ui/uispriteelement.js +24 -24
  260. package/src/renderable/ui/uitextbutton.js +85 -67
  261. package/src/state/stage.js +6 -6
  262. package/src/state/state.js +14 -14
  263. package/src/system/device.js +2 -2
  264. package/src/system/event.js +1 -1
  265. package/src/system/pooling.js +8 -8
  266. package/src/system/save.js +5 -5
  267. package/src/system/timer.js +15 -11
  268. package/src/text/bitmaptext.js +19 -19
  269. package/src/text/bitmaptextdata.js +21 -21
  270. package/src/text/glyph.js +2 -2
  271. package/src/text/text.js +62 -91
  272. package/src/text/textmetrics.js +14 -14
  273. package/src/text/textstyle.js +3 -5
  274. package/src/tweens/easing.js +3 -3
  275. package/src/tweens/interpolation.js +7 -7
  276. package/src/tweens/tween.js +10 -10
  277. package/src/utils/agent.js +5 -5
  278. package/src/utils/array.js +3 -3
  279. package/src/utils/function.js +4 -4
  280. package/src/utils/string.js +2 -2
  281. package/src/utils/utils.js +15 -15
  282. package/src/video/canvas/canvas_renderer.js +39 -117
  283. package/src/video/renderer.js +68 -12
  284. package/src/video/texture/atlas.js +38 -44
  285. package/src/video/texture/cache.js +6 -6
  286. package/src/video/texture/canvas_texture.js +62 -2
  287. package/src/video/video.js +1 -1
  288. package/src/video/webgl/buffer/vertex.js +22 -18
  289. package/src/video/webgl/compositors/compositor.js +79 -80
  290. package/src/video/webgl/compositors/primitive_compositor.js +68 -0
  291. package/src/video/webgl/compositors/{webgl_compositor.js → quad_compositor.js} +52 -109
  292. package/src/video/webgl/glshader.js +6 -6
  293. package/src/video/webgl/shaders/primitive.vert +2 -5
  294. package/src/video/webgl/shaders/quad.vert +3 -1
  295. package/src/video/webgl/utils/attributes.js +1 -1
  296. package/src/video/webgl/utils/program.js +6 -6
  297. package/src/video/webgl/utils/uniforms.js +3 -3
  298. package/src/video/webgl/webgl_renderer.js +186 -179
  299. package/dist/melonjs.mjs/_virtual/make-built-in.js +0 -10
  300. package/dist/melonjs.mjs/_virtual/object-define-property.js +0 -10
  301. package/dist/melonjs.mjs/_virtual/object-get-own-property-descriptor.js +0 -10
  302. package/dist/melonjs.mjs/_virtual/object-get-own-property-names.js +0 -10
  303. package/dist/melonjs.mjs/_virtual/object-get-own-property-symbols.js +0 -10
  304. package/dist/melonjs.mjs/_virtual/object-property-is-enumerable.js +0 -10
  305. package/dist/melonjs.mjs/_virtual/shared.js +0 -10
  306. package/dist/melonjs.mjs/game.js +0 -29
  307. package/dist/melonjs.mjs/polyfill/console.js +0 -18
  308. package/dist/melonjs.mjs/polyfill/performance.js +0 -27
  309. package/dist/melonjs.mjs/polyfill/requestAnimationFrame.js +0 -46
  310. package/dist/melonjs.mjs/polyfill/roundrect.js +0 -242
  311. package/dist/melonjs.mjs/renderable/re_container.js +0 -1016
  312. package/dist/melonjs.mjs/video/utils/resize.js +0 -116
  313. package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +0 -494
  314. package/src/polyfill/performance.js +0 -20
  315. package/src/polyfill/requestAnimationFrame.js +0 -39
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.5.0
2
+ * melonJS Game Engine - v15.1.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -7,14 +7,15 @@
7
7
  */
8
8
  import Color from '../../math/color.js';
9
9
  import Matrix2d from '../../math/matrix2.js';
10
- import WebGLCompositor from './compositors/webgl_compositor.js';
10
+ import QuadCompositor from './compositors/quad_compositor.js';
11
+ import PrimitiveCompositor from './compositors/primitive_compositor.js';
11
12
  import Renderer from '../renderer.js';
12
13
  import TextureCache from '../texture/cache.js';
13
14
  import { TextureAtlas, createAtlas } from '../texture/atlas.js';
14
- import { createCanvas, renderer } from '../video.js';
15
- import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js';
15
+ import { renderer } from '../video.js';
16
+ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET, CANVAS_ONRESIZE } from '../../system/event.js';
16
17
  import pool from '../../system/pooling.js';
17
- import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
18
+ import { isPowerOfTwo } from '../../math/math.js';
18
19
 
19
20
  /**
20
21
  * @classdesc
@@ -33,13 +34,13 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
33
34
  * @param {boolean} [options.premultipliedAlpha=true] - in WebGL, whether the renderer will assume that colors have premultiplied alpha when canvas transparency is enabled
34
35
  * @param {boolean} [options.subPixel=false] - Whether to enable subpixel renderering (performance hit when enabled)
35
36
  * @param {boolean} [options.preferWebGL1=false] - if true the renderer will only use WebGL 1
37
+ * @param {boolean} [options.depthTest="sorting"] - ~Experimental~ the default method to sort object on the z axis in WebGL ("sorting", "z-buffer")
36
38
  * @param {string} [options.powerPreference="default"] - a hint to the user agent indicating what configuration of GPU is suitable for the WebGL context ("default", "high-performance", "low-power"). To be noted that Safari and Chrome (since version 80) both default to "low-power" to save battery life and improve the user experience on these dual-GPU machines.
37
39
  * @param {number} [options.zoomX=width] - The actual width of the canvas with scaling applied
38
40
  * @param {number} [options.zoomY=height] - The actual height of the canvas with scaling applied
39
- * @param {WebGLCompositor} [options.compositor] - A class that implements the compositor API
41
+ * @param {Compositor} [options.compositor] - A class that implements the compositor API for sprite rendering
40
42
  */
41
43
  constructor(options) {
42
-
43
44
  // parent contructor
44
45
  super(options);
45
46
 
@@ -54,25 +55,31 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
54
55
  /**
55
56
  * The vendor string of the underlying graphics driver.
56
57
  * @type {string}
57
- * @default null
58
+ * @default undefined
58
59
  * @readonly
59
60
  */
60
- this.GPUVendor = null;
61
+ this.GPUVendor = undefined;
61
62
 
62
63
  /**
63
64
  * The renderer string of the underlying graphics driver.
64
65
  * @type {string}
65
- * @default null
66
+ * @default undefined
66
67
  * @readonly
67
68
  */
68
- this.GPURenderer = null;
69
+ this.GPURenderer = undefined;
69
70
 
70
71
  /**
71
72
  * The WebGL context
72
73
  * @name gl
73
74
  * @type {WebGLRenderingContext}
74
75
  */
75
- this.context = this.gl = this.getContextGL(this.getCanvas(), options.transparent);
76
+ this.context = this.gl = this.getContextGL(this.getCanvas(), options.transparent, options.depthTest === "z-buffer");
77
+
78
+ /**
79
+ * the vertex buffer used by this WebGL Renderer
80
+ * @type {WebGLBuffer}
81
+ */
82
+ this.vertexBuffer = this.gl.createBuffer();
76
83
 
77
84
  /**
78
85
  * Maximum number of texture unit supported under the current context
@@ -111,7 +118,13 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
111
118
  * The current compositor used by the renderer
112
119
  * @type {WebGLCompositor}
113
120
  */
114
- this.currentCompositor = null;
121
+ this.currentCompositor = undefined;
122
+
123
+ /**
124
+ * a reference to the current shader program used by the renderer
125
+ * @type {WebGLProgram}
126
+ */
127
+ this.currentProgram = undefined;
115
128
 
116
129
  /**
117
130
  * The list of active compositors
@@ -119,14 +132,27 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
119
132
  */
120
133
  this.compositors = new Map();
121
134
 
122
- // Create a default compositor
123
- var compositor = new (this.settings.compositor || WebGLCompositor)(this);
124
- this.compositors.set("default", compositor);
125
- this.setCompositor(compositor);
135
+ // bind the vertex buffer
136
+ this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.vertexBuffer);
137
+
138
+ // Create both quad and primitive compositor
139
+ this.addCompositor(new (this.settings.compositor || QuadCompositor)(this), "quad", true);
140
+ this.addCompositor(new (this.settings.compositor || PrimitiveCompositor)(this), "primitive");
126
141
 
142
+ // depth Test settings
143
+ this.depthTest = options.depthTest;
127
144
 
128
145
  // default WebGL state(s)
129
- this.gl.disable(this.gl.DEPTH_TEST);
146
+ if (this.depthTest === "z-buffer") {
147
+ this.gl.enable(this.gl.DEPTH_TEST);
148
+ // https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/depthFunc
149
+ this.gl.depthFunc(this.gl.LEQUAL);
150
+ this.gl.depthMask(true);
151
+ } else {
152
+ this.gl.disable(this.gl.DEPTH_TEST);
153
+ this.gl.depthMask(false);
154
+ }
155
+
130
156
  this.gl.disable(this.gl.SCISSOR_TEST);
131
157
  this.gl.enable(this.gl.BLEND);
132
158
 
@@ -134,12 +160,16 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
134
160
  this.setBlendMode(this.settings.blendMode);
135
161
 
136
162
  // get GPU vendor and renderer
137
- var debugInfo = this.gl.getExtension("WEBGL_debug_renderer_info");
163
+ let debugInfo = this.gl.getExtension("WEBGL_debug_renderer_info");
138
164
  if (debugInfo !== null) {
139
165
  this.GPUVendor = this.gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);
140
166
  this.GPURenderer = this.gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
141
167
  }
142
168
 
169
+ // a private property that when set will make `setCompositor`
170
+ // to use this specific shader instead of the default one
171
+ this.customShader = undefined;
172
+
143
173
  // Create a texture cache
144
174
  this.cache = new TextureCache(this.maxTextures);
145
175
 
@@ -147,7 +177,7 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
147
177
  this.type = "WebGL" + this.WebGLVersion;
148
178
 
149
179
  // to simulate context lost and restore in WebGL:
150
- // var ctx = me.video.renderer.context.getExtension('WEBGL_lose_context');
180
+ // let ctx = me.video.renderer.context.getExtension('WEBGL_lose_context');
151
181
  // ctx.loseContext()
152
182
  this.getCanvas().addEventListener("webglcontextlost", (e) => {
153
183
  e.preventDefault();
@@ -160,6 +190,17 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
160
190
  this.isContextValid = true;
161
191
  emit(ONCONTEXT_RESTORED, this);
162
192
  }, false );
193
+
194
+ // reset the renderer on game reset
195
+ on(GAME_RESET, () => {
196
+ this.reset();
197
+ });
198
+
199
+ // register to the CANVAS resize channel
200
+ on(CANVAS_ONRESIZE, (width, height) => {
201
+ this.flush();
202
+ this.setViewport(0, 0, width, height);
203
+ });
163
204
  }
164
205
 
165
206
  /**
@@ -168,6 +209,21 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
168
209
  reset() {
169
210
  super.reset();
170
211
 
212
+ // clear gl context
213
+ this.clear();
214
+
215
+ // initial viewport size
216
+ this.setViewport();
217
+
218
+ // rebind the vertex buffer if required (e.g in case of context loss)
219
+ if (this.gl.getParameter(this.gl.ARRAY_BUFFER_BINDING) !== this.vertexBuffer) {
220
+ this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.vertexBuffer);
221
+ }
222
+
223
+ this.currentCompositor = undefined;
224
+ this.currentProgram = undefined;
225
+ this.customShader = undefined;
226
+
171
227
  this.compositors.forEach((compositor) => {
172
228
  if (this.isContextValid === false) {
173
229
  // on context lost/restore
@@ -177,35 +233,62 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
177
233
  }
178
234
  });
179
235
 
236
+ this.setCompositor("quad");
237
+
180
238
  this.gl.disable(this.gl.SCISSOR_TEST);
181
- if (typeof this.fontContext2D !== "undefined" ) {
182
- this.createFontTexture(this.cache);
239
+ }
240
+
241
+ /**
242
+ * add a new compositor to this renderer
243
+ * @param {Compositor} compositor - a compositor instance
244
+ * @param {String} name - a name uniquely identifying this compositor
245
+ * @param {Boolean} [activate=false] - true if the given compositor should be set as the active one
246
+ */
247
+ addCompositor(compositor, name = "default", activate = false) {
248
+ // make sure there is no existing compositor with the same name
249
+ if (typeof this.compositors.get(name) !== "undefined") {
250
+ throw new Error("Invalid Compositor name");
183
251
  }
184
252
 
253
+ // add the new compositor
254
+ this.compositors.set(name, compositor);
255
+
256
+ if (activate === true) {
257
+ // set as active one
258
+ this.setCompositor(name);
259
+ }
185
260
  }
186
261
 
187
262
  /**
188
263
  * set the active compositor for this renderer
189
- * @param {WebGLCompositor|string} compositor - a compositor name or instance
264
+ * @param {String} name - a compositor name
265
+ * @param {GLShader} [shader] - an optional shader program to be used, instead of the default one, when activating the compositor
266
+ * @return {Compositor} an instance to the current active compositor
190
267
  */
191
- setCompositor(compositor = "default") {
192
-
193
- if (typeof compositor === "string") {
194
- compositor = this.compositors.get(compositor);
195
- }
268
+ setCompositor(name = "default", shader = this.customShader) {
269
+ let compositor = this.compositors.get(name);
196
270
 
197
271
  if (typeof compositor === "undefined") {
198
- throw new Error("Invalid WebGL Compositor");
272
+ throw new Error("Invalid Compositor");
199
273
  }
200
274
 
201
275
  if (this.currentCompositor !== compositor) {
202
- if (this.currentCompositor !== null) {
276
+ if (this.currentCompositor !== undefined) {
203
277
  // flush the current compositor
204
278
  this.currentCompositor.flush();
205
279
  }
206
- // set given one as current
280
+ // set as the active one
207
281
  this.currentCompositor = compositor;
208
282
  }
283
+
284
+ if (name === "quad" && typeof shader === "object") {
285
+ this.currentCompositor.useShader(shader);
286
+ } else {
287
+ // (re)bind the compositor with the default shader (program & attributes)
288
+ this.currentCompositor.bind();
289
+ }
290
+
291
+ return this.currentCompositor;
209
292
  }
210
293
 
211
294
  /**
@@ -215,66 +298,31 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
215
298
  this.currentTransform.identity();
216
299
  }
217
300
 
218
- /**
219
- * @ignore
220
- */
221
- createFontTexture(cache) {
222
- if (typeof this.fontTexture === "undefined") {
223
- var canvas = this.getCanvas();
224
- var width = canvas.width;
225
- var height = canvas.height;
226
-
227
- if (this.WebGLVersion === 1) {
228
- if (!isPowerOfTwo(width)) {
229
- width = nextPowerOfTwo(canvas.width);
230
- }
231
- if (!isPowerOfTwo(height)) {
232
- height = nextPowerOfTwo(canvas.height);
233
- }
234
- }
235
-
236
- var image = createCanvas(width, height, true);
237
-
238
- /**
239
- * @ignore
240
- */
241
- this.fontContext2D = this.getContext2d(image);
242
-
243
- /**
244
- * @ignore
245
- */
246
- this.fontTexture = new TextureAtlas(createAtlas(canvas.width, canvas.height, "fontTexture"), image, cache);
247
- this.currentCompositor.uploadTexture(this.fontTexture, 0, 0, 0);
248
-
249
- } else {
250
- // fontTexture was already created, just add it back into the cache
251
- cache.set(this.fontContext2D.canvas, this.fontTexture);
252
- }
253
- }
254
-
255
301
  /**
256
302
  * Create a pattern with the specified repetition
257
- * @param {Image} image - Source image
303
+ * @param {HTMLImageElement|SVGImageElement|HTMLVideoElement|HTMLCanvasElement|ImageBitmap|OffscreenCanvas|VideoFrame} image - Source image to be used as the pattern's image
258
304
  * @param {string} repeat - Define how the pattern should be repeated
259
305
  * @returns {TextureAtlas}
260
306
  * @see ImageLayer#repeat
261
307
  * @example
262
- * var tileable = renderer.createPattern(image, "repeat");
263
- * var horizontal = renderer.createPattern(image, "repeat-x");
264
- * var vertical = renderer.createPattern(image, "repeat-y");
265
- * var basic = renderer.createPattern(image, "no-repeat");
308
+ * let tileable = renderer.createPattern(image, "repeat");
309
+ * let horizontal = renderer.createPattern(image, "repeat-x");
310
+ * let vertical = renderer.createPattern(image, "repeat-y");
311
+ * let basic = renderer.createPattern(image, "no-repeat");
266
312
  */
267
313
  createPattern(image, repeat) {
268
314
 
315
+ this.setCompositor("quad");
316
+
269
317
  if (renderer.WebGLVersion === 1 && (!isPowerOfTwo(image.width) || !isPowerOfTwo(image.height))) {
270
- var src = typeof image.src !== "undefined" ? image.src : image;
318
+ let src = typeof image.src !== "undefined" ? image.src : image;
271
319
  throw new Error(
272
320
  "[WebGL Renderer] " + src + " is not a POT texture " +
273
321
  "(" + image.width + "x" + image.height + ")"
274
322
  );
275
323
  }
276
324
 
277
- var texture = new TextureAtlas(createAtlas(image.width, image.height, "pattern", repeat), image);
325
+ let texture = new TextureAtlas(createAtlas(image.width, image.height, "pattern", repeat), image);
278
326
 
279
327
  // FIXME: Remove old cache entry and texture when changing the repeat mode
280
328
  this.currentCompositor.uploadTexture(texture);
@@ -299,10 +347,27 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
299
347
  }
300
348
 
301
349
  /**
302
- * prepare the framebuffer for drawing a new frame
350
+ * Sets the WebGL viewport, which specifies the affine transformation of x and y from normalized device coordinates to window coordinates
351
+ * @param {number} [x = 0] - x the horizontal coordinate for the lower left corner of the viewport origin
352
+ * @param {number} [y = 0] - y the vertical coordinate for the lower left corner of the viewport origin
353
+ * @param {number} [w = width of the canvas] - the width of viewport
354
+ * @param {number} [h = height of the canvas] - the height of viewport
355
+ */
356
+ setViewport(x = 0, y = 0, w = this.getCanvas().width, h = this.getCanvas().height) {
357
+ this.gl.viewport(x, y, w, h);
358
+ }
359
+
360
+ /**
361
+ * Clear the frame buffer
303
362
  */
304
363
  clear() {
305
- this.currentCompositor.clear(this.settings.transparent ? 0.0 : 1.0);
364
+ let gl = this.gl;
365
+ gl.clearColor(0, 0, 0, this.settings.transparent ? 0.0 : 1.0);
366
+ if (this.depthTest === "z-buffer") {
367
+ gl.clear(gl.DEPTH_BUFFER_BIT | gl.COLOR_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
368
+ } else {
369
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
370
+ }
306
371
  }
307
372
 
308
373
  /**
@@ -311,18 +376,21 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
311
376
  * @param {boolean} [opaque=false] - Allow transparency [default] or clear the surface completely [true]
312
377
  */
313
378
  clearColor(color = "#000000", opaque = false) {
314
- var glArray;
379
+ let glArray;
380
+ let gl = this.gl;
315
381
 
316
382
  if (color instanceof Color) {
317
383
  glArray = color.toArray();
318
384
  } else {
319
- var _color = pool.pull("me.Color");
385
+ let _color = pool.pull("me.Color");
320
386
  // reuse temporary the renderer default color object
321
387
  glArray = _color.parseCSS(color).toArray();
322
388
  pool.push(_color);
323
389
  }
390
+
324
391
  // clear gl context with the specified color
325
- this.currentCompositor.clearColor(glArray[0], glArray[1], glArray[2], (opaque === true) ? 1.0 : glArray[3]);
392
+ gl.clearColor(glArray[0], glArray[1], glArray[2], (opaque === true) ? 1.0 : glArray[3]);
393
+ gl.clear(gl.COLOR_BUFFER_BIT);
326
394
  }
327
395
 
328
396
  /**
@@ -339,42 +407,9 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
339
407
  this.restore();
340
408
  }
341
409
 
342
- /**
343
- * @ignore
344
- */
345
- drawFont(bounds) {
346
- var fontContext = this.getFontContext();
347
-
348
- // Force-upload the new texture
349
- this.currentCompositor.uploadTexture(this.fontTexture, 0, 0, 0, true);
350
-
351
- // Add the new quad
352
- var uvs = this.fontTexture.getUVs(bounds.left + "," + bounds.top + "," + bounds.width + "," + bounds.height);
353
- this.currentCompositor.addQuad(
354
- this.fontTexture,
355
- bounds.left,
356
- bounds.top,
357
- bounds.width,
358
- bounds.height,
359
- uvs[0],
360
- uvs[1],
361
- uvs[2],
362
- uvs[3],
363
- this.currentTint.toUint32(this.getGlobalAlpha())
364
- );
365
-
366
- // Clear font context2D
367
- fontContext.clearRect(
368
- bounds.left,
369
- bounds.top,
370
- bounds.width,
371
- bounds.height
372
- );
373
- }
374
-
375
410
  /**
376
411
  * Draw an image to the gl context
377
- * @param {Image} image - An element to draw into the context. The specification permits any canvas image source (CanvasImageSource), specifically, a CSSImageValue, an HTMLImageElement, an SVGImageElement, an HTMLVideoElement, an HTMLCanvasElement, an ImageBitmap, or an OffscreenCanvas.
412
+ * @param {HTMLImageElement|SVGImageElement|HTMLVideoElement|HTMLCanvasElement|ImageBitmap|OffscreenCanvas|VideoFrame} image - An element to draw into the context.
378
413
  * @param {number} sx - The X coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.
379
414
  * @param {number} sy - The Y coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.
380
415
  * @param {number} sw - The width of the sub-rectangle of the source image to draw into the destination context. If not specified, the entire rectangle from the coordinates specified by sx and sy to the bottom-right corner of the image is used.
@@ -417,8 +452,10 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
417
452
  dy |= 0;
418
453
  }
419
454
 
420
- var texture = this.cache.get(image);
421
- var uvs = texture.getUVs(sx + "," + sy + "," + sw + "," + sh);
455
+ this.setCompositor("quad");
456
+
457
+ let texture = this.cache.get(image);
458
+ let uvs = texture.getUVs(sx + "," + sy + "," + sw + "," + sh);
422
459
  this.currentCompositor.addQuad(texture, dx, dy, dw, dh, uvs[0], uvs[1], uvs[2], uvs[3], this.currentTint.toUint32(this.getGlobalAlpha()));
423
460
  }
424
461
 
@@ -432,7 +469,8 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
432
469
  * @see WebGLRenderer#createPattern
433
470
  */
434
471
  drawPattern(pattern, x, y, width, height) {
435
- var uvs = pattern.getUVs("0,0," + width + "," + height);
472
+ let uvs = pattern.getUVs("0,0," + width + "," + height);
473
+ this.setCompositor("quad");
436
474
  this.currentCompositor.addQuad(pattern, x, y, width, height, uvs[0], uvs[1], uvs[2], uvs[3], this.currentTint.toUint32(this.getGlobalAlpha()));
437
475
  }
438
476
 
@@ -440,9 +478,10 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
440
478
  * Returns the WebGL Context object of the given canvas element
441
479
  * @param {HTMLCanvasElement} canvas
442
480
  * @param {boolean} [transparent=false] - use true to enable transparency
481
+ * @param {boolean} [depth=false] - use true to enable depth buffer testing
443
482
  * @returns {WebGLRenderingContext}
444
483
  */
445
- getContextGL(canvas, transparent = false) {
484
+ getContextGL(canvas, transparent = false, depth = false) {
446
485
  if (typeof canvas === "undefined" || canvas === null) {
447
486
  throw new Error(
448
487
  "You must pass a canvas element in order to create " +
@@ -450,10 +489,10 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
450
489
  );
451
490
  }
452
491
 
453
- var attr = {
492
+ let attr = {
454
493
  alpha : transparent,
455
494
  antialias : this.settings.antiAlias,
456
- depth : false,
495
+ depth : depth,
457
496
  stencil: true,
458
497
  preserveDrawingBuffer : false,
459
498
  premultipliedAlpha: transparent ? this.settings.premultipliedAlpha : false,
@@ -461,7 +500,7 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
461
500
  failIfMajorPerformanceCaveat : this.settings.failIfMajorPerformanceCaveat
462
501
  };
463
502
 
464
- var gl;
503
+ let gl;
465
504
 
466
505
  // attempt to create a WebGL2 context if requested
467
506
  if (this.settings.preferWebGL1 === false) {
@@ -539,28 +578,14 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
539
578
  }
540
579
  }
541
580
 
542
- /**
543
- * return a reference to the font 2d Context
544
- * @ignore
545
- */
546
- getFontContext() {
547
- if (typeof this.fontContext2D === "undefined" ) {
548
- // warn the end user about performance impact
549
- console.warn("[WebGL Renderer] WARNING : Using Standard me.Text with WebGL will severly impact performances !");
550
- // create the font texture if not done yet
551
- this.createFontTexture(this.cache);
552
- }
553
- return this.fontContext2D;
554
- }
555
-
556
581
  /**
557
582
  * restores the canvas context
558
583
  */
559
584
  restore() {
560
585
  // do nothing if there is no saved states
561
586
  if (this._matrixStack.length !== 0) {
562
- var color = this._colorStack.pop();
563
- var matrix = this._matrixStack.pop();
587
+ let color = this._colorStack.pop();
588
+ let matrix = this._matrixStack.pop();
564
589
 
565
590
  // restore the previous context
566
591
  this.currentColor.copy(color);
@@ -649,7 +674,7 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
649
674
  * @param {Color|string} color - css color string.
650
675
  */
651
676
  setColor(color) {
652
- var alpha = this.currentColor.alpha;
677
+ let alpha = this.currentColor.alpha;
653
678
  this.currentColor.copy(color);
654
679
  this.currentColor.alpha *= alpha;
655
680
  }
@@ -673,10 +698,7 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
673
698
  * @param {boolean} [fill=false]
674
699
  */
675
700
  strokeArc(x, y, radius, start, end, antiClockwise = false, fill = false) {
676
- if (this.getGlobalAlpha() < 1 / 255) {
677
- // Fast path: don't draw fully transparent
678
- return;
679
- }
701
+ this.setCompositor("primitive");
680
702
  this.path2D.beginPath();
681
703
  this.path2D.arc(x, y, radius, start, end, antiClockwise);
682
704
  if (fill === false) {
@@ -709,15 +731,12 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
709
731
  * @param {boolean} [fill=false] - also fill the shape with the current color if true
710
732
  */
711
733
  strokeEllipse(x, y, w, h, fill = false) {
712
- if (this.getGlobalAlpha() < 1 / 255) {
713
- // Fast path: don't draw fully transparent
714
- return;
715
- }
734
+ this.setCompositor("primitive");
716
735
  this.path2D.beginPath();
717
736
  this.path2D.ellipse(x, y, w, h, 0, 0, 360);
718
737
  this.path2D.closePath();
719
738
  if (fill === false) {
720
- this.currentCompositor.drawVertices(this.gl.LINE_LOOP, this.path2D.points);
739
+ this.currentCompositor.drawVertices(this.gl.LINE_STRIP, this.path2D.points);
721
740
  } else {
722
741
  this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
723
742
  }
@@ -742,14 +761,11 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
742
761
  * @param {number} endY - the end y coordinate
743
762
  */
744
763
  strokeLine(startX, startY, endX, endY) {
745
- if (this.getGlobalAlpha() < 1 / 255) {
746
- // Fast path: don't draw fully transparent
747
- return;
748
- }
764
+ this.setCompositor("primitive");
749
765
  this.path2D.beginPath();
750
766
  this.path2D.moveTo(startX, startY);
751
767
  this.path2D.lineTo(endX, endY);
752
- this.currentCompositor.drawVertices(this.gl.LINE_STRIP, this.path2D.points);
768
+ this.currentCompositor.drawVertices(this.gl.LINES, this.path2D.points);
753
769
  }
754
770
 
755
771
 
@@ -770,22 +786,19 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
770
786
  * @param {boolean} [fill=false] - also fill the shape with the current color if true
771
787
  */
772
788
  strokePolygon(poly, fill = false) {
773
- if (this.getGlobalAlpha() < 1 / 255) {
774
- // Fast path: don't draw fully transparent
775
- return;
776
- }
789
+ this.setCompositor("primitive");
777
790
  this.translate(poly.pos.x, poly.pos.y);
778
791
  this.path2D.beginPath();
779
- this.path2D.moveTo(poly.points[0].x, poly.points[0].y);
780
- var point;
781
- for (var i = 1; i < poly.points.length; i++) {
782
- point = poly.points[i];
783
- this.path2D.lineTo(point.x, point.y);
792
+
793
+ let points = poly.points;
794
+ for (let i = 1; i < points.length; i++) {
795
+ this.path2D.moveTo(points[i-1].x, points[i-1].y);
796
+ this.path2D.lineTo(points[i].x, points[i].y);
784
797
  }
785
- this.path2D.lineTo(poly.points[0].x, poly.points[0].y);
798
+ this.path2D.lineTo(points[points.length - 1].x, points[points.length - 1].y);
786
799
  this.path2D.closePath();
787
800
  if (fill === false) {
788
- this.currentCompositor.drawVertices(this.gl.LINE_LOOP, this.path2D.points);
801
+ this.currentCompositor.drawVertices(this.gl.LINES, this.path2D.points);
789
802
  } else {
790
803
  // draw all triangles
791
804
  this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
@@ -810,14 +823,11 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
810
823
  * @param {boolean} [fill=false] - also fill the shape with the current color if true
811
824
  */
812
825
  strokeRect(x, y, width, height, fill = false) {
813
- if (this.getGlobalAlpha() < 1 / 255) {
814
- // Fast path: don't draw fully transparent
815
- return;
816
- }
826
+ this.setCompositor("primitive");
817
827
  this.path2D.beginPath();
818
828
  this.path2D.rect(x, y, width, height);
819
829
  if (fill === false) {
820
- this.currentCompositor.drawVertices(this.gl.LINE_LOOP, this.path2D.points);
830
+ this.currentCompositor.drawVertices(this.gl.LINES, this.path2D.points);
821
831
  } else {
822
832
  this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
823
833
  }
@@ -844,14 +854,11 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
844
854
  * @param {boolean} [fill=false] - also fill the shape with the current color if true
845
855
  */
846
856
  strokeRoundRect(x, y, width, height, radius, fill = false) {
847
- if (this.getGlobalAlpha() < 1 / 255) {
848
- // Fast path: don't draw fully transparent
849
- return;
850
- }
857
+ this.setCompositor("primitive");
851
858
  this.path2D.beginPath();
852
859
  this.path2D.roundRect(x, y, width, height, radius);
853
860
  if (fill === false) {
854
- this.currentCompositor.drawVertices(this.gl.LINE_LOOP, this.path2D.points);
861
+ this.currentCompositor.drawVertices(this.gl.LINE_STRIP, this.path2D.points);
855
862
  } else {
856
863
  this.path2D.closePath();
857
864
  this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
@@ -905,11 +912,11 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
905
912
  * @param {Matrix2d} mat2d - Matrix to transform by
906
913
  */
907
914
  transform(mat2d) {
908
- var currentTransform = this.currentTransform;
915
+ let currentTransform = this.currentTransform;
909
916
  currentTransform.multiply(mat2d);
910
917
  if (this.settings.subPixel === false) {
911
918
  // snap position values to pixel grid
912
- var a = currentTransform.toArray();
919
+ let a = currentTransform.toArray();
913
920
  a[6] |= 0;
914
921
  a[7] |= 0;
915
922
  }
@@ -921,11 +928,11 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
921
928
  * @param {number} y
922
929
  */
923
930
  translate(x, y) {
924
- var currentTransform = this.currentTransform;
931
+ let currentTransform = this.currentTransform;
925
932
  currentTransform.translate(x, y);
926
933
  if (this.settings.subPixel === false) {
927
934
  // snap position values to pixel grid
928
- var a = currentTransform.toArray();
935
+ let a = currentTransform.toArray();
929
936
  a[6] |= 0;
930
937
  a[7] |= 0;
931
938
  }
@@ -943,11 +950,11 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
943
950
  * @param {number} height
944
951
  */
945
952
  clipRect(x, y, width, height) {
946
- var canvas = this.getCanvas();
947
- var gl = this.gl;
953
+ let canvas = this.getCanvas();
954
+ let gl = this.gl;
948
955
  // if requested box is different from the current canvas size
949
956
  if (x !== 0 || y !== 0 || width !== canvas.width || height !== canvas.height) {
950
- var currentScissor = this.currentScissor;
957
+ let currentScissor = this.currentScissor;
951
958
  if (gl.isEnabled(gl.SCISSOR_TEST)) {
952
959
  // if same as the current scissor box do nothing
953
960
  if (currentScissor[0] === x && currentScissor[1] === y &&
@@ -986,7 +993,7 @@ import { isPowerOfTwo, nextPowerOfTwo } from '../../math/math.js';
986
993
  * @param {boolean} [invert=false] - either the given shape should define what is visible (default) or the opposite
987
994
  */
988
995
  setMask(mask, invert = false) {
989
- var gl = this.gl;
996
+ let gl = this.gl;
990
997
 
991
998
  // flush the compositor
992
999
  this.flush();