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