melonjs 10.2.0 → 10.3.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 (95) hide show
  1. package/README.md +1 -1
  2. package/dist/melonjs.js +4435 -4283
  3. package/dist/melonjs.min.js +4 -4
  4. package/dist/melonjs.module.d.ts +3348 -3833
  5. package/dist/melonjs.module.js +4025 -3920
  6. package/package.json +13 -14
  7. package/src/audio/audio.js +45 -45
  8. package/src/camera/camera2d.js +78 -101
  9. package/src/entity/draggable.js +21 -29
  10. package/src/entity/droptarget.js +24 -31
  11. package/src/entity/entity.js +34 -38
  12. package/src/game.js +8 -8
  13. package/src/{shapes → geometries}/ellipse.js +46 -46
  14. package/src/{shapes → geometries}/line.js +14 -14
  15. package/src/{shapes → geometries}/poly.js +103 -54
  16. package/src/{shapes → geometries}/rectangle.js +73 -120
  17. package/src/index.js +18 -19
  18. package/src/input/gamepad.js +20 -20
  19. package/src/input/input.js +3 -3
  20. package/src/input/keyboard.js +122 -124
  21. package/src/input/pointer.js +102 -62
  22. package/src/input/pointerevent.js +97 -42
  23. package/src/lang/deprecated.js +29 -18
  24. package/src/level/level.js +34 -26
  25. package/src/level/tiled/TMXGroup.js +12 -13
  26. package/src/level/tiled/TMXLayer.js +41 -42
  27. package/src/level/tiled/TMXObject.js +76 -70
  28. package/src/level/tiled/TMXTile.js +13 -15
  29. package/src/level/tiled/TMXTileMap.js +26 -25
  30. package/src/level/tiled/TMXTileset.js +14 -15
  31. package/src/level/tiled/TMXTilesetGroup.js +5 -6
  32. package/src/level/tiled/TMXUtils.js +13 -11
  33. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +3 -4
  34. package/src/level/tiled/renderer/TMXIsometricRenderer.js +3 -4
  35. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +2 -3
  36. package/src/level/tiled/renderer/TMXRenderer.js +18 -19
  37. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +2 -3
  38. package/src/loader/loader.js +46 -40
  39. package/src/loader/loadingscreen.js +7 -7
  40. package/src/math/color.js +68 -88
  41. package/src/math/math.js +33 -33
  42. package/src/math/matrix2.js +70 -71
  43. package/src/math/matrix3.js +90 -91
  44. package/src/math/observable_vector2.js +91 -92
  45. package/src/math/observable_vector3.js +110 -106
  46. package/src/math/vector2.js +116 -104
  47. package/src/math/vector3.js +129 -110
  48. package/src/particles/emitter.js +116 -126
  49. package/src/particles/particle.js +4 -5
  50. package/src/particles/particlecontainer.js +2 -3
  51. package/src/physics/body.js +82 -83
  52. package/src/physics/bounds.js +64 -66
  53. package/src/physics/collision.js +21 -22
  54. package/src/physics/detector.js +13 -13
  55. package/src/physics/quadtree.js +26 -25
  56. package/src/physics/sat.js +21 -21
  57. package/src/physics/world.js +23 -22
  58. package/src/plugin/plugin.js +12 -13
  59. package/src/renderable/GUI.js +20 -26
  60. package/src/renderable/collectable.js +6 -7
  61. package/src/renderable/colorlayer.js +11 -12
  62. package/src/renderable/container.js +98 -81
  63. package/src/renderable/imagelayer.js +33 -35
  64. package/src/renderable/nineslicesprite.js +15 -16
  65. package/src/renderable/renderable.js +112 -111
  66. package/src/renderable/sprite.js +71 -58
  67. package/src/renderable/trigger.js +17 -19
  68. package/src/state/stage.js +14 -15
  69. package/src/state/state.js +78 -78
  70. package/src/system/device.js +137 -180
  71. package/src/system/event.js +116 -104
  72. package/src/system/pooling.js +15 -15
  73. package/src/system/save.js +9 -6
  74. package/src/system/timer.js +33 -33
  75. package/src/text/bitmaptext.js +39 -46
  76. package/src/text/bitmaptextdata.js +14 -15
  77. package/src/text/text.js +55 -58
  78. package/src/tweens/easing.js +5 -5
  79. package/src/tweens/interpolation.js +5 -5
  80. package/src/tweens/tween.js +49 -40
  81. package/src/utils/agent.js +12 -11
  82. package/src/utils/array.js +8 -8
  83. package/src/utils/file.js +7 -7
  84. package/src/utils/function.js +8 -8
  85. package/src/utils/string.js +19 -19
  86. package/src/utils/utils.js +23 -23
  87. package/src/video/canvas/canvas_renderer.js +127 -128
  88. package/src/video/renderer.js +69 -69
  89. package/src/video/texture.js +80 -82
  90. package/src/video/texture_cache.js +2 -4
  91. package/src/video/video.js +38 -38
  92. package/src/video/webgl/buffer/vertex.js +11 -3
  93. package/src/video/webgl/glshader.js +31 -32
  94. package/src/video/webgl/webgl_compositor.js +145 -127
  95. package/src/video/webgl/webgl_renderer.js +196 -175
@@ -9,7 +9,6 @@ import primitiveFragment from "./shaders/primitive.frag";
9
9
  import quadVertex from "./shaders/quad.vert";
10
10
  import quadFragment from "./shaders/quad.frag";
11
11
 
12
-
13
12
  // a pool of resuable vectors
14
13
  var V_ARRAY = [
15
14
  new Vector2d(),
@@ -18,47 +17,12 @@ var V_ARRAY = [
18
17
  new Vector2d()
19
18
  ];
20
19
 
21
- // Handy constants
22
- var VERTEX_SIZE = 2;
23
- var REGION_SIZE = 2;
24
- var COLOR_SIZE = 4;
25
-
26
- var ELEMENT_SIZE = VERTEX_SIZE + REGION_SIZE + COLOR_SIZE;
27
- var ELEMENT_OFFSET = ELEMENT_SIZE * Float32Array.BYTES_PER_ELEMENT;
28
-
29
- var ELEMENTS_PER_QUAD = 4;
30
- var INDICES_PER_QUAD = 6;
31
-
32
- var MAX_LENGTH = 16000;
33
-
34
- /**
35
- * Create a full index buffer for the element array
36
- * @ignore
37
- */
38
- function createIB() {
39
- var indices = [
40
- 0, 1, 2,
41
- 2, 1, 3
42
- ];
43
-
44
- // ~384KB index buffer
45
- var data = new Array(MAX_LENGTH * INDICES_PER_QUAD);
46
- for (var i = 0; i < data.length; i++) {
47
- data[i] = indices[i % INDICES_PER_QUAD] +
48
- ~~(i / INDICES_PER_QUAD) * ELEMENTS_PER_QUAD;
49
- }
50
-
51
- return new Uint16Array(data);
52
- };
53
-
54
-
55
20
  /**
56
21
  * @classdesc
57
22
  * A WebGL Compositor object. This class handles all of the WebGL state<br>
58
23
  * Pushes texture regions or shape geometry into WebGL buffers, automatically flushes to GPU
59
24
  * @class WebGLCompositor
60
- * @memberOf me
61
- * @constructor
25
+ * @memberof me
62
26
  * @param {me.WebGLRenderer} renderer the current WebGL renderer session
63
27
  */
64
28
  class WebGLCompositor {
@@ -75,15 +39,6 @@ class WebGLCompositor {
75
39
  // local reference
76
40
  var gl = renderer.gl;
77
41
 
78
- /**
79
- * The number of quads held in the batch
80
- * @name length
81
- * @memberOf me.WebGLCompositor
82
- * @type Number
83
- * @readonly
84
- */
85
- //this.length = 0;
86
-
87
42
  // list of active texture units
88
43
  this.currentTextureUnit = -1;
89
44
  this.boundTextures = [];
@@ -103,7 +58,7 @@ class WebGLCompositor {
103
58
  /**
104
59
  * a reference to the active WebGL shader
105
60
  * @name activeShader
106
- * @memberOf me.WebGLCompositor
61
+ * @memberof me.WebGLCompositor
107
62
  * @type {me.GLShader}
108
63
  */
109
64
  this.activeShader = null;
@@ -112,7 +67,7 @@ class WebGLCompositor {
112
67
  * primitive type to render (gl.POINTS, gl.LINE_STRIP, gl.LINE_LOOP, gl.LINES, gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN, gl.TRIANGLES)
113
68
  * @name mode
114
69
  * @see me.WebGLCompositor
115
- * @memberOf me.WebGLCompositor
70
+ * @memberof me.WebGLCompositor
116
71
  * @default gl.TRIANGLES
117
72
  */
118
73
  this.mode = gl.TRIANGLES;
@@ -121,10 +76,28 @@ class WebGLCompositor {
121
76
  * an array of vertex attribute properties
122
77
  * @name attributes
123
78
  * @see me.WebGLCompositor.addAttribute
124
- * @memberOf me.WebGLCompositor
79
+ * @memberof me.WebGLCompositor
125
80
  */
126
81
  this.attributes = [];
127
82
 
83
+ /**
84
+ * the size of a single vertex in bytes
85
+ * (will automatically be calculated as attributes definitions are added)
86
+ * @name vertexByteSize
87
+ * @see me.WebGLCompositor.addAttribute
88
+ * @memberof me.WebGLCompositor
89
+ */
90
+ this.vertexByteSize = 0;
91
+
92
+ /**
93
+ * the size of a single vertex in floats
94
+ * (will automatically be calculated as attributes definitions are added)
95
+ * @name vertexSize
96
+ * @see me.WebGLCompositor.addAttribute
97
+ * @memberof me.WebGLCompositor
98
+ */
99
+ this.vertexSize = 0;
100
+
128
101
  // Load and create shader programs
129
102
  this.primitiveShader = new GLShader(this.gl, primitiveVertex, primitiveFragment);
130
103
  this.quadShader = new GLShader(this.gl, quadVertex, quadFragment);
@@ -134,27 +107,17 @@ class WebGLCompositor {
134
107
  this.addAttribute("aRegion", 2, gl.FLOAT, false, 2 * Float32Array.BYTES_PER_ELEMENT); // 1
135
108
  this.addAttribute("aColor", 4, gl.UNSIGNED_BYTE, true, 4 * Float32Array.BYTES_PER_ELEMENT); // 2
136
109
 
110
+ this.vertexBuffer = new VertexArrayBuffer(this.vertexSize, 6); // 6 vertices per quad
111
+
137
112
  // vertex buffer
138
113
  gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
139
- gl.bufferData(
140
- gl.ARRAY_BUFFER,
141
- MAX_LENGTH * ELEMENT_OFFSET * ELEMENTS_PER_QUAD,
142
- gl.STREAM_DRAW
143
- );
144
-
145
- this.vertexBuffer = new VertexArrayBuffer(ELEMENT_SIZE, ELEMENTS_PER_QUAD);
146
-
147
- // Cache index buffer (TODO Remove use for cache by replacing drawElements by drawArrays)
148
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, gl.createBuffer());
149
- gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, createIB(), gl.STATIC_DRAW);
114
+ gl.bufferData(gl.ARRAY_BUFFER, this.vertexBuffer.buffer, gl.STREAM_DRAW);
150
115
 
151
116
  // register to the CANVAS resize channel
152
117
  event.on(event.CANVAS_ONRESIZE, (width, height) => {
153
118
  this.flush();
154
119
  this.setViewport(0, 0, width, height);
155
120
  });
156
-
157
- this.reset();
158
121
  }
159
122
 
160
123
  /**
@@ -179,11 +142,10 @@ class WebGLCompositor {
179
142
 
180
143
  // delete all related bound texture
181
144
  for (var i = 0; i < this.renderer.maxTextures; i++) {
182
- var texture = this.boundTextures[i];
183
- if (texture !== null) {
184
- this.gl.deleteTexture(texture);
145
+ var texture2D = this.getTexture2D(i);
146
+ if (typeof texture2D !== "undefined") {
147
+ this.deleteTexture2D(texture2D);
185
148
  }
186
- this.boundTextures[i] = null;
187
149
  }
188
150
  this.currentTextureUnit = -1;
189
151
 
@@ -194,13 +156,13 @@ class WebGLCompositor {
194
156
  /**
195
157
  * add vertex attribute property definition to the compositor
196
158
  * @name addAttribute
197
- * @memberOf me.WebGLCompositor
159
+ * @memberof me.WebGLCompositor
198
160
  * @function
199
- * @param {String} name name of the attribute in the vertex shader
200
- * @param {Number} size number of components per vertex attribute. Must be 1, 2, 3, or 4.
161
+ * @param {string} name name of the attribute in the vertex shader
162
+ * @param {number} size number of components per vertex attribute. Must be 1, 2, 3, or 4.
201
163
  * @param {GLenum} type data type of each component in the array
202
- * @param {Boolean} normalized whether integer data values should be normalized into a certain range when being cast to a float
203
- * @param {Number} offset offset in bytes of the first component in the vertex attribute array
164
+ * @param {boolean} normalized whether integer data values should be normalized into a certain range when being cast to a float
165
+ * @param {number} offset offset in bytes of the first component in the vertex attribute array
204
166
  */
205
167
  addAttribute(name, size, type, normalized, offset) {
206
168
  this.attributes.push({
@@ -210,17 +172,44 @@ class WebGLCompositor {
210
172
  normalized: normalized,
211
173
  offset: offset
212
174
  });
175
+
176
+ switch (type) {
177
+ case this.gl.BYTE:
178
+ this.vertexByteSize += size * Int8Array.BYTES_PER_ELEMENT;
179
+ break;
180
+ case this.gl.UNSIGNED_BYTE:
181
+ this.vertexByteSize += size * Uint8Array.BYTES_PER_ELEMENT;
182
+ break;
183
+ case this.gl.SHORT:
184
+ this.vertexByteSize += size * Int16Array.BYTES_PER_ELEMENT;
185
+ break;
186
+ case this.gl.UNSIGNED_SHORT:
187
+ this.vertexByteSize += size * Uint16Array.BYTES_PER_ELEMENT;
188
+ break;
189
+ case this.gl.INT:
190
+ this.vertexByteSize += size * Int32Array.BYTES_PER_ELEMENT;
191
+ break;
192
+ case this.gl.UNSIGNED_INT:
193
+ this.vertexByteSize += size * Uint32Array.BYTES_PER_ELEMENT;
194
+ break;
195
+ case this.gl.FLOAT:
196
+ this.vertexByteSize += size * Float32Array.BYTES_PER_ELEMENT;
197
+ break;
198
+ default:
199
+ throw new Error("Invalid GL Attribute type");
200
+ }
201
+ this.vertexSize = this.vertexByteSize / Float32Array.BYTES_PER_ELEMENT;
213
202
  }
214
203
 
215
204
  /**
216
205
  * Sets the viewport
217
206
  * @name setViewport
218
- * @memberOf me.WebGLCompositor
207
+ * @memberof me.WebGLCompositor
219
208
  * @function
220
- * @param {Number} x x position of viewport
221
- * @param {Number} y y position of viewport
222
- * @param {Number} width width of viewport
223
- * @param {Number} height height of viewport
209
+ * @param {number} x x position of viewport
210
+ * @param {number} y y position of viewport
211
+ * @param {number} w width of viewport
212
+ * @param {number} h height of viewport
224
213
  */
225
214
  setViewport(x, y, w, h) {
226
215
  this.gl.viewport(x, y, w, h);
@@ -229,19 +218,18 @@ class WebGLCompositor {
229
218
  /**
230
219
  * Create a WebGL texture from an image
231
220
  * @name createTexture2D
232
- * @memberOf me.WebGLCompositor
221
+ * @memberof me.WebGLCompositor
233
222
  * @function
234
- * @param {Number} unit Destination texture unit
235
- * @param {Image|Canvas|ImageData|UInt8Array[]|Float32Array[]} image Source image
236
- * @param {Number} filter gl.LINEAR or gl.NEAREST
237
- * @param {String} [repeat="no-repeat"] Image repeat behavior (see {@link me.ImageLayer#repeat})
238
- * @param {Number} [w] Source image width (Only use with UInt8Array[] or Float32Array[] source image)
239
- * @param {Number} [h] Source image height (Only use with UInt8Array[] or Float32Array[] source image)
240
- * @param {Number} [b] Source image border (Only use with UInt8Array[] or Float32Array[] source image)
241
- * @param {Number} [b] Source image border (Only use with UInt8Array[] or Float32Array[] source image)
242
- * @param {Boolean} [premultipliedAlpha=true] Multiplies the alpha channel into the other color channels
243
- * @param {Boolean} [mipmap=true] Whether mipmap levels should be generated for this texture
244
- * @return {WebGLTexture} a WebGL texture
223
+ * @param {number} unit Destination texture unit
224
+ * @param {Image|HTMLCanvasElement|ImageData|Uint8Array[]|Float32Array[]} image Source image
225
+ * @param {number} filter gl.LINEAR or gl.NEAREST
226
+ * @param {string} [repeat="no-repeat"] Image repeat behavior (see {@link me.ImageLayer#repeat})
227
+ * @param {number} [w] Source image width (Only use with UInt8Array[] or Float32Array[] source image)
228
+ * @param {number} [h] Source image height (Only use with UInt8Array[] or Float32Array[] source image)
229
+ * @param {number} [b] Source image border (Only use with UInt8Array[] or Float32Array[] source image)
230
+ * @param {boolean} [premultipliedAlpha=true] Multiplies the alpha channel into the other color channels
231
+ * @param {boolean} [mipmap=true] Whether mipmap levels should be generated for this texture
232
+ * @returns {WebGLTexture} a WebGL texture
245
233
  */
246
234
  createTexture2D(unit, image, filter, repeat = "no-repeat", w, h, b, premultipliedAlpha = true, mipmap = true) {
247
235
  var gl = this.gl;
@@ -272,13 +260,38 @@ class WebGLCompositor {
272
260
  return texture;
273
261
  }
274
262
 
263
+ /**
264
+ * delete the given WebGL texture
265
+ * @name bindTexture2D
266
+ * @memberof me.WebGLCompositor
267
+ * @function
268
+ * @param {WebGLTexture} [texture] a WebGL texture to delete
269
+ * @param {number} [unit] Texture unit to delete
270
+ */
271
+ deleteTexture2D(texture) {
272
+ this.gl.deleteTexture(texture);
273
+ this.unbindTexture2D(texture);
274
+ }
275
+
276
+ /**
277
+ * returns the WebGL texture associated to the given texture unit
278
+ * @name bindTexture2D
279
+ * @memberof me.WebGLCompositor
280
+ * @function
281
+ * @param {number} unit Texture unit to which a texture is bound
282
+ * @returns {WebGLTexture} texture a WebGL texture
283
+ */
284
+ getTexture2D(unit) {
285
+ return this.boundTextures[unit];
286
+ }
287
+
275
288
  /**
276
289
  * assign the given WebGL texture to the current batch
277
290
  * @name bindTexture2D
278
- * @memberOf me.WebGLCompositor
291
+ * @memberof me.WebGLCompositor
279
292
  * @function
280
- * @param {WebGLTexture} a WebGL texture
281
- * @param {Number} unit Texture unit to which the given texture is bound
293
+ * @param {WebGLTexture} texture a WebGL texture
294
+ * @param {number} unit Texture unit to which the given texture is bound
282
295
  */
283
296
  bindTexture2D(texture, unit) {
284
297
  var gl = this.gl;
@@ -303,23 +316,33 @@ class WebGLCompositor {
303
316
  /**
304
317
  * unbind the given WebGL texture, forcing it to be reuploaded
305
318
  * @name unbindTexture2D
306
- * @memberOf me.WebGLCompositor
319
+ * @memberof me.WebGLCompositor
307
320
  * @function
308
- * @param {WebGLTexture} a WebGL texture
321
+ * @param {WebGLTexture} [texture] a WebGL texture
322
+ * @param {number} [unit] a WebGL texture
323
+ * @returns {number} unit the unit number that was associated with the given texture
309
324
  */
310
- unbindTexture2D(texture) {
311
- var unit = this.renderer.cache.getUnit(texture);
312
- this.boundTextures[unit] = null;
325
+ unbindTexture2D(texture, unit) {
326
+ if (typeof unit === "undefined") {
327
+ unit = this.boundTextures.indexOf(texture);
328
+ }
329
+ if (unit !== -1) {
330
+ delete this.boundTextures[unit];
331
+ if (unit === this.currentTextureUnit) {
332
+ this.currentTextureUnit = -1;
333
+ }
334
+ }
335
+ return unit;
313
336
  }
314
337
 
315
338
  /**
316
339
  * @ignore
317
340
  */
318
- uploadTexture(texture, w, h, b, force) {
341
+ uploadTexture(texture, w, h, b, force = false) {
319
342
  var unit = this.renderer.cache.getUnit(texture);
320
343
  var texture2D = this.boundTextures[unit];
321
344
 
322
- if (texture2D === null || force) {
345
+ if (typeof texture2D === "undefined" || force) {
323
346
  this.createTexture2D(
324
347
  unit,
325
348
  texture.getTexture(),
@@ -341,7 +364,7 @@ class WebGLCompositor {
341
364
  * Select the shader to use for compositing
342
365
  * @name useShader
343
366
  * @see me.GLShader
344
- * @memberOf me.WebGLCompositor
367
+ * @memberof me.WebGLCompositor
345
368
  * @function
346
369
  * @param {me.GLShader} shader a reference to a GLShader instance
347
370
  */
@@ -360,7 +383,7 @@ class WebGLCompositor {
360
383
 
361
384
  if (location !== -1) {
362
385
  gl.enableVertexAttribArray(location);
363
- gl.vertexAttribPointer(location, element.size, element.type, element.normalized, ELEMENT_OFFSET, element.offset);
386
+ gl.vertexAttribPointer(location, element.size, element.type, element.normalized, this.vertexByteSize, element.offset);
364
387
  } else {
365
388
  gl.disableVertexAttribArray(index);
366
389
  }
@@ -371,18 +394,18 @@ class WebGLCompositor {
371
394
  /**
372
395
  * Add a textured quad
373
396
  * @name addQuad
374
- * @memberOf me.WebGLCompositor
397
+ * @memberof me.WebGLCompositor
375
398
  * @function
376
399
  * @param {me.Renderer.Texture} texture Source texture
377
- * @param {Number} x Destination x-coordinate
378
- * @param {Number} y Destination y-coordinate
379
- * @param {Number} w Destination width
380
- * @param {Number} h Destination height
400
+ * @param {number} x Destination x-coordinate
401
+ * @param {number} y Destination y-coordinate
402
+ * @param {number} w Destination width
403
+ * @param {number} h Destination height
381
404
  * @param {number} u0 Texture UV (u0) value.
382
405
  * @param {number} v0 Texture UV (v0) value.
383
406
  * @param {number} u1 Texture UV (u1) value.
384
407
  * @param {number} v1 Texture UV (v1) value.
385
- * @param {number} tint tint color to be applied to the texture in UINT32 format
408
+ * @param {number} tint tint color to be applied to the texture in UINT32 (argb) format
386
409
  */
387
410
  addQuad(texture, x, y, w, h, u0, v0, u1, v1, tint) {
388
411
 
@@ -393,8 +416,8 @@ class WebGLCompositor {
393
416
 
394
417
  this.useShader(this.quadShader);
395
418
 
396
- if (this.vertexBuffer.isFull(4)) {
397
- // is the vertex buffer full if we add 4 more vertices
419
+ if (this.vertexBuffer.isFull(6)) {
420
+ // is the vertex buffer full if we add 6 more vertices
398
421
  this.flush();
399
422
  }
400
423
 
@@ -420,13 +443,15 @@ class WebGLCompositor {
420
443
  this.vertexBuffer.push(vec0.x, vec0.y, u0, v0, tint);
421
444
  this.vertexBuffer.push(vec1.x, vec1.y, u1, v0, tint);
422
445
  this.vertexBuffer.push(vec2.x, vec2.y, u0, v1, tint);
446
+ this.vertexBuffer.push(vec2.x, vec2.y, u0, v1, tint);
447
+ this.vertexBuffer.push(vec1.x, vec1.y, u1, v0, tint);
423
448
  this.vertexBuffer.push(vec3.x, vec3.y, u1, v1, tint);
424
449
  }
425
450
 
426
451
  /**
427
452
  * Flush batched texture operations to the GPU
428
- * @param
429
- * @memberOf me.WebGLCompositor
453
+ * @param {number} [mode=gl.TRIANGLES] the GL drawing mode
454
+ * @memberof me.WebGLCompositor
430
455
  * @function
431
456
  */
432
457
  flush(mode = this.mode) {
@@ -444,14 +469,7 @@ class WebGLCompositor {
444
469
  gl.bufferData(gl.ARRAY_BUFFER, vertex.toFloat32(0, vertexCount * vertexSize), gl.STREAM_DRAW);
445
470
  }
446
471
 
447
- // Draw the stream buffer
448
- // TODO : finalize the WebGLCompositor implementation (splitting this one into two)
449
- // so that different compositor with different attributes/uniforms & drawing method can be used
450
- if (this.activeShader === this.primitiveShader) {
451
- gl.drawArrays(mode, 0, vertexCount);
452
- } else {
453
- gl.drawElements(mode, vertexCount / vertex.quadSize * INDICES_PER_QUAD, gl.UNSIGNED_SHORT, 0);
454
- }
472
+ gl.drawArrays(mode, 0, vertexCount);
455
473
 
456
474
  // clear the vertex buffer
457
475
  vertex.clear();
@@ -461,11 +479,11 @@ class WebGLCompositor {
461
479
  /**
462
480
  * Draw an array of vertices
463
481
  * @name drawVertices
464
- * @memberOf me.WebGLCompositor
482
+ * @memberof me.WebGLCompositor
465
483
  * @function
466
- * @param {GLENUM} mode primitive type to render (gl.POINTS, gl.LINE_STRIP, gl.LINE_LOOP, gl.LINES, gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN, gl.TRIANGLES)
484
+ * @param {GLenum} mode primitive type to render (gl.POINTS, gl.LINE_STRIP, gl.LINE_LOOP, gl.LINES, gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN, gl.TRIANGLES)
467
485
  * @param {me.Vector2d[]} verts vertices
468
- * @param {Number} [vertexCount=verts.length] amount of points defined in the points array
486
+ * @param {number} [vertexCount=verts.length] amount of points defined in the points array
469
487
  */
470
488
  drawVertices(mode, verts, vertexCount = verts.length) {
471
489
  // use the primitive shader
@@ -491,12 +509,12 @@ class WebGLCompositor {
491
509
  /**
492
510
  * Specify the color values used when clearing color buffers. The values are clamped between 0 and 1.
493
511
  * @name clearColor
494
- * @memberOf me.WebGLCompositor
512
+ * @memberof me.WebGLCompositor
495
513
  * @function
496
- * @param {Number} r - the red color value used when the color buffers are cleared
497
- * @param {Number} g - the green color value used when the color buffers are cleared
498
- * @param {Number} b - the blue color value used when the color buffers are cleared
499
- * @param {Number} a - the alpha color value used when the color buffers are cleared
514
+ * @param {number} [r=0] - the red color value used when the color buffers are cleared
515
+ * @param {number} [g=0] - the green color value used when the color buffers are cleared
516
+ * @param {number} [b=0] - the blue color value used when the color buffers are cleared
517
+ * @param {number} [a=0] - the alpha color value used when the color buffers are cleared
500
518
  */
501
519
  clearColor(r, g, b, a) {
502
520
  this.gl.clearColor(r, g, b, a);
@@ -505,7 +523,7 @@ class WebGLCompositor {
505
523
  /**
506
524
  * Clear the frame buffer
507
525
  * @name clear
508
- * @memberOf me.WebGLCompositor
526
+ * @memberof me.WebGLCompositor
509
527
  * @function
510
528
  */
511
529
  clear() {