melonjs 10.2.3 → 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 (93) hide show
  1. package/dist/melonjs.js +1741 -1558
  2. package/dist/melonjs.min.js +4 -4
  3. package/dist/melonjs.module.d.ts +1256 -1758
  4. package/dist/melonjs.module.js +1734 -1582
  5. package/package.json +12 -12
  6. package/src/audio/audio.js +3 -3
  7. package/src/camera/camera2d.js +26 -27
  8. package/src/entity/draggable.js +10 -19
  9. package/src/entity/droptarget.js +12 -20
  10. package/src/entity/entity.js +13 -13
  11. package/src/game.js +6 -6
  12. package/src/{shapes → geometries}/ellipse.js +19 -20
  13. package/src/{shapes → geometries}/line.js +6 -7
  14. package/src/{shapes → geometries}/poly.js +70 -23
  15. package/src/{shapes → geometries}/rectangle.js +23 -24
  16. package/src/index.js +8 -9
  17. package/src/input/gamepad.js +7 -7
  18. package/src/input/input.js +2 -2
  19. package/src/input/keyboard.js +108 -108
  20. package/src/input/pointer.js +61 -28
  21. package/src/input/pointerevent.js +79 -16
  22. package/src/lang/deprecated.js +26 -15
  23. package/src/level/level.js +10 -10
  24. package/src/level/tiled/TMXGroup.js +6 -7
  25. package/src/level/tiled/TMXLayer.js +10 -11
  26. package/src/level/tiled/TMXObject.js +57 -51
  27. package/src/level/tiled/TMXTile.js +2 -3
  28. package/src/level/tiled/TMXTileMap.js +3 -4
  29. package/src/level/tiled/TMXTileset.js +1 -2
  30. package/src/level/tiled/TMXTilesetGroup.js +1 -2
  31. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -3
  32. package/src/level/tiled/renderer/TMXIsometricRenderer.js +2 -3
  33. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +2 -3
  34. package/src/level/tiled/renderer/TMXRenderer.js +1 -2
  35. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +2 -3
  36. package/src/loader/loader.js +17 -15
  37. package/src/loader/loadingscreen.js +1 -2
  38. package/src/math/color.js +23 -24
  39. package/src/math/math.js +16 -16
  40. package/src/math/matrix2.js +24 -25
  41. package/src/math/matrix3.js +26 -27
  42. package/src/math/observable_vector2.js +46 -35
  43. package/src/math/observable_vector3.js +54 -36
  44. package/src/math/vector2.js +58 -47
  45. package/src/math/vector3.js +66 -48
  46. package/src/particles/emitter.js +64 -72
  47. package/src/particles/particle.js +3 -4
  48. package/src/particles/particlecontainer.js +2 -3
  49. package/src/physics/body.js +38 -39
  50. package/src/physics/bounds.js +30 -32
  51. package/src/physics/collision.js +6 -6
  52. package/src/physics/detector.js +3 -3
  53. package/src/physics/quadtree.js +8 -9
  54. package/src/physics/sat.js +4 -4
  55. package/src/physics/world.js +11 -12
  56. package/src/plugin/plugin.js +6 -7
  57. package/src/renderable/GUI.js +7 -8
  58. package/src/renderable/collectable.js +3 -4
  59. package/src/renderable/colorlayer.js +7 -8
  60. package/src/renderable/container.js +36 -37
  61. package/src/renderable/imagelayer.js +4 -5
  62. package/src/renderable/nineslicesprite.js +2 -3
  63. package/src/renderable/renderable.js +45 -46
  64. package/src/renderable/sprite.js +16 -17
  65. package/src/renderable/trigger.js +4 -5
  66. package/src/state/stage.js +8 -9
  67. package/src/state/state.js +24 -24
  68. package/src/system/device.js +41 -97
  69. package/src/system/event.js +45 -33
  70. package/src/system/pooling.js +1 -1
  71. package/src/system/save.js +3 -3
  72. package/src/system/timer.js +13 -13
  73. package/src/text/bitmaptext.js +12 -13
  74. package/src/text/bitmaptextdata.js +5 -6
  75. package/src/text/text.js +16 -17
  76. package/src/tweens/easing.js +1 -1
  77. package/src/tweens/interpolation.js +1 -1
  78. package/src/tweens/tween.js +14 -15
  79. package/src/utils/agent.js +3 -3
  80. package/src/utils/array.js +4 -4
  81. package/src/utils/file.js +3 -3
  82. package/src/utils/function.js +3 -3
  83. package/src/utils/string.js +7 -7
  84. package/src/utils/utils.js +4 -4
  85. package/src/video/canvas/canvas_renderer.js +39 -40
  86. package/src/video/renderer.js +29 -30
  87. package/src/video/texture.js +8 -9
  88. package/src/video/texture_cache.js +2 -4
  89. package/src/video/video.js +7 -7
  90. package/src/video/webgl/buffer/vertex.js +2 -2
  91. package/src/video/webgl/glshader.js +11 -12
  92. package/src/video/webgl/webgl_compositor.js +118 -90
  93. package/src/video/webgl/webgl_renderer.js +95 -74
@@ -10,7 +10,7 @@ import { initialized, version } from "./../index.js";
10
10
  /**
11
11
  * video functions
12
12
  * @namespace me.video
13
- * @memberOf me
13
+ * @memberof me
14
14
  */
15
15
 
16
16
  var designRatio = 1;
@@ -126,7 +126,7 @@ function onresize() {
126
126
  /**
127
127
  * Select the HTML5 Canvas renderer
128
128
  * @name CANVAS
129
- * @memberOf me.video
129
+ * @memberof me.video
130
130
  * @constant
131
131
  */
132
132
  export const CANVAS = 0;
@@ -134,7 +134,7 @@ export const CANVAS = 0;
134
134
  /**
135
135
  * Select the WebGL renderer
136
136
  * @name WEBGL
137
- * @memberOf me.video
137
+ * @memberof me.video
138
138
  * @constant
139
139
  */
140
140
  export const WEBGL = 1;
@@ -142,7 +142,7 @@ export const WEBGL = 1;
142
142
  /**
143
143
  * Auto-select the renderer (Attempt WebGL first, with fallback to Canvas)
144
144
  * @name AUTO
145
- * @memberOf me.video
145
+ * @memberof me.video
146
146
  * @constant
147
147
  */
148
148
  export const AUTO = 2;
@@ -153,7 +153,7 @@ export const AUTO = 2;
153
153
  * @type {HTMLElement}
154
154
  * @readonly
155
155
  * @name parent
156
- * @memberOf me.video
156
+ * @memberof me.video
157
157
  */
158
158
  export let parent = null;
159
159
 
@@ -162,7 +162,7 @@ export let parent = null;
162
162
  * @name scaleRatio
163
163
  * @type {me.Vector2d}
164
164
  * @default <1,1>
165
- * @memberOf me.video
165
+ * @memberof me.video
166
166
  */
167
167
  export let scaleRatio = new Vector2d(1, 1);
168
168
 
@@ -170,7 +170,7 @@ export let scaleRatio = new Vector2d(1, 1);
170
170
  * A reference to the active Canvas or WebGL active renderer renderer
171
171
  * @name renderer
172
172
  * @type {me.CanvasRenderer|me.WebGLRenderer}
173
- * @memberOf me.video
173
+ * @memberof me.video
174
174
  */
175
175
  export let renderer = null;
176
176
 
@@ -8,7 +8,7 @@
8
8
  class VertexArrayBuffer {
9
9
 
10
10
  constructor(vertex_size, vertex_per_quad) {
11
- // the size of one vertex
11
+ // the size of one vertex in float
12
12
  this.vertexSize = vertex_size;
13
13
  // size of a quad in vertex
14
14
  this.quadSize = vertex_per_quad;
@@ -40,7 +40,7 @@ class VertexArrayBuffer {
40
40
  * return true if full
41
41
  * @ignore
42
42
  */
43
- isFull(vertex = 0) {
43
+ isFull(vertex = this.quadSize) {
44
44
  return (this.vertexCount + vertex >= this.maxVertex);
45
45
  }
46
46
 
@@ -198,12 +198,11 @@ function minify(src) {
198
198
  * @classdesc
199
199
  * a base GL Shader object
200
200
  * @class GLShader
201
- * @memberOf me
201
+ * @memberof me
202
202
  * @param {WebGLRenderingContext} gl the current WebGL rendering context
203
203
  * @param {string} vertex a string containing the GLSL source code to set
204
204
  * @param {string} fragment a string containing the GLSL source code to set
205
205
  * @param {string} [precision=auto detected] float precision ('lowp', 'mediump' or 'highp').
206
- * @constructor
207
206
  * @see https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders
208
207
  * @example
209
208
  * // create a basic shader
@@ -235,7 +234,7 @@ class GLShader {
235
234
  * @public
236
235
  * @type {WebGLRenderingContext}
237
236
  * @name gl
238
- * @memberOf me.GLShader
237
+ * @memberof me.GLShader
239
238
  */
240
239
  this.gl = gl;
241
240
 
@@ -244,7 +243,7 @@ class GLShader {
244
243
  * @public
245
244
  * @type {string}
246
245
  * @name vertex
247
- * @memberOf me.GLShader
246
+ * @memberof me.GLShader
248
247
  */
249
248
  this.vertex = setPrecision(minify(vertex), precision || device.getMaxShaderPrecision(this.gl));
250
249
 
@@ -253,7 +252,7 @@ class GLShader {
253
252
  * @public
254
253
  * @type {string}
255
254
  * @name vertex
256
- * @memberOf me.GLShader
255
+ * @memberof me.GLShader
257
256
  */
258
257
  this.fragment = setPrecision(minify(fragment), precision || device.getMaxShaderPrecision(this.gl));
259
258
 
@@ -262,7 +261,7 @@ class GLShader {
262
261
  * @public
263
262
  * @type {GLint[]}
264
263
  * @name attributes
265
- * @memberOf me.GLShader
264
+ * @memberof me.GLShader
266
265
  */
267
266
  this.attributes = extractAttributes(this.gl, this);
268
267
 
@@ -272,7 +271,7 @@ class GLShader {
272
271
  * @public
273
272
  * @type {WebGLProgram}
274
273
  * @name program
275
- * @memberOf me.GLShader
274
+ * @memberof me.GLShader
276
275
  */
277
276
  this.program = compileProgram(this.gl, this.vertex, this.fragment, this.attributes);
278
277
 
@@ -281,7 +280,7 @@ class GLShader {
281
280
  * @public
282
281
  * @type {object}
283
282
  * @name uniforms
284
- * @memberOf me.GLShader
283
+ * @memberof me.GLShader
285
284
  */
286
285
  this.uniforms = extractUniforms(this.gl, this);
287
286
 
@@ -294,7 +293,7 @@ class GLShader {
294
293
  /**
295
294
  * Installs this shader program as part of current rendering state
296
295
  * @name bind
297
- * @memberOf me.GLShader
296
+ * @memberof me.GLShader
298
297
  * @function
299
298
  */
300
299
  bind() {
@@ -304,7 +303,7 @@ class GLShader {
304
303
  /**
305
304
  * returns the location of an attribute variable in this shader program
306
305
  * @name getAttribLocation
307
- * @memberOf me.GLShader
306
+ * @memberof me.GLShader
308
307
  * @function
309
308
  * @param {string} name the name of the attribute variable whose location to get.
310
309
  * @returns {GLint} number indicating the location of the variable name if found. Returns -1 otherwise
@@ -321,7 +320,7 @@ class GLShader {
321
320
  /**
322
321
  * Set the uniform to the given value
323
322
  * @name setUniform
324
- * @memberOf me.GLShader
323
+ * @memberof me.GLShader
325
324
  * @function
326
325
  * @param {string} name the uniform name
327
326
  * @param {object|Float32Array} value the value to assign to that uniform
@@ -344,7 +343,7 @@ class GLShader {
344
343
  /**
345
344
  * destroy this shader objects resources (program, attributes, uniforms)
346
345
  * @name destroy
347
- * @memberOf me.GLShader
346
+ * @memberof me.GLShader
348
347
  * @function
349
348
  */
350
349
  destroy() {
@@ -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 {
@@ -94,7 +58,7 @@ class WebGLCompositor {
94
58
  /**
95
59
  * a reference to the active WebGL shader
96
60
  * @name activeShader
97
- * @memberOf me.WebGLCompositor
61
+ * @memberof me.WebGLCompositor
98
62
  * @type {me.GLShader}
99
63
  */
100
64
  this.activeShader = null;
@@ -103,7 +67,7 @@ class WebGLCompositor {
103
67
  * primitive type to render (gl.POINTS, gl.LINE_STRIP, gl.LINE_LOOP, gl.LINES, gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN, gl.TRIANGLES)
104
68
  * @name mode
105
69
  * @see me.WebGLCompositor
106
- * @memberOf me.WebGLCompositor
70
+ * @memberof me.WebGLCompositor
107
71
  * @default gl.TRIANGLES
108
72
  */
109
73
  this.mode = gl.TRIANGLES;
@@ -112,10 +76,28 @@ class WebGLCompositor {
112
76
  * an array of vertex attribute properties
113
77
  * @name attributes
114
78
  * @see me.WebGLCompositor.addAttribute
115
- * @memberOf me.WebGLCompositor
79
+ * @memberof me.WebGLCompositor
116
80
  */
117
81
  this.attributes = [];
118
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
+
119
101
  // Load and create shader programs
120
102
  this.primitiveShader = new GLShader(this.gl, primitiveVertex, primitiveFragment);
121
103
  this.quadShader = new GLShader(this.gl, quadVertex, quadFragment);
@@ -125,27 +107,17 @@ class WebGLCompositor {
125
107
  this.addAttribute("aRegion", 2, gl.FLOAT, false, 2 * Float32Array.BYTES_PER_ELEMENT); // 1
126
108
  this.addAttribute("aColor", 4, gl.UNSIGNED_BYTE, true, 4 * Float32Array.BYTES_PER_ELEMENT); // 2
127
109
 
110
+ this.vertexBuffer = new VertexArrayBuffer(this.vertexSize, 6); // 6 vertices per quad
111
+
128
112
  // vertex buffer
129
113
  gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
130
- gl.bufferData(
131
- gl.ARRAY_BUFFER,
132
- MAX_LENGTH * ELEMENT_OFFSET * ELEMENTS_PER_QUAD,
133
- gl.STREAM_DRAW
134
- );
135
-
136
- this.vertexBuffer = new VertexArrayBuffer(ELEMENT_SIZE, ELEMENTS_PER_QUAD);
137
-
138
- // Cache index buffer (TODO Remove use for cache by replacing drawElements by drawArrays)
139
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, gl.createBuffer());
140
- gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, createIB(), gl.STATIC_DRAW);
114
+ gl.bufferData(gl.ARRAY_BUFFER, this.vertexBuffer.buffer, gl.STREAM_DRAW);
141
115
 
142
116
  // register to the CANVAS resize channel
143
117
  event.on(event.CANVAS_ONRESIZE, (width, height) => {
144
118
  this.flush();
145
119
  this.setViewport(0, 0, width, height);
146
120
  });
147
-
148
- this.reset();
149
121
  }
150
122
 
151
123
  /**
@@ -170,10 +142,9 @@ class WebGLCompositor {
170
142
 
171
143
  // delete all related bound texture
172
144
  for (var i = 0; i < this.renderer.maxTextures; i++) {
173
- var texture = this.boundTextures[i];
174
- if (texture !== null) {
175
- this.boundTextures[i] = null;
176
- this.gl.deleteTexture(texture);
145
+ var texture2D = this.getTexture2D(i);
146
+ if (typeof texture2D !== "undefined") {
147
+ this.deleteTexture2D(texture2D);
177
148
  }
178
149
  }
179
150
  this.currentTextureUnit = -1;
@@ -185,7 +156,7 @@ class WebGLCompositor {
185
156
  /**
186
157
  * add vertex attribute property definition to the compositor
187
158
  * @name addAttribute
188
- * @memberOf me.WebGLCompositor
159
+ * @memberof me.WebGLCompositor
189
160
  * @function
190
161
  * @param {string} name name of the attribute in the vertex shader
191
162
  * @param {number} size number of components per vertex attribute. Must be 1, 2, 3, or 4.
@@ -201,12 +172,39 @@ class WebGLCompositor {
201
172
  normalized: normalized,
202
173
  offset: offset
203
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;
204
202
  }
205
203
 
206
204
  /**
207
205
  * Sets the viewport
208
206
  * @name setViewport
209
- * @memberOf me.WebGLCompositor
207
+ * @memberof me.WebGLCompositor
210
208
  * @function
211
209
  * @param {number} x x position of viewport
212
210
  * @param {number} y y position of viewport
@@ -220,7 +218,7 @@ class WebGLCompositor {
220
218
  /**
221
219
  * Create a WebGL texture from an image
222
220
  * @name createTexture2D
223
- * @memberOf me.WebGLCompositor
221
+ * @memberof me.WebGLCompositor
224
222
  * @function
225
223
  * @param {number} unit Destination texture unit
226
224
  * @param {Image|HTMLCanvasElement|ImageData|Uint8Array[]|Float32Array[]} image Source image
@@ -262,10 +260,35 @@ class WebGLCompositor {
262
260
  return texture;
263
261
  }
264
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
+
265
288
  /**
266
289
  * assign the given WebGL texture to the current batch
267
290
  * @name bindTexture2D
268
- * @memberOf me.WebGLCompositor
291
+ * @memberof me.WebGLCompositor
269
292
  * @function
270
293
  * @param {WebGLTexture} texture a WebGL texture
271
294
  * @param {number} unit Texture unit to which the given texture is bound
@@ -293,23 +316,33 @@ class WebGLCompositor {
293
316
  /**
294
317
  * unbind the given WebGL texture, forcing it to be reuploaded
295
318
  * @name unbindTexture2D
296
- * @memberOf me.WebGLCompositor
319
+ * @memberof me.WebGLCompositor
297
320
  * @function
298
- * @param {WebGLTexture} texture 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
299
324
  */
300
- unbindTexture2D(texture) {
301
- var unit = this.renderer.cache.getUnit(texture);
302
- 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;
303
336
  }
304
337
 
305
338
  /**
306
339
  * @ignore
307
340
  */
308
- uploadTexture(texture, w, h, b, force) {
341
+ uploadTexture(texture, w, h, b, force = false) {
309
342
  var unit = this.renderer.cache.getUnit(texture);
310
343
  var texture2D = this.boundTextures[unit];
311
344
 
312
- if (texture2D === null || force) {
345
+ if (typeof texture2D === "undefined" || force) {
313
346
  this.createTexture2D(
314
347
  unit,
315
348
  texture.getTexture(),
@@ -331,7 +364,7 @@ class WebGLCompositor {
331
364
  * Select the shader to use for compositing
332
365
  * @name useShader
333
366
  * @see me.GLShader
334
- * @memberOf me.WebGLCompositor
367
+ * @memberof me.WebGLCompositor
335
368
  * @function
336
369
  * @param {me.GLShader} shader a reference to a GLShader instance
337
370
  */
@@ -350,7 +383,7 @@ class WebGLCompositor {
350
383
 
351
384
  if (location !== -1) {
352
385
  gl.enableVertexAttribArray(location);
353
- 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);
354
387
  } else {
355
388
  gl.disableVertexAttribArray(index);
356
389
  }
@@ -361,7 +394,7 @@ class WebGLCompositor {
361
394
  /**
362
395
  * Add a textured quad
363
396
  * @name addQuad
364
- * @memberOf me.WebGLCompositor
397
+ * @memberof me.WebGLCompositor
365
398
  * @function
366
399
  * @param {me.Renderer.Texture} texture Source texture
367
400
  * @param {number} x Destination x-coordinate
@@ -372,7 +405,7 @@ class WebGLCompositor {
372
405
  * @param {number} v0 Texture UV (v0) value.
373
406
  * @param {number} u1 Texture UV (u1) value.
374
407
  * @param {number} v1 Texture UV (v1) value.
375
- * @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
376
409
  */
377
410
  addQuad(texture, x, y, w, h, u0, v0, u1, v1, tint) {
378
411
 
@@ -383,8 +416,8 @@ class WebGLCompositor {
383
416
 
384
417
  this.useShader(this.quadShader);
385
418
 
386
- if (this.vertexBuffer.isFull(4)) {
387
- // 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
388
421
  this.flush();
389
422
  }
390
423
 
@@ -410,13 +443,15 @@ class WebGLCompositor {
410
443
  this.vertexBuffer.push(vec0.x, vec0.y, u0, v0, tint);
411
444
  this.vertexBuffer.push(vec1.x, vec1.y, u1, v0, tint);
412
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);
413
448
  this.vertexBuffer.push(vec3.x, vec3.y, u1, v1, tint);
414
449
  }
415
450
 
416
451
  /**
417
452
  * Flush batched texture operations to the GPU
418
453
  * @param {number} [mode=gl.TRIANGLES] the GL drawing mode
419
- * @memberOf me.WebGLCompositor
454
+ * @memberof me.WebGLCompositor
420
455
  * @function
421
456
  */
422
457
  flush(mode = this.mode) {
@@ -434,14 +469,7 @@ class WebGLCompositor {
434
469
  gl.bufferData(gl.ARRAY_BUFFER, vertex.toFloat32(0, vertexCount * vertexSize), gl.STREAM_DRAW);
435
470
  }
436
471
 
437
- // Draw the stream buffer
438
- // TODO : finalize the WebGLCompositor implementation (splitting this one into two)
439
- // so that different compositor with different attributes/uniforms & drawing method can be used
440
- if (this.activeShader === this.primitiveShader) {
441
- gl.drawArrays(mode, 0, vertexCount);
442
- } else {
443
- gl.drawElements(mode, vertexCount / vertex.quadSize * INDICES_PER_QUAD, gl.UNSIGNED_SHORT, 0);
444
- }
472
+ gl.drawArrays(mode, 0, vertexCount);
445
473
 
446
474
  // clear the vertex buffer
447
475
  vertex.clear();
@@ -451,7 +479,7 @@ class WebGLCompositor {
451
479
  /**
452
480
  * Draw an array of vertices
453
481
  * @name drawVertices
454
- * @memberOf me.WebGLCompositor
482
+ * @memberof me.WebGLCompositor
455
483
  * @function
456
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)
457
485
  * @param {me.Vector2d[]} verts vertices
@@ -481,12 +509,12 @@ class WebGLCompositor {
481
509
  /**
482
510
  * Specify the color values used when clearing color buffers. The values are clamped between 0 and 1.
483
511
  * @name clearColor
484
- * @memberOf me.WebGLCompositor
512
+ * @memberof me.WebGLCompositor
485
513
  * @function
486
- * @param {number} r - the red color value used when the color buffers are cleared
487
- * @param {number} g - the green color value used when the color buffers are cleared
488
- * @param {number} b - the blue color value used when the color buffers are cleared
489
- * @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
490
518
  */
491
519
  clearColor(r, g, b, a) {
492
520
  this.gl.clearColor(r, g, b, a);
@@ -495,7 +523,7 @@ class WebGLCompositor {
495
523
  /**
496
524
  * Clear the frame buffer
497
525
  * @name clear
498
- * @memberOf me.WebGLCompositor
526
+ * @memberof me.WebGLCompositor
499
527
  * @function
500
528
  */
501
529
  clear() {