melonjs 14.0.2 → 14.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 (214) hide show
  1. package/README.md +2 -0
  2. package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +10 -0
  3. package/dist/melonjs.mjs/_virtual/arraymultimap.js +10 -0
  4. package/dist/melonjs.mjs/_virtual/earcut.js +10 -0
  5. package/dist/melonjs.mjs/_virtual/howler.js +10 -0
  6. package/dist/melonjs.mjs/_virtual/index.js +10 -0
  7. package/dist/melonjs.mjs/_virtual/index2.js +10 -0
  8. package/dist/melonjs.mjs/_virtual/multimap.js +10 -0
  9. package/dist/melonjs.mjs/_virtual/setmultimap.js +10 -0
  10. package/dist/melonjs.mjs/application/application.js +240 -0
  11. package/dist/melonjs.mjs/audio/audio.js +536 -0
  12. package/dist/melonjs.mjs/camera/camera2d.js +732 -0
  13. package/dist/melonjs.mjs/entity/entity.js +248 -0
  14. package/dist/melonjs.mjs/game.js +29 -0
  15. package/dist/melonjs.mjs/geometries/ellipse.js +275 -0
  16. package/dist/melonjs.mjs/geometries/line.js +116 -0
  17. package/dist/melonjs.mjs/geometries/path2d.js +319 -0
  18. package/dist/melonjs.mjs/geometries/point.js +89 -0
  19. package/dist/melonjs.mjs/geometries/poly.js +500 -0
  20. package/dist/melonjs.mjs/geometries/rectangle.js +375 -0
  21. package/dist/melonjs.mjs/geometries/roundrect.js +168 -0
  22. package/dist/melonjs.mjs/index.js +248 -0
  23. package/dist/melonjs.mjs/input/gamepad.js +501 -0
  24. package/dist/melonjs.mjs/input/input.js +26 -0
  25. package/dist/melonjs.mjs/input/keyboard.js +470 -0
  26. package/dist/melonjs.mjs/input/pointer.js +393 -0
  27. package/dist/melonjs.mjs/input/pointerevent.js +818 -0
  28. package/dist/melonjs.mjs/lang/deprecated.js +157 -0
  29. package/dist/melonjs.mjs/level/level.js +297 -0
  30. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +141 -0
  31. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +448 -0
  32. package/dist/melonjs.mjs/level/tiled/TMXObject.js +355 -0
  33. package/dist/melonjs.mjs/level/tiled/TMXTile.js +194 -0
  34. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +639 -0
  35. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +311 -0
  36. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +83 -0
  37. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +367 -0
  38. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +506 -0
  39. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +220 -0
  40. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +157 -0
  41. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +125 -0
  42. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +109 -0
  43. package/dist/melonjs.mjs/loader/loader.js +801 -0
  44. package/dist/melonjs.mjs/loader/loadingscreen.js +120 -0
  45. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +11 -0
  46. package/dist/melonjs.mjs/math/color.js +618 -0
  47. package/dist/melonjs.mjs/math/math.js +218 -0
  48. package/dist/melonjs.mjs/math/matrix2.js +503 -0
  49. package/dist/melonjs.mjs/math/matrix3.js +681 -0
  50. package/dist/melonjs.mjs/math/observable_vector2.js +471 -0
  51. package/dist/melonjs.mjs/math/observable_vector3.js +561 -0
  52. package/dist/melonjs.mjs/math/vector2.js +528 -0
  53. package/dist/melonjs.mjs/math/vector3.js +569 -0
  54. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +73 -0
  55. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +21 -0
  56. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +324 -0
  57. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +69 -0
  58. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +691 -0
  59. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +350 -0
  60. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +3241 -0
  61. package/dist/melonjs.mjs/particles/emitter.js +267 -0
  62. package/dist/melonjs.mjs/particles/particle.js +188 -0
  63. package/dist/melonjs.mjs/particles/settings.js +319 -0
  64. package/dist/melonjs.mjs/physics/body.js +704 -0
  65. package/dist/melonjs.mjs/physics/bounds.js +460 -0
  66. package/dist/melonjs.mjs/physics/collision.js +132 -0
  67. package/dist/melonjs.mjs/physics/detector.js +194 -0
  68. package/dist/melonjs.mjs/physics/quadtree.js +391 -0
  69. package/dist/melonjs.mjs/physics/response.js +57 -0
  70. package/dist/melonjs.mjs/physics/sat.js +483 -0
  71. package/dist/melonjs.mjs/physics/world.js +221 -0
  72. package/dist/melonjs.mjs/plugin/plugin.js +141 -0
  73. package/dist/melonjs.mjs/renderable/collectable.js +62 -0
  74. package/dist/melonjs.mjs/renderable/colorlayer.js +80 -0
  75. package/dist/melonjs.mjs/renderable/container.js +1018 -0
  76. package/dist/melonjs.mjs/renderable/dragndrop.js +224 -0
  77. package/dist/melonjs.mjs/renderable/imagelayer.js +306 -0
  78. package/dist/melonjs.mjs/renderable/light2d.js +156 -0
  79. package/dist/melonjs.mjs/renderable/nineslicesprite.js +247 -0
  80. package/dist/melonjs.mjs/renderable/renderable.js +783 -0
  81. package/dist/melonjs.mjs/renderable/sprite.js +654 -0
  82. package/dist/melonjs.mjs/renderable/trigger.js +157 -0
  83. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +213 -0
  84. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +226 -0
  85. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +128 -0
  86. package/dist/melonjs.mjs/state/stage.js +237 -0
  87. package/dist/melonjs.mjs/state/state.js +596 -0
  88. package/dist/melonjs.mjs/system/device.js +909 -0
  89. package/dist/melonjs.mjs/system/dom.js +78 -0
  90. package/dist/melonjs.mjs/system/event.js +537 -0
  91. package/dist/melonjs.mjs/system/platform.js +41 -0
  92. package/dist/melonjs.mjs/system/pooling.js +209 -0
  93. package/dist/melonjs.mjs/system/save.js +157 -0
  94. package/dist/melonjs.mjs/system/timer.js +286 -0
  95. package/dist/melonjs.mjs/text/bitmaptext.js +364 -0
  96. package/dist/melonjs.mjs/text/bitmaptextdata.js +199 -0
  97. package/dist/melonjs.mjs/text/glyph.js +66 -0
  98. package/dist/melonjs.mjs/text/text.js +453 -0
  99. package/dist/melonjs.mjs/text/textmetrics.js +176 -0
  100. package/dist/melonjs.mjs/text/textstyle.js +23 -0
  101. package/dist/melonjs.mjs/tweens/easing.js +336 -0
  102. package/dist/melonjs.mjs/tweens/interpolation.js +112 -0
  103. package/dist/melonjs.mjs/tweens/tween.js +480 -0
  104. package/dist/melonjs.mjs/utils/agent.js +76 -0
  105. package/dist/melonjs.mjs/utils/array.js +63 -0
  106. package/dist/melonjs.mjs/utils/file.js +42 -0
  107. package/dist/melonjs.mjs/utils/function.js +70 -0
  108. package/dist/melonjs.mjs/utils/string.js +82 -0
  109. package/dist/melonjs.mjs/utils/utils.js +173 -0
  110. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +807 -0
  111. package/dist/melonjs.mjs/video/renderer.js +411 -0
  112. package/dist/melonjs.mjs/video/texture/atlas.js +519 -0
  113. package/dist/melonjs.mjs/video/texture/cache.js +143 -0
  114. package/dist/melonjs.mjs/video/texture/canvas_texture.js +144 -0
  115. package/dist/melonjs.mjs/video/video.js +462 -0
  116. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +143 -0
  117. package/dist/melonjs.mjs/video/webgl/glshader.js +168 -0
  118. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +10 -0
  119. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +10 -0
  120. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +10 -0
  121. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +10 -0
  122. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +25 -0
  123. package/dist/melonjs.mjs/video/webgl/utils/precision.js +20 -0
  124. package/dist/melonjs.mjs/video/webgl/utils/program.js +67 -0
  125. package/dist/melonjs.mjs/video/webgl/utils/string.js +25 -0
  126. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +92 -0
  127. package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +495 -0
  128. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +1036 -0
  129. package/dist/melonjs.module.d.ts +1163 -1163
  130. package/dist/melonjs.module.js +1903 -3274
  131. package/package.json +22 -17
  132. package/src/application/application.js +3 -3
  133. package/src/audio/audio.js +32 -32
  134. package/src/camera/camera2d.js +31 -31
  135. package/src/entity/entity.js +17 -17
  136. package/src/geometries/ellipse.js +16 -16
  137. package/src/geometries/line.js +5 -5
  138. package/src/geometries/path2d.js +32 -32
  139. package/src/geometries/poly.js +15 -15
  140. package/src/geometries/rectangle.js +18 -18
  141. package/src/geometries/roundrect.js +8 -8
  142. package/src/input/gamepad.js +15 -15
  143. package/src/input/keyboard.js +12 -12
  144. package/src/input/pointer.js +6 -6
  145. package/src/input/pointerevent.js +12 -12
  146. package/src/lang/deprecated.js +12 -12
  147. package/src/level/level.js +25 -25
  148. package/src/level/tiled/TMXLayer.js +22 -22
  149. package/src/level/tiled/TMXTile.js +5 -5
  150. package/src/level/tiled/TMXTileMap.js +6 -6
  151. package/src/level/tiled/TMXTileset.js +2 -2
  152. package/src/level/tiled/TMXUtils.js +5 -5
  153. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -2
  154. package/src/level/tiled/renderer/TMXIsometricRenderer.js +2 -2
  155. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  156. package/src/level/tiled/renderer/TMXRenderer.js +19 -19
  157. package/src/loader/loader.js +20 -20
  158. package/src/math/color.js +20 -20
  159. package/src/math/math.js +16 -16
  160. package/src/math/matrix2.js +16 -16
  161. package/src/math/matrix3.js +25 -25
  162. package/src/math/observable_vector2.js +14 -14
  163. package/src/math/observable_vector3.js +16 -16
  164. package/src/math/vector2.js +9 -9
  165. package/src/math/vector3.js +10 -10
  166. package/src/particles/emitter.js +6 -6
  167. package/src/particles/particle.js +2 -2
  168. package/src/physics/body.js +28 -28
  169. package/src/physics/bounds.js +8 -8
  170. package/src/physics/collision.js +2 -2
  171. package/src/physics/detector.js +6 -6
  172. package/src/physics/quadtree.js +11 -11
  173. package/src/physics/sat.js +31 -31
  174. package/src/physics/world.js +5 -5
  175. package/src/plugin/plugin.js +5 -5
  176. package/src/renderable/collectable.js +3 -3
  177. package/src/renderable/colorlayer.js +5 -5
  178. package/src/renderable/container.js +21 -21
  179. package/src/renderable/dragndrop.js +14 -14
  180. package/src/renderable/imagelayer.js +13 -13
  181. package/src/renderable/light2d.js +3 -3
  182. package/src/renderable/nineslicesprite.js +16 -16
  183. package/src/renderable/renderable.js +23 -23
  184. package/src/renderable/sprite.js +28 -28
  185. package/src/renderable/trigger.js +15 -15
  186. package/src/renderable/ui/uibaseelement.js +7 -7
  187. package/src/renderable/ui/uispriteelement.js +6 -6
  188. package/src/renderable/ui/uitextbutton.js +13 -13
  189. package/src/state/stage.js +7 -7
  190. package/src/state/state.js +17 -17
  191. package/src/system/device.js +11 -11
  192. package/src/system/event.js +10 -10
  193. package/src/system/pooling.js +9 -9
  194. package/src/system/save.js +2 -2
  195. package/src/system/timer.js +10 -10
  196. package/src/text/bitmaptext.js +18 -18
  197. package/src/text/bitmaptextdata.js +2 -2
  198. package/src/text/text.js +23 -23
  199. package/src/text/textmetrics.js +8 -8
  200. package/src/tweens/tween.js +19 -19
  201. package/src/utils/agent.js +5 -5
  202. package/src/utils/array.js +4 -4
  203. package/src/utils/file.js +2 -2
  204. package/src/utils/function.js +6 -6
  205. package/src/utils/string.js +5 -5
  206. package/src/utils/utils.js +4 -4
  207. package/src/video/canvas/canvas_renderer.js +70 -70
  208. package/src/video/renderer.js +26 -26
  209. package/src/video/texture/atlas.js +22 -22
  210. package/src/video/texture/canvas_texture.js +9 -9
  211. package/src/video/video.js +17 -17
  212. package/src/video/webgl/glshader.js +10 -10
  213. package/src/video/webgl/webgl_compositor.js +41 -41
  214. package/src/video/webgl/webgl_renderer.js +75 -75
@@ -0,0 +1,143 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.0
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ /**
9
+ * @classdesc
10
+ * a Vertex Buffer object
11
+ * @class VertexArrayBuffer
12
+ * @ignore
13
+ */
14
+
15
+ class VertexArrayBuffer {
16
+
17
+ constructor(vertex_size, vertex_per_quad) {
18
+ // the size of one vertex in float
19
+ this.vertexSize = vertex_size;
20
+ // size of a quad in vertex
21
+ this.quadSize = vertex_per_quad;
22
+ // the maximum number of vertices the vertex array buffer can hold
23
+ this.maxVertex = 256;
24
+ // the current number of vertices added to the vertex array buffer
25
+ this.vertexCount = 0;
26
+
27
+ // the actual vertex data buffer
28
+ this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.quadSize);
29
+ // Float32 and Uint32 view of the vertex data array buffer
30
+ this.bufferF32 = new Float32Array(this.buffer);
31
+ this.bufferU32 = new Uint32Array(this.buffer);
32
+ }
33
+
34
+ /**
35
+ * clear the vertex array buffer
36
+ * @ignore
37
+ */
38
+ clear() {
39
+ this.vertexCount = 0;
40
+ }
41
+
42
+
43
+ /**
44
+ * return true if full
45
+ * @ignore
46
+ */
47
+ isFull(vertex = this.quadSize) {
48
+ return (this.vertexCount + vertex >= this.maxVertex);
49
+ }
50
+
51
+ /**
52
+ * resize the vertex buffer, retaining its original contents
53
+ * @ignore
54
+ */
55
+ resize() {
56
+ // double the vertex size
57
+ this.maxVertex <<= 1;
58
+ // save a reference to the previous data
59
+ var data = this.bufferF32;
60
+
61
+ // recreate ArrayBuffer and views
62
+ this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.quadSize);
63
+ this.bufferF32 = new Float32Array(this.buffer);
64
+ this.bufferU32 = new Uint32Array(this.buffer);
65
+
66
+ // copy previous data
67
+ this.bufferF32.set(data);
68
+
69
+ return this;
70
+ }
71
+
72
+ /**
73
+ * push a new vertex to the buffer
74
+ * @ignore
75
+ */
76
+ push(x, y, u, v, tint) {
77
+ var offset = this.vertexCount * this.vertexSize;
78
+
79
+ if (this.vertexCount >= this.maxVertex) {
80
+ this.resize();
81
+ }
82
+
83
+ this.bufferF32[offset + 0] = x;
84
+ this.bufferF32[offset + 1] = y;
85
+
86
+ if (typeof u !== "undefined") {
87
+ this.bufferF32[offset + 2] = u;
88
+ this.bufferF32[offset + 3] = v;
89
+ }
90
+
91
+ if (typeof tint !== "undefined") {
92
+ this.bufferU32[offset + 4] = tint;
93
+ }
94
+
95
+ this.vertexCount++;
96
+
97
+ return this;
98
+ }
99
+
100
+ /**
101
+ * return a reference to the data in Float32 format
102
+ * @ignore
103
+ */
104
+ toFloat32(begin, end) {
105
+ if (typeof end !== "undefined") {
106
+ return this.bufferF32.subarray(begin, end);
107
+ } else {
108
+ return this.bufferF32;
109
+ }
110
+ }
111
+
112
+ /**
113
+ * return a reference to the data in Uint32 format
114
+ * @ignore
115
+ */
116
+ toUint32(begin, end) {
117
+ if (typeof end !== "undefined") {
118
+ return this.bufferU32.subarray(begin, end);
119
+ } else {
120
+ return this.bufferU32;
121
+ }
122
+ }
123
+
124
+ /**
125
+ * return the size of the vertex in vertex
126
+ * @ignore
127
+ */
128
+ length() {
129
+ return this.vertexCount;
130
+ }
131
+
132
+ /**
133
+ * return true if empty
134
+ * @ignore
135
+ */
136
+ isEmpty() {
137
+ return this.vertexCount === 0;
138
+ }
139
+
140
+ }
141
+ var VertexArrayBuffer$1 = VertexArrayBuffer;
142
+
143
+ export { VertexArrayBuffer$1 as default };
@@ -0,0 +1,168 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.0
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ import { on, ONCONTEXT_LOST } from '../../system/event.js';
9
+ import { getMaxShaderPrecision } from '../../system/device.js';
10
+ import { extractUniforms } from './utils/uniforms.js';
11
+ import { extractAttributes } from './utils/attributes.js';
12
+ import { compileProgram } from './utils/program.js';
13
+ import { setPrecision } from './utils/precision.js';
14
+ import { minify } from './utils/string.js';
15
+
16
+ /**
17
+ * @classdesc
18
+ * a base GL Shader object
19
+ */
20
+ class GLShader {
21
+ /**
22
+ * @param {WebGLRenderingContext} gl - the current WebGL rendering context
23
+ * @param {string} vertex - a string containing the GLSL source code to set
24
+ * @param {string} fragment - a string containing the GLSL source code to set
25
+ * @param {string} [precision=auto detected] - float precision ('lowp', 'mediump' or 'highp').
26
+ * @see https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders
27
+ * @example
28
+ * // create a basic shader
29
+ * var myShader = new me.GLShader(
30
+ * // WebGL rendering context
31
+ * gl,
32
+ * // vertex shader
33
+ * [
34
+ * "void main() {",
35
+ * " gl_Position = doMathToMakeClipspaceCoordinates;",
36
+ * "}"
37
+ * ].join("\n"),
38
+ * // fragment shader
39
+ * [
40
+ * "void main() {",
41
+ * " gl_FragColor = doMathToMakeAColor;",
42
+ * "}"
43
+ * ].join("\n")
44
+ * )
45
+ * // use the shader
46
+ * myShader.bind();
47
+ */
48
+ constructor(gl, vertex, fragment, precision) {
49
+
50
+ /**
51
+ * the active gl rendering context
52
+ * @type {WebGLRenderingContext}
53
+ */
54
+ this.gl = gl;
55
+
56
+ /**
57
+ * the vertex shader source code
58
+ * @type {string}
59
+ */
60
+ this.vertex = setPrecision(minify(vertex), precision || getMaxShaderPrecision(this.gl));
61
+
62
+ /**
63
+ * the fragment shader source code
64
+ * @type {string}
65
+ */
66
+ this.fragment = setPrecision(minify(fragment), precision || getMaxShaderPrecision(this.gl));
67
+
68
+ /**
69
+ * the location attributes of the shader
70
+ * @type {GLint[]}
71
+ */
72
+ this.attributes = extractAttributes(this.gl, this);
73
+
74
+
75
+ /**
76
+ * a reference to the shader program (once compiled)
77
+ * @type {WebGLProgram}
78
+ */
79
+ this.program = compileProgram(this.gl, this.vertex, this.fragment, this.attributes);
80
+
81
+ /**
82
+ * the uniforms of the shader
83
+ * @type {object}
84
+ */
85
+ this.uniforms = extractUniforms(this.gl, this);
86
+
87
+ // destroy the shader on context lost (will be recreated on context restore)
88
+ on(ONCONTEXT_LOST, this.destroy, this);
89
+ }
90
+
91
+ /**
92
+ * Installs this shader program as part of current rendering state
93
+ */
94
+ bind() {
95
+ this.gl.useProgram(this.program);
96
+ }
97
+
98
+ /**
99
+ * returns the location of an attribute variable in this shader program
100
+ * @param {string} name - the name of the attribute variable whose location to get.
101
+ * @returns {GLint} number indicating the location of the variable name if found. Returns -1 otherwise
102
+ */
103
+ getAttribLocation(name) {
104
+ var attr = this.attributes[name];
105
+ if (typeof attr !== "undefined") {
106
+ return attr;
107
+ } else {
108
+ return -1;
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Set the uniform to the given value
114
+ * @param {string} name - the uniform name
115
+ * @param {object|Float32Array} value - the value to assign to that uniform
116
+ * @example
117
+ * myShader.setUniform("uProjectionMatrix", this.projectionMatrix);
118
+ */
119
+ setUniform(name, value) {
120
+ var uniforms = this.uniforms;
121
+ if (typeof uniforms[name] !== "undefined") {
122
+ if (typeof value === "object" && typeof value.toArray === "function") {
123
+ uniforms[name] = value.toArray();
124
+ } else {
125
+ uniforms[name] = value;
126
+ }
127
+ } else {
128
+ throw new Error("undefined (" + name + ") uniform for shader " + this);
129
+ }
130
+ }
131
+
132
+ /**
133
+ * activate the given vertex attribute for this shader
134
+ * @param {WebGLRenderingContext} gl - the current WebGL rendering context
135
+ * @param {object[]} attributes - an array of vertex attributes
136
+ * @param {number} vertexByteSize - the size of a single vertex in bytes
137
+ */
138
+ setVertexAttributes(gl, attributes, vertexByteSize) {
139
+ // set the vertex attributes
140
+ for (var index = 0; index < attributes.length; ++index) {
141
+ var element = attributes[index];
142
+ var location = this.getAttribLocation(element.name);
143
+
144
+ if (location !== -1) {
145
+ gl.enableVertexAttribArray(location);
146
+ gl.vertexAttribPointer(location, element.size, element.type, element.normalized, vertexByteSize, element.offset);
147
+ } else {
148
+ gl.disableVertexAttribArray(index);
149
+ }
150
+ }
151
+ }
152
+
153
+ /**
154
+ * destroy this shader objects resources (program, attributes, uniforms)
155
+ */
156
+ destroy() {
157
+ this.uniforms = null;
158
+ this.attributes = null;
159
+
160
+ this.gl.deleteProgram(this.program);
161
+
162
+ this.vertex = null;
163
+ this.fragment = null;
164
+ }
165
+ }
166
+ var GLShader$1 = GLShader;
167
+
168
+ export { GLShader$1 as default };
@@ -0,0 +1,10 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.0
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ var primitiveFragment = "varying vec4 vColor;\n\nvoid main(void) {\n gl_FragColor = vColor;\n}\n";
9
+
10
+ export { primitiveFragment as default };
@@ -0,0 +1,10 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.0
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ var primitiveVertex = "// Current vertex point\nattribute vec2 aVertex;\n\n// Projection matrix\nuniform mat4 uProjectionMatrix;\n\n// Vertex color\nuniform vec4 uColor;\n\n// Fragment color\nvarying vec4 vColor;\n\nvoid main(void) {\n // Transform the vertex position by the projection matrix\n gl_Position = uProjectionMatrix * vec4(aVertex, 0.0, 1.0);\n // Pass the remaining attributes to the fragment shader\n vColor = vec4(uColor.rgb * uColor.a, uColor.a);\n}\n";
9
+
10
+ export { primitiveVertex as default };
@@ -0,0 +1,10 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.0
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ var quadFragment = "uniform sampler2D uSampler;\nvarying vec4 vColor;\nvarying vec2 vRegion;\n\nvoid main(void) {\n gl_FragColor = texture2D(uSampler, vRegion) * vColor;\n}\n";
9
+
10
+ export { quadFragment as default };
@@ -0,0 +1,10 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.0
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ var quadVertex = "attribute vec2 aVertex;\nattribute vec2 aRegion;\nattribute vec4 aColor;\n\nuniform mat4 uProjectionMatrix;\n\nvarying vec2 vRegion;\nvarying vec4 vColor;\n\nvoid main(void) {\n // Transform the vertex position by the projection matrix\n gl_Position = uProjectionMatrix * vec4(aVertex, 0.0, 1.0);\n // Pass the remaining attributes to the fragment shader\n vColor = vec4(aColor.bgr * aColor.a, aColor.a);\n vRegion = aRegion;\n}\n";
9
+
10
+ export { quadVertex as default };
@@ -0,0 +1,25 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.0
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ /**
9
+ * @ignore
10
+ */
11
+ function extractAttributes(gl, shader) {
12
+ var attributes = {},
13
+ attrRx = /attribute\s+\w+\s+(\w+)/g,
14
+ match,
15
+ i = 0;
16
+
17
+ // Detect all attribute names
18
+ while ((match = attrRx.exec(shader.vertex))) {
19
+ attributes[match[1]] = i++;
20
+ }
21
+
22
+ return attributes;
23
+ }
24
+
25
+ export { extractAttributes };
@@ -0,0 +1,20 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.0
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ /**
9
+ * set precision for the fiven shader source
10
+ * won't do anything if the precision is already specified
11
+ * @ignore
12
+ */
13
+ function setPrecision(src, precision) {
14
+ if (src.substring(0, 9) !== "precision") {
15
+ return "precision " + precision + " float;" + src;
16
+ }
17
+ return src;
18
+ }
19
+
20
+ export { setPrecision };
@@ -0,0 +1,67 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.0
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ /**
9
+ * @ignore
10
+ */
11
+ function compileShader(gl, type, source) {
12
+ var shader = gl.createShader(type);
13
+ gl.shaderSource(shader, source);
14
+ gl.compileShader(shader);
15
+
16
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
17
+ throw new Error(gl.getShaderInfoLog(shader));
18
+ }
19
+
20
+ return shader;
21
+ }
22
+
23
+ /**
24
+ * Compile GLSL into a shader object
25
+ * @ignore
26
+ */
27
+ function compileProgram(gl, vertex, fragment, attributes) {
28
+ var vertShader = compileShader(gl, gl.VERTEX_SHADER, vertex);
29
+ var fragShader = compileShader(gl, gl.FRAGMENT_SHADER, fragment);
30
+
31
+ var program = gl.createProgram();
32
+
33
+ gl.attachShader(program, vertShader);
34
+ gl.attachShader(program, fragShader);
35
+
36
+
37
+ // force vertex attributes to use location 0 as starting location to prevent
38
+ // browser to do complicated emulation when running on desktop OpenGL (e.g. on macOS)
39
+ for (var location in attributes) {
40
+ gl.bindAttribLocation(program, attributes[location], location);
41
+ }
42
+
43
+ gl.linkProgram(program);
44
+
45
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
46
+ var error_msg =
47
+ "Error initializing Shader " + this + "\n" +
48
+ "gl.VALIDATE_STATUS: " + gl.getProgramParameter(program, gl.VALIDATE_STATUS) + "\n" +
49
+ "gl.getError()" + gl.getError() + "\n" +
50
+ "gl.getProgramInfoLog()" + gl.getProgramInfoLog(program);
51
+ // house cleaning
52
+ gl.deleteProgram(program);
53
+ program = null;
54
+ // throw the exception
55
+ throw new Error(error_msg);
56
+ }
57
+
58
+ gl.useProgram(program);
59
+
60
+ // clean-up
61
+ gl.deleteShader(vertShader);
62
+ gl.deleteShader(fragShader);
63
+
64
+ return program;
65
+ }
66
+
67
+ export { compileProgram };
@@ -0,0 +1,25 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.0
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ /**
9
+ * clean the given source from space, comments, etc...
10
+ * @ignore
11
+ */
12
+ function minify(src) {
13
+ // remove comments
14
+ src = src.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, "$1");
15
+ // Remove leading and trailing whitespace from lines
16
+ src = src.replace(/(\\n\s+)|(\s+\\n)/g, "");
17
+ // Remove line breaks
18
+ src = src.replace(/(\\r|\\n)+/g, "");
19
+ // Remove unnecessary whitespace
20
+ src = src.replace(/\s*([;,[\](){}\\\/\-+*|^&!=<>?~%])\s*/g, "$1");
21
+
22
+ return src;
23
+ }
24
+
25
+ export { minify };
@@ -0,0 +1,92 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.0
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ /**
9
+ * Hash map of GLSL data types to WebGL Uniform methods
10
+ * @ignore
11
+ */
12
+ const fnHash = {
13
+ "bool" : "1i",
14
+ "int" : "1i",
15
+ "float" : "1f",
16
+ "vec2" : "2fv",
17
+ "vec3" : "3fv",
18
+ "vec4" : "4fv",
19
+ "bvec2" : "2iv",
20
+ "bvec3" : "3iv",
21
+ "bvec4" : "4iv",
22
+ "ivec2" : "2iv",
23
+ "ivec3" : "3iv",
24
+ "ivec4" : "4iv",
25
+ "mat2" : "Matrix2fv",
26
+ "mat3" : "Matrix3fv",
27
+ "mat4" : "Matrix4fv",
28
+ "sampler2D" : "1i"
29
+ };
30
+
31
+ /**
32
+ * @ignore
33
+ */
34
+ function extractUniforms(gl, shader) {
35
+ var uniforms = {},
36
+ uniRx = /uniform\s+(\w+)\s+(\w+)/g,
37
+ uniformsData = {},
38
+ descriptor = {},
39
+ locations = {},
40
+ match;
41
+
42
+ // Detect all uniform names and types
43
+ [ shader.vertex, shader.fragment ].forEach((shader) => {
44
+ while ((match = uniRx.exec(shader))) {
45
+ uniformsData[match[2]] = match[1];
46
+ }
47
+ });
48
+
49
+ // Get uniform references
50
+ Object.keys(uniformsData).forEach((name) => {
51
+ var type = uniformsData[name];
52
+ locations[name] = gl.getUniformLocation(shader.program, name);
53
+
54
+ descriptor[name] = {
55
+ "get" : (function (name) {
56
+ /*
57
+ * A getter for the uniform location
58
+ */
59
+ return function () {
60
+ return locations[name];
61
+ };
62
+ })(name),
63
+ "set" : (function (name, type, fn) {
64
+ if (type.indexOf("mat") === 0) {
65
+ /*
66
+ * A generic setter for uniform matrices
67
+ */
68
+ return function (val) {
69
+ gl[fn](locations[name], false, val);
70
+ };
71
+ }
72
+ else {
73
+ /*
74
+ * A generic setter for uniform vectors
75
+ */
76
+ return function (val) {
77
+ var fnv = fn;
78
+ if (val.length && fn.slice(-1) !== "v") {
79
+ fnv += "v";
80
+ }
81
+ gl[fnv](locations[name], val);
82
+ };
83
+ }
84
+ })(name, type, "uniform" + fnHash[type])
85
+ };
86
+ });
87
+ Object.defineProperties(uniforms, descriptor);
88
+
89
+ return uniforms;
90
+ }
91
+
92
+ export { extractUniforms };