melonjs 10.2.2 → 10.4.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 +2907 -3383
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +3620 -4528
- package/dist/melonjs.module.js +3210 -3331
- package/package.json +19 -19
- package/src/audio/audio.js +30 -31
- package/src/camera/camera2d.js +47 -58
- package/src/entity/draggable.js +11 -21
- package/src/entity/droptarget.js +12 -22
- 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 +9 -20
- 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 +44 -14
- 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 +38 -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 +8 -10
- 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 +47 -146
- package/src/physics/bounds.js +48 -50
- package/src/physics/collision.js +13 -14
- package/src/physics/detector.js +14 -14
- package/src/physics/quadtree.js +18 -21
- 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/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 +4 -6
- package/src/video/video.js +16 -17
- 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 -110
- package/src/video/webgl/webgl_renderer.js +126 -106
|
@@ -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
|
}
|
|
@@ -75,15 +38,6 @@ class WebGLCompositor {
|
|
|
75
38
|
// local reference
|
|
76
39
|
var gl = renderer.gl;
|
|
77
40
|
|
|
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
41
|
// list of active texture units
|
|
88
42
|
this.currentTextureUnit = -1;
|
|
89
43
|
this.boundTextures = [];
|
|
@@ -103,16 +57,16 @@ class WebGLCompositor {
|
|
|
103
57
|
/**
|
|
104
58
|
* a reference to the active WebGL shader
|
|
105
59
|
* @name activeShader
|
|
106
|
-
* @
|
|
107
|
-
* @type {
|
|
60
|
+
* @memberof WebGLCompositor
|
|
61
|
+
* @type {GLShader}
|
|
108
62
|
*/
|
|
109
63
|
this.activeShader = null;
|
|
110
64
|
|
|
111
65
|
/**
|
|
112
66
|
* primitive type to render (gl.POINTS, gl.LINE_STRIP, gl.LINE_LOOP, gl.LINES, gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN, gl.TRIANGLES)
|
|
113
67
|
* @name mode
|
|
114
|
-
* @see
|
|
115
|
-
* @
|
|
68
|
+
* @see WebGLCompositor
|
|
69
|
+
* @memberof WebGLCompositor
|
|
116
70
|
* @default gl.TRIANGLES
|
|
117
71
|
*/
|
|
118
72
|
this.mode = gl.TRIANGLES;
|
|
@@ -120,11 +74,29 @@ class WebGLCompositor {
|
|
|
120
74
|
/**
|
|
121
75
|
* an array of vertex attribute properties
|
|
122
76
|
* @name attributes
|
|
123
|
-
* @see
|
|
124
|
-
* @
|
|
77
|
+
* @see WebGLCompositor.addAttribute
|
|
78
|
+
* @memberof WebGLCompositor
|
|
125
79
|
*/
|
|
126
80
|
this.attributes = [];
|
|
127
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
|
+
|
|
128
100
|
// Load and create shader programs
|
|
129
101
|
this.primitiveShader = new GLShader(this.gl, primitiveVertex, primitiveFragment);
|
|
130
102
|
this.quadShader = new GLShader(this.gl, quadVertex, quadFragment);
|
|
@@ -134,27 +106,17 @@ class WebGLCompositor {
|
|
|
134
106
|
this.addAttribute("aRegion", 2, gl.FLOAT, false, 2 * Float32Array.BYTES_PER_ELEMENT); // 1
|
|
135
107
|
this.addAttribute("aColor", 4, gl.UNSIGNED_BYTE, true, 4 * Float32Array.BYTES_PER_ELEMENT); // 2
|
|
136
108
|
|
|
109
|
+
this.vertexBuffer = new VertexArrayBuffer(this.vertexSize, 6); // 6 vertices per quad
|
|
110
|
+
|
|
137
111
|
// vertex buffer
|
|
138
112
|
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);
|
|
113
|
+
gl.bufferData(gl.ARRAY_BUFFER, this.vertexBuffer.buffer, gl.STREAM_DRAW);
|
|
150
114
|
|
|
151
115
|
// register to the CANVAS resize channel
|
|
152
116
|
event.on(event.CANVAS_ONRESIZE, (width, height) => {
|
|
153
117
|
this.flush();
|
|
154
118
|
this.setViewport(0, 0, width, height);
|
|
155
119
|
});
|
|
156
|
-
|
|
157
|
-
this.reset();
|
|
158
120
|
}
|
|
159
121
|
|
|
160
122
|
/**
|
|
@@ -179,11 +141,10 @@ class WebGLCompositor {
|
|
|
179
141
|
|
|
180
142
|
// delete all related bound texture
|
|
181
143
|
for (var i = 0; i < this.renderer.maxTextures; i++) {
|
|
182
|
-
var
|
|
183
|
-
if (
|
|
184
|
-
this.
|
|
144
|
+
var texture2D = this.getTexture2D(i);
|
|
145
|
+
if (typeof texture2D !== "undefined") {
|
|
146
|
+
this.deleteTexture2D(texture2D);
|
|
185
147
|
}
|
|
186
|
-
this.boundTextures[i] = null;
|
|
187
148
|
}
|
|
188
149
|
this.currentTextureUnit = -1;
|
|
189
150
|
|
|
@@ -194,7 +155,7 @@ class WebGLCompositor {
|
|
|
194
155
|
/**
|
|
195
156
|
* add vertex attribute property definition to the compositor
|
|
196
157
|
* @name addAttribute
|
|
197
|
-
* @
|
|
158
|
+
* @memberof WebGLCompositor
|
|
198
159
|
* @function
|
|
199
160
|
* @param {string} name name of the attribute in the vertex shader
|
|
200
161
|
* @param {number} size number of components per vertex attribute. Must be 1, 2, 3, or 4.
|
|
@@ -210,12 +171,39 @@ class WebGLCompositor {
|
|
|
210
171
|
normalized: normalized,
|
|
211
172
|
offset: offset
|
|
212
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;
|
|
213
201
|
}
|
|
214
202
|
|
|
215
203
|
/**
|
|
216
204
|
* Sets the viewport
|
|
217
205
|
* @name setViewport
|
|
218
|
-
* @
|
|
206
|
+
* @memberof WebGLCompositor
|
|
219
207
|
* @function
|
|
220
208
|
* @param {number} x x position of viewport
|
|
221
209
|
* @param {number} y y position of viewport
|
|
@@ -229,12 +217,12 @@ class WebGLCompositor {
|
|
|
229
217
|
/**
|
|
230
218
|
* Create a WebGL texture from an image
|
|
231
219
|
* @name createTexture2D
|
|
232
|
-
* @
|
|
220
|
+
* @memberof WebGLCompositor
|
|
233
221
|
* @function
|
|
234
222
|
* @param {number} unit Destination texture unit
|
|
235
223
|
* @param {Image|HTMLCanvasElement|ImageData|Uint8Array[]|Float32Array[]} image Source image
|
|
236
224
|
* @param {number} filter gl.LINEAR or gl.NEAREST
|
|
237
|
-
* @param {string} [repeat="no-repeat"] Image repeat behavior (see {@link
|
|
225
|
+
* @param {string} [repeat="no-repeat"] Image repeat behavior (see {@link ImageLayer#repeat})
|
|
238
226
|
* @param {number} [w] Source image width (Only use with UInt8Array[] or Float32Array[] source image)
|
|
239
227
|
* @param {number} [h] Source image height (Only use with UInt8Array[] or Float32Array[] source image)
|
|
240
228
|
* @param {number} [b] Source image border (Only use with UInt8Array[] or Float32Array[] source image)
|
|
@@ -271,10 +259,35 @@ class WebGLCompositor {
|
|
|
271
259
|
return texture;
|
|
272
260
|
}
|
|
273
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
|
+
|
|
274
287
|
/**
|
|
275
288
|
* assign the given WebGL texture to the current batch
|
|
276
289
|
* @name bindTexture2D
|
|
277
|
-
* @
|
|
290
|
+
* @memberof WebGLCompositor
|
|
278
291
|
* @function
|
|
279
292
|
* @param {WebGLTexture} texture a WebGL texture
|
|
280
293
|
* @param {number} unit Texture unit to which the given texture is bound
|
|
@@ -302,23 +315,33 @@ class WebGLCompositor {
|
|
|
302
315
|
/**
|
|
303
316
|
* unbind the given WebGL texture, forcing it to be reuploaded
|
|
304
317
|
* @name unbindTexture2D
|
|
305
|
-
* @
|
|
318
|
+
* @memberof WebGLCompositor
|
|
306
319
|
* @function
|
|
307
|
-
* @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
|
|
308
323
|
*/
|
|
309
|
-
unbindTexture2D(texture) {
|
|
310
|
-
|
|
311
|
-
|
|
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;
|
|
312
335
|
}
|
|
313
336
|
|
|
314
337
|
/**
|
|
315
338
|
* @ignore
|
|
316
339
|
*/
|
|
317
|
-
uploadTexture(texture, w, h, b, force) {
|
|
340
|
+
uploadTexture(texture, w, h, b, force = false) {
|
|
318
341
|
var unit = this.renderer.cache.getUnit(texture);
|
|
319
342
|
var texture2D = this.boundTextures[unit];
|
|
320
343
|
|
|
321
|
-
if (texture2D ===
|
|
344
|
+
if (typeof texture2D === "undefined" || force) {
|
|
322
345
|
this.createTexture2D(
|
|
323
346
|
unit,
|
|
324
347
|
texture.getTexture(),
|
|
@@ -339,10 +362,10 @@ class WebGLCompositor {
|
|
|
339
362
|
/**
|
|
340
363
|
* Select the shader to use for compositing
|
|
341
364
|
* @name useShader
|
|
342
|
-
* @see
|
|
343
|
-
* @
|
|
365
|
+
* @see GLShader
|
|
366
|
+
* @memberof WebGLCompositor
|
|
344
367
|
* @function
|
|
345
|
-
* @param {
|
|
368
|
+
* @param {GLShader} shader a reference to a GLShader instance
|
|
346
369
|
*/
|
|
347
370
|
useShader(shader) {
|
|
348
371
|
if (this.activeShader !== shader) {
|
|
@@ -359,7 +382,7 @@ class WebGLCompositor {
|
|
|
359
382
|
|
|
360
383
|
if (location !== -1) {
|
|
361
384
|
gl.enableVertexAttribArray(location);
|
|
362
|
-
gl.vertexAttribPointer(location, element.size, element.type, element.normalized,
|
|
385
|
+
gl.vertexAttribPointer(location, element.size, element.type, element.normalized, this.vertexByteSize, element.offset);
|
|
363
386
|
} else {
|
|
364
387
|
gl.disableVertexAttribArray(index);
|
|
365
388
|
}
|
|
@@ -370,9 +393,9 @@ class WebGLCompositor {
|
|
|
370
393
|
/**
|
|
371
394
|
* Add a textured quad
|
|
372
395
|
* @name addQuad
|
|
373
|
-
* @
|
|
396
|
+
* @memberof WebGLCompositor
|
|
374
397
|
* @function
|
|
375
|
-
* @param {
|
|
398
|
+
* @param {TextureAtlas} texture Source texture atlas
|
|
376
399
|
* @param {number} x Destination x-coordinate
|
|
377
400
|
* @param {number} y Destination y-coordinate
|
|
378
401
|
* @param {number} w Destination width
|
|
@@ -381,7 +404,7 @@ class WebGLCompositor {
|
|
|
381
404
|
* @param {number} v0 Texture UV (v0) value.
|
|
382
405
|
* @param {number} u1 Texture UV (u1) value.
|
|
383
406
|
* @param {number} v1 Texture UV (v1) value.
|
|
384
|
-
* @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
|
|
385
408
|
*/
|
|
386
409
|
addQuad(texture, x, y, w, h, u0, v0, u1, v1, tint) {
|
|
387
410
|
|
|
@@ -392,8 +415,8 @@ class WebGLCompositor {
|
|
|
392
415
|
|
|
393
416
|
this.useShader(this.quadShader);
|
|
394
417
|
|
|
395
|
-
if (this.vertexBuffer.isFull(
|
|
396
|
-
// 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
|
|
397
420
|
this.flush();
|
|
398
421
|
}
|
|
399
422
|
|
|
@@ -419,13 +442,15 @@ class WebGLCompositor {
|
|
|
419
442
|
this.vertexBuffer.push(vec0.x, vec0.y, u0, v0, tint);
|
|
420
443
|
this.vertexBuffer.push(vec1.x, vec1.y, u1, v0, tint);
|
|
421
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);
|
|
422
447
|
this.vertexBuffer.push(vec3.x, vec3.y, u1, v1, tint);
|
|
423
448
|
}
|
|
424
449
|
|
|
425
450
|
/**
|
|
426
451
|
* Flush batched texture operations to the GPU
|
|
427
452
|
* @param {number} [mode=gl.TRIANGLES] the GL drawing mode
|
|
428
|
-
* @
|
|
453
|
+
* @memberof WebGLCompositor
|
|
429
454
|
* @function
|
|
430
455
|
*/
|
|
431
456
|
flush(mode = this.mode) {
|
|
@@ -443,14 +468,7 @@ class WebGLCompositor {
|
|
|
443
468
|
gl.bufferData(gl.ARRAY_BUFFER, vertex.toFloat32(0, vertexCount * vertexSize), gl.STREAM_DRAW);
|
|
444
469
|
}
|
|
445
470
|
|
|
446
|
-
|
|
447
|
-
// TODO : finalize the WebGLCompositor implementation (splitting this one into two)
|
|
448
|
-
// so that different compositor with different attributes/uniforms & drawing method can be used
|
|
449
|
-
if (this.activeShader === this.primitiveShader) {
|
|
450
|
-
gl.drawArrays(mode, 0, vertexCount);
|
|
451
|
-
} else {
|
|
452
|
-
gl.drawElements(mode, vertexCount / vertex.quadSize * INDICES_PER_QUAD, gl.UNSIGNED_SHORT, 0);
|
|
453
|
-
}
|
|
471
|
+
gl.drawArrays(mode, 0, vertexCount);
|
|
454
472
|
|
|
455
473
|
// clear the vertex buffer
|
|
456
474
|
vertex.clear();
|
|
@@ -460,10 +478,10 @@ class WebGLCompositor {
|
|
|
460
478
|
/**
|
|
461
479
|
* Draw an array of vertices
|
|
462
480
|
* @name drawVertices
|
|
463
|
-
* @
|
|
481
|
+
* @memberof WebGLCompositor
|
|
464
482
|
* @function
|
|
465
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)
|
|
466
|
-
* @param {
|
|
484
|
+
* @param {Vector2d[]} verts vertices
|
|
467
485
|
* @param {number} [vertexCount=verts.length] amount of points defined in the points array
|
|
468
486
|
*/
|
|
469
487
|
drawVertices(mode, verts, vertexCount = verts.length) {
|
|
@@ -490,12 +508,12 @@ class WebGLCompositor {
|
|
|
490
508
|
/**
|
|
491
509
|
* Specify the color values used when clearing color buffers. The values are clamped between 0 and 1.
|
|
492
510
|
* @name clearColor
|
|
493
|
-
* @
|
|
511
|
+
* @memberof WebGLCompositor
|
|
494
512
|
* @function
|
|
495
|
-
* @param {number} r - the red color value used when the color buffers are cleared
|
|
496
|
-
* @param {number} g - the green color value used when the color buffers are cleared
|
|
497
|
-
* @param {number} b - the blue color value used when the color buffers are cleared
|
|
498
|
-
* @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
|
|
499
517
|
*/
|
|
500
518
|
clearColor(r, g, b, a) {
|
|
501
519
|
this.gl.clearColor(r, g, b, a);
|
|
@@ -504,7 +522,7 @@ class WebGLCompositor {
|
|
|
504
522
|
/**
|
|
505
523
|
* Clear the frame buffer
|
|
506
524
|
* @name clear
|
|
507
|
-
* @
|
|
525
|
+
* @memberof WebGLCompositor
|
|
508
526
|
* @function
|
|
509
527
|
*/
|
|
510
528
|
clear() {
|