melonjs 10.2.3 → 10.5.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.
- package/README.md +6 -6
- package/dist/melonjs.js +3620 -3582
- package/dist/melonjs.min.js +5 -5
- package/dist/melonjs.module.d.ts +3646 -4545
- package/dist/melonjs.module.js +3912 -3521
- package/package.json +21 -20
- package/src/audio/audio.js +30 -31
- package/src/camera/camera2d.js +47 -58
- package/src/entity/entity.js +32 -38
- package/src/game.js +21 -22
- package/src/{shapes → geometries}/ellipse.js +40 -47
- package/src/{shapes → geometries}/line.js +9 -12
- package/src/{shapes → geometries}/poly.js +100 -53
- package/src/{shapes → geometries}/rectangle.js +42 -45
- package/src/index.js +14 -32
- package/src/input/gamepad.js +11 -10
- package/src/input/input.js +2 -3
- package/src/input/keyboard.js +113 -113
- package/src/input/pointer.js +61 -29
- package/src/input/pointerevent.js +92 -29
- package/src/lang/deprecated.js +83 -13
- package/src/level/level.js +23 -24
- package/src/level/tiled/TMXGroup.js +7 -9
- package/src/level/tiled/TMXLayer.js +30 -33
- package/src/level/tiled/TMXObject.js +59 -53
- package/src/level/tiled/TMXTile.js +18 -19
- package/src/level/tiled/TMXTileMap.js +40 -46
- package/src/level/tiled/TMXTileset.js +12 -16
- package/src/level/tiled/TMXTilesetGroup.js +9 -10
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +7 -9
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +7 -9
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +4 -6
- package/src/level/tiled/renderer/TMXRenderer.js +24 -26
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -5
- package/src/loader/loader.js +17 -16
- package/src/loader/loadingscreen.js +2 -5
- package/src/math/color.js +47 -67
- package/src/math/math.js +15 -16
- package/src/math/matrix2.js +53 -59
- package/src/math/matrix3.js +56 -63
- package/src/math/observable_vector2.js +87 -77
- package/src/math/observable_vector3.js +97 -80
- package/src/math/vector2.js +107 -97
- package/src/math/vector3.js +116 -100
- package/src/particles/emitter.js +66 -76
- package/src/particles/particle.js +4 -6
- package/src/particles/particlecontainer.js +2 -4
- package/src/physics/body.js +49 -147
- package/src/physics/bounds.js +48 -50
- package/src/physics/collision.js +13 -14
- package/src/physics/detector.js +18 -17
- package/src/physics/quadtree.js +17 -20
- package/src/physics/sat.js +30 -30
- package/src/physics/world.js +24 -29
- package/src/plugin/plugin.js +11 -15
- package/src/renderable/GUI.js +41 -47
- package/src/renderable/collectable.js +5 -10
- package/src/renderable/colorlayer.js +10 -15
- package/src/renderable/container.js +87 -73
- package/src/renderable/dragndrop.js +224 -0
- package/src/renderable/imagelayer.js +25 -32
- package/src/renderable/nineslicesprite.js +41 -42
- package/src/renderable/renderable.js +113 -124
- package/src/renderable/sprite.js +62 -69
- package/src/renderable/trigger.js +26 -32
- package/src/state/stage.js +13 -18
- package/src/state/state.js +26 -27
- package/src/system/device.js +76 -133
- package/src/system/event.js +81 -70
- package/src/system/pooling.js +11 -12
- package/src/system/save.js +3 -4
- package/src/system/timer.js +19 -20
- package/src/text/bitmaptext.js +57 -55
- package/src/text/bitmaptextdata.js +10 -11
- package/src/text/glyph.js +3 -0
- package/src/text/text.js +49 -55
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +1 -1
- package/src/tweens/tween.js +44 -46
- package/src/utils/agent.js +3 -4
- package/src/utils/array.js +4 -5
- package/src/utils/file.js +3 -4
- package/src/utils/function.js +4 -5
- package/src/utils/string.js +7 -9
- package/src/utils/utils.js +4 -5
- package/src/video/canvas/canvas_renderer.js +60 -62
- package/src/video/renderer.js +53 -58
- package/src/video/texture.js +98 -112
- package/src/video/texture_cache.js +26 -10
- package/src/video/video.js +15 -16
- package/src/video/webgl/buffer/vertex.js +2 -2
- package/src/video/webgl/glshader.js +37 -39
- package/src/video/webgl/webgl_compositor.js +128 -101
- package/src/video/webgl/webgl_renderer.js +126 -106
- package/src/entity/draggable.js +0 -139
- package/src/entity/droptarget.js +0 -109
|
@@ -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,51 +17,15 @@ 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
|
-
* @class WebGLCompositor
|
|
60
|
-
* @memberOf me
|
|
61
|
-
* @constructor
|
|
62
|
-
* @param {me.WebGLRenderer} renderer the current WebGL renderer session
|
|
63
24
|
*/
|
|
64
25
|
class WebGLCompositor {
|
|
65
|
-
|
|
26
|
+
/**
|
|
27
|
+
* @param {WebGLRenderer} renderer the current WebGL renderer session
|
|
28
|
+
*/
|
|
66
29
|
constructor (renderer) {
|
|
67
30
|
this.init(renderer);
|
|
68
31
|
}
|
|
@@ -94,16 +57,16 @@ class WebGLCompositor {
|
|
|
94
57
|
/**
|
|
95
58
|
* a reference to the active WebGL shader
|
|
96
59
|
* @name activeShader
|
|
97
|
-
* @
|
|
98
|
-
* @type {
|
|
60
|
+
* @memberof WebGLCompositor
|
|
61
|
+
* @type {GLShader}
|
|
99
62
|
*/
|
|
100
63
|
this.activeShader = null;
|
|
101
64
|
|
|
102
65
|
/**
|
|
103
66
|
* primitive type to render (gl.POINTS, gl.LINE_STRIP, gl.LINE_LOOP, gl.LINES, gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN, gl.TRIANGLES)
|
|
104
67
|
* @name mode
|
|
105
|
-
* @see
|
|
106
|
-
* @
|
|
68
|
+
* @see WebGLCompositor
|
|
69
|
+
* @memberof WebGLCompositor
|
|
107
70
|
* @default gl.TRIANGLES
|
|
108
71
|
*/
|
|
109
72
|
this.mode = gl.TRIANGLES;
|
|
@@ -111,11 +74,29 @@ class WebGLCompositor {
|
|
|
111
74
|
/**
|
|
112
75
|
* an array of vertex attribute properties
|
|
113
76
|
* @name attributes
|
|
114
|
-
* @see
|
|
115
|
-
* @
|
|
77
|
+
* @see WebGLCompositor.addAttribute
|
|
78
|
+
* @memberof WebGLCompositor
|
|
116
79
|
*/
|
|
117
80
|
this.attributes = [];
|
|
118
81
|
|
|
82
|
+
/**
|
|
83
|
+
* the size of a single vertex in bytes
|
|
84
|
+
* (will automatically be calculated as attributes definitions are added)
|
|
85
|
+
* @name vertexByteSize
|
|
86
|
+
* @see WebGLCompositor.addAttribute
|
|
87
|
+
* @memberof WebGLCompositor
|
|
88
|
+
*/
|
|
89
|
+
this.vertexByteSize = 0;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* the size of a single vertex in floats
|
|
93
|
+
* (will automatically be calculated as attributes definitions are added)
|
|
94
|
+
* @name vertexSize
|
|
95
|
+
* @see WebGLCompositor.addAttribute
|
|
96
|
+
* @memberof WebGLCompositor
|
|
97
|
+
*/
|
|
98
|
+
this.vertexSize = 0;
|
|
99
|
+
|
|
119
100
|
// Load and create shader programs
|
|
120
101
|
this.primitiveShader = new GLShader(this.gl, primitiveVertex, primitiveFragment);
|
|
121
102
|
this.quadShader = new GLShader(this.gl, quadVertex, quadFragment);
|
|
@@ -125,27 +106,17 @@ class WebGLCompositor {
|
|
|
125
106
|
this.addAttribute("aRegion", 2, gl.FLOAT, false, 2 * Float32Array.BYTES_PER_ELEMENT); // 1
|
|
126
107
|
this.addAttribute("aColor", 4, gl.UNSIGNED_BYTE, true, 4 * Float32Array.BYTES_PER_ELEMENT); // 2
|
|
127
108
|
|
|
109
|
+
this.vertexBuffer = new VertexArrayBuffer(this.vertexSize, 6); // 6 vertices per quad
|
|
110
|
+
|
|
128
111
|
// vertex buffer
|
|
129
112
|
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);
|
|
113
|
+
gl.bufferData(gl.ARRAY_BUFFER, this.vertexBuffer.buffer, gl.STREAM_DRAW);
|
|
141
114
|
|
|
142
115
|
// register to the CANVAS resize channel
|
|
143
116
|
event.on(event.CANVAS_ONRESIZE, (width, height) => {
|
|
144
117
|
this.flush();
|
|
145
118
|
this.setViewport(0, 0, width, height);
|
|
146
119
|
});
|
|
147
|
-
|
|
148
|
-
this.reset();
|
|
149
120
|
}
|
|
150
121
|
|
|
151
122
|
/**
|
|
@@ -170,10 +141,9 @@ class WebGLCompositor {
|
|
|
170
141
|
|
|
171
142
|
// delete all related bound texture
|
|
172
143
|
for (var i = 0; i < this.renderer.maxTextures; i++) {
|
|
173
|
-
var
|
|
174
|
-
if (
|
|
175
|
-
this.
|
|
176
|
-
this.gl.deleteTexture(texture);
|
|
144
|
+
var texture2D = this.getTexture2D(i);
|
|
145
|
+
if (typeof texture2D !== "undefined") {
|
|
146
|
+
this.deleteTexture2D(texture2D);
|
|
177
147
|
}
|
|
178
148
|
}
|
|
179
149
|
this.currentTextureUnit = -1;
|
|
@@ -185,7 +155,7 @@ class WebGLCompositor {
|
|
|
185
155
|
/**
|
|
186
156
|
* add vertex attribute property definition to the compositor
|
|
187
157
|
* @name addAttribute
|
|
188
|
-
* @
|
|
158
|
+
* @memberof WebGLCompositor
|
|
189
159
|
* @function
|
|
190
160
|
* @param {string} name name of the attribute in the vertex shader
|
|
191
161
|
* @param {number} size number of components per vertex attribute. Must be 1, 2, 3, or 4.
|
|
@@ -201,12 +171,39 @@ class WebGLCompositor {
|
|
|
201
171
|
normalized: normalized,
|
|
202
172
|
offset: offset
|
|
203
173
|
});
|
|
174
|
+
|
|
175
|
+
switch (type) {
|
|
176
|
+
case this.gl.BYTE:
|
|
177
|
+
this.vertexByteSize += size * Int8Array.BYTES_PER_ELEMENT;
|
|
178
|
+
break;
|
|
179
|
+
case this.gl.UNSIGNED_BYTE:
|
|
180
|
+
this.vertexByteSize += size * Uint8Array.BYTES_PER_ELEMENT;
|
|
181
|
+
break;
|
|
182
|
+
case this.gl.SHORT:
|
|
183
|
+
this.vertexByteSize += size * Int16Array.BYTES_PER_ELEMENT;
|
|
184
|
+
break;
|
|
185
|
+
case this.gl.UNSIGNED_SHORT:
|
|
186
|
+
this.vertexByteSize += size * Uint16Array.BYTES_PER_ELEMENT;
|
|
187
|
+
break;
|
|
188
|
+
case this.gl.INT:
|
|
189
|
+
this.vertexByteSize += size * Int32Array.BYTES_PER_ELEMENT;
|
|
190
|
+
break;
|
|
191
|
+
case this.gl.UNSIGNED_INT:
|
|
192
|
+
this.vertexByteSize += size * Uint32Array.BYTES_PER_ELEMENT;
|
|
193
|
+
break;
|
|
194
|
+
case this.gl.FLOAT:
|
|
195
|
+
this.vertexByteSize += size * Float32Array.BYTES_PER_ELEMENT;
|
|
196
|
+
break;
|
|
197
|
+
default:
|
|
198
|
+
throw new Error("Invalid GL Attribute type");
|
|
199
|
+
}
|
|
200
|
+
this.vertexSize = this.vertexByteSize / Float32Array.BYTES_PER_ELEMENT;
|
|
204
201
|
}
|
|
205
202
|
|
|
206
203
|
/**
|
|
207
204
|
* Sets the viewport
|
|
208
205
|
* @name setViewport
|
|
209
|
-
* @
|
|
206
|
+
* @memberof WebGLCompositor
|
|
210
207
|
* @function
|
|
211
208
|
* @param {number} x x position of viewport
|
|
212
209
|
* @param {number} y y position of viewport
|
|
@@ -220,12 +217,12 @@ class WebGLCompositor {
|
|
|
220
217
|
/**
|
|
221
218
|
* Create a WebGL texture from an image
|
|
222
219
|
* @name createTexture2D
|
|
223
|
-
* @
|
|
220
|
+
* @memberof WebGLCompositor
|
|
224
221
|
* @function
|
|
225
222
|
* @param {number} unit Destination texture unit
|
|
226
223
|
* @param {Image|HTMLCanvasElement|ImageData|Uint8Array[]|Float32Array[]} image Source image
|
|
227
224
|
* @param {number} filter gl.LINEAR or gl.NEAREST
|
|
228
|
-
* @param {string} [repeat="no-repeat"] Image repeat behavior (see {@link
|
|
225
|
+
* @param {string} [repeat="no-repeat"] Image repeat behavior (see {@link ImageLayer#repeat})
|
|
229
226
|
* @param {number} [w] Source image width (Only use with UInt8Array[] or Float32Array[] source image)
|
|
230
227
|
* @param {number} [h] Source image height (Only use with UInt8Array[] or Float32Array[] source image)
|
|
231
228
|
* @param {number} [b] Source image border (Only use with UInt8Array[] or Float32Array[] source image)
|
|
@@ -262,10 +259,35 @@ class WebGLCompositor {
|
|
|
262
259
|
return texture;
|
|
263
260
|
}
|
|
264
261
|
|
|
262
|
+
/**
|
|
263
|
+
* delete the given WebGL texture
|
|
264
|
+
* @name bindTexture2D
|
|
265
|
+
* @memberof WebGLCompositor
|
|
266
|
+
* @function
|
|
267
|
+
* @param {WebGLTexture} [texture] a WebGL texture to delete
|
|
268
|
+
* @param {number} [unit] Texture unit to delete
|
|
269
|
+
*/
|
|
270
|
+
deleteTexture2D(texture) {
|
|
271
|
+
this.gl.deleteTexture(texture);
|
|
272
|
+
this.unbindTexture2D(texture);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* returns the WebGL texture associated to the given texture unit
|
|
277
|
+
* @name bindTexture2D
|
|
278
|
+
* @memberof WebGLCompositor
|
|
279
|
+
* @function
|
|
280
|
+
* @param {number} unit Texture unit to which a texture is bound
|
|
281
|
+
* @returns {WebGLTexture} texture a WebGL texture
|
|
282
|
+
*/
|
|
283
|
+
getTexture2D(unit) {
|
|
284
|
+
return this.boundTextures[unit];
|
|
285
|
+
}
|
|
286
|
+
|
|
265
287
|
/**
|
|
266
288
|
* assign the given WebGL texture to the current batch
|
|
267
289
|
* @name bindTexture2D
|
|
268
|
-
* @
|
|
290
|
+
* @memberof WebGLCompositor
|
|
269
291
|
* @function
|
|
270
292
|
* @param {WebGLTexture} texture a WebGL texture
|
|
271
293
|
* @param {number} unit Texture unit to which the given texture is bound
|
|
@@ -293,23 +315,33 @@ class WebGLCompositor {
|
|
|
293
315
|
/**
|
|
294
316
|
* unbind the given WebGL texture, forcing it to be reuploaded
|
|
295
317
|
* @name unbindTexture2D
|
|
296
|
-
* @
|
|
318
|
+
* @memberof WebGLCompositor
|
|
297
319
|
* @function
|
|
298
|
-
* @param {WebGLTexture} texture a WebGL texture
|
|
320
|
+
* @param {WebGLTexture} [texture] a WebGL texture
|
|
321
|
+
* @param {number} [unit] a WebGL texture
|
|
322
|
+
* @returns {number} unit the unit number that was associated with the given texture
|
|
299
323
|
*/
|
|
300
|
-
unbindTexture2D(texture) {
|
|
301
|
-
|
|
302
|
-
|
|
324
|
+
unbindTexture2D(texture, unit) {
|
|
325
|
+
if (typeof unit === "undefined") {
|
|
326
|
+
unit = this.boundTextures.indexOf(texture);
|
|
327
|
+
}
|
|
328
|
+
if (unit !== -1) {
|
|
329
|
+
delete this.boundTextures[unit];
|
|
330
|
+
if (unit === this.currentTextureUnit) {
|
|
331
|
+
this.currentTextureUnit = -1;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return unit;
|
|
303
335
|
}
|
|
304
336
|
|
|
305
337
|
/**
|
|
306
338
|
* @ignore
|
|
307
339
|
*/
|
|
308
|
-
uploadTexture(texture, w, h, b, force) {
|
|
340
|
+
uploadTexture(texture, w, h, b, force = false) {
|
|
309
341
|
var unit = this.renderer.cache.getUnit(texture);
|
|
310
342
|
var texture2D = this.boundTextures[unit];
|
|
311
343
|
|
|
312
|
-
if (texture2D ===
|
|
344
|
+
if (typeof texture2D === "undefined" || force) {
|
|
313
345
|
this.createTexture2D(
|
|
314
346
|
unit,
|
|
315
347
|
texture.getTexture(),
|
|
@@ -330,10 +362,10 @@ class WebGLCompositor {
|
|
|
330
362
|
/**
|
|
331
363
|
* Select the shader to use for compositing
|
|
332
364
|
* @name useShader
|
|
333
|
-
* @see
|
|
334
|
-
* @
|
|
365
|
+
* @see GLShader
|
|
366
|
+
* @memberof WebGLCompositor
|
|
335
367
|
* @function
|
|
336
|
-
* @param {
|
|
368
|
+
* @param {GLShader} shader a reference to a GLShader instance
|
|
337
369
|
*/
|
|
338
370
|
useShader(shader) {
|
|
339
371
|
if (this.activeShader !== shader) {
|
|
@@ -350,7 +382,7 @@ class WebGLCompositor {
|
|
|
350
382
|
|
|
351
383
|
if (location !== -1) {
|
|
352
384
|
gl.enableVertexAttribArray(location);
|
|
353
|
-
gl.vertexAttribPointer(location, element.size, element.type, element.normalized,
|
|
385
|
+
gl.vertexAttribPointer(location, element.size, element.type, element.normalized, this.vertexByteSize, element.offset);
|
|
354
386
|
} else {
|
|
355
387
|
gl.disableVertexAttribArray(index);
|
|
356
388
|
}
|
|
@@ -361,9 +393,9 @@ class WebGLCompositor {
|
|
|
361
393
|
/**
|
|
362
394
|
* Add a textured quad
|
|
363
395
|
* @name addQuad
|
|
364
|
-
* @
|
|
396
|
+
* @memberof WebGLCompositor
|
|
365
397
|
* @function
|
|
366
|
-
* @param {
|
|
398
|
+
* @param {TextureAtlas} texture Source texture atlas
|
|
367
399
|
* @param {number} x Destination x-coordinate
|
|
368
400
|
* @param {number} y Destination y-coordinate
|
|
369
401
|
* @param {number} w Destination width
|
|
@@ -372,7 +404,7 @@ class WebGLCompositor {
|
|
|
372
404
|
* @param {number} v0 Texture UV (v0) value.
|
|
373
405
|
* @param {number} u1 Texture UV (u1) value.
|
|
374
406
|
* @param {number} v1 Texture UV (v1) value.
|
|
375
|
-
* @param {number} tint tint color to be applied to the texture in UINT32 format
|
|
407
|
+
* @param {number} tint tint color to be applied to the texture in UINT32 (argb) format
|
|
376
408
|
*/
|
|
377
409
|
addQuad(texture, x, y, w, h, u0, v0, u1, v1, tint) {
|
|
378
410
|
|
|
@@ -383,8 +415,8 @@ class WebGLCompositor {
|
|
|
383
415
|
|
|
384
416
|
this.useShader(this.quadShader);
|
|
385
417
|
|
|
386
|
-
if (this.vertexBuffer.isFull(
|
|
387
|
-
// is the vertex buffer full if we add
|
|
418
|
+
if (this.vertexBuffer.isFull(6)) {
|
|
419
|
+
// is the vertex buffer full if we add 6 more vertices
|
|
388
420
|
this.flush();
|
|
389
421
|
}
|
|
390
422
|
|
|
@@ -410,13 +442,15 @@ class WebGLCompositor {
|
|
|
410
442
|
this.vertexBuffer.push(vec0.x, vec0.y, u0, v0, tint);
|
|
411
443
|
this.vertexBuffer.push(vec1.x, vec1.y, u1, v0, tint);
|
|
412
444
|
this.vertexBuffer.push(vec2.x, vec2.y, u0, v1, tint);
|
|
445
|
+
this.vertexBuffer.push(vec2.x, vec2.y, u0, v1, tint);
|
|
446
|
+
this.vertexBuffer.push(vec1.x, vec1.y, u1, v0, tint);
|
|
413
447
|
this.vertexBuffer.push(vec3.x, vec3.y, u1, v1, tint);
|
|
414
448
|
}
|
|
415
449
|
|
|
416
450
|
/**
|
|
417
451
|
* Flush batched texture operations to the GPU
|
|
418
452
|
* @param {number} [mode=gl.TRIANGLES] the GL drawing mode
|
|
419
|
-
* @
|
|
453
|
+
* @memberof WebGLCompositor
|
|
420
454
|
* @function
|
|
421
455
|
*/
|
|
422
456
|
flush(mode = this.mode) {
|
|
@@ -434,14 +468,7 @@ class WebGLCompositor {
|
|
|
434
468
|
gl.bufferData(gl.ARRAY_BUFFER, vertex.toFloat32(0, vertexCount * vertexSize), gl.STREAM_DRAW);
|
|
435
469
|
}
|
|
436
470
|
|
|
437
|
-
|
|
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
|
-
}
|
|
471
|
+
gl.drawArrays(mode, 0, vertexCount);
|
|
445
472
|
|
|
446
473
|
// clear the vertex buffer
|
|
447
474
|
vertex.clear();
|
|
@@ -451,10 +478,10 @@ class WebGLCompositor {
|
|
|
451
478
|
/**
|
|
452
479
|
* Draw an array of vertices
|
|
453
480
|
* @name drawVertices
|
|
454
|
-
* @
|
|
481
|
+
* @memberof WebGLCompositor
|
|
455
482
|
* @function
|
|
456
483
|
* @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
|
-
* @param {
|
|
484
|
+
* @param {Vector2d[]} verts vertices
|
|
458
485
|
* @param {number} [vertexCount=verts.length] amount of points defined in the points array
|
|
459
486
|
*/
|
|
460
487
|
drawVertices(mode, verts, vertexCount = verts.length) {
|
|
@@ -481,12 +508,12 @@ class WebGLCompositor {
|
|
|
481
508
|
/**
|
|
482
509
|
* Specify the color values used when clearing color buffers. The values are clamped between 0 and 1.
|
|
483
510
|
* @name clearColor
|
|
484
|
-
* @
|
|
511
|
+
* @memberof WebGLCompositor
|
|
485
512
|
* @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
|
|
513
|
+
* @param {number} [r=0] - the red color value used when the color buffers are cleared
|
|
514
|
+
* @param {number} [g=0] - the green color value used when the color buffers are cleared
|
|
515
|
+
* @param {number} [b=0] - the blue color value used when the color buffers are cleared
|
|
516
|
+
* @param {number} [a=0] - the alpha color value used when the color buffers are cleared
|
|
490
517
|
*/
|
|
491
518
|
clearColor(r, g, b, a) {
|
|
492
519
|
this.gl.clearColor(r, g, b, a);
|
|
@@ -495,7 +522,7 @@ class WebGLCompositor {
|
|
|
495
522
|
/**
|
|
496
523
|
* Clear the frame buffer
|
|
497
524
|
* @name clear
|
|
498
|
-
* @
|
|
525
|
+
* @memberof WebGLCompositor
|
|
499
526
|
* @function
|
|
500
527
|
*/
|
|
501
528
|
clear() {
|